IronPython应用之Selenium(Web测试,AutoPyTest自动化测试)

(一)工具框架:

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()

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值