(一)工具框架:
IronPython自动化工具框架AutoPyTest简介---http://blog.csdn.net/w565911788/article/details/7594403
(二)批处理命令(bat):
echo "切换到工作盘符"
D:
echo "主程序路径 -py 调用python脚本路径 -t 处理时间秒 -s(最后关闭)"
"D:\Program Files\IronPythonTest\IronPythonTest.exe" -py "D:\Program Files\IronPythonTest\Scripts\TestFirefox.py" -t 60 -s
echo "处理完成"
exit
(三)Python测试脚本(TestFirefox.py)
import clr, sys
import datetime,time
clr.AddReference('IronPythonTest')
clr.AddReference('System.Windows.Forms')
#引用SeleniumWebdriver四个Dll与IronPythonTest.exe同目录
clr.AddReference('WebDriver')
clr.AddReference('WebDriver.Support')
clr.AddReference('Ionic.Zip')
clr.AddReference('Newtonsoft.Json')
from System.Windows.Forms import *
from IronPythonTest import *
from OpenQA.Selenium import *
from OpenQA.Selenium.Firefox import *
from OpenQA.Selenium.Support.UI import *
from time import sleep
text_path="//input[@id='kw']"
text_id="kw"
text_name="wd"
text="谷歌"
button_id="su"
news_path="//div[@id='s_tab']//a[text()='新闻']"
baseURL = "http://www.baidu.com"
driver = FirefoxDriver()
sleep(1.0)
driver.Navigate().GoToUrl(baseURL)
sleep(1.0)
driver.FindElement(By.XPath(text_path)).Clear()
driver.FindElement(By.XPath(text_path)).SendKeys(text)
sleep(1.0)
#driver.FindElement(By.Id(text_id)).Clear()
#driver.FindElement(By.Id(text_id)).SendKeys(text)
#sleep(1.0)
#driver.FindElement(By.Name(text_name)).Clear()
#driver.FindElement(By.Name(text_name)).SendKeys(text)
#sleep(1.0)
driver.FindElement(By.Id(button_id)).Click()
sleep(5.0)
driver.FindElement(By.XPath(news_path)).Click()
sleep(5.0)
driver.Quit()