测试必须在时间、质量和成本之间获取一个平衡点,这是测试策略和测试设计的价值体现。

第一个完整的自动化测试脚本

上一篇 / 下一篇  2018-01-30 15:52:53 / 个人分类:自动化测试

测试用例51Testing软件测试网]	`(~3f`
打开百度首页,搜索Selenium,然后检查搜索列表,有没有Selenium官网链接。
1A'M Y(Ao0
I%R tEy vuj9A0步骤:
51Testing软件测试网 x{%Q xVT
1)启动浏览器
c+nO_`f&w\5W02)打开百度首页:http://www.baidu.com
tqX|,?0T7~2v03)定位搜索输入框,记录下输入框元素的xpath表达式://*[@id='kw']
51Testing软件测试网d7jK#jLHT[
4)定位搜索提交按钮(百度一下),获取xpath表达式://*[@id='su']
z;Eb&DF9Hb0q05)在搜索输入框输入:Selenium,点百度一下这个按钮
!Dgg(o~uL.P06)在搜索结果列表去判断是否存在Selenium官网这个链接51Testing软件测试网7p#eX fY qW$A{j
7)退出浏览器,结束测试
K/x0_#` PU9d1D0

-B_E/s R&k KA3rEC0测试脚本:51Testing软件测试网x:\L E.W-j;O

%}r8PpYu7L)d0q0
importtime
j$|,Bl5q'H2p4@ LO n0fromseleniumimportwebdriver51Testing软件测试网#}Hh C4huH2F

(hkh9T$}0driver = webdriver.Chrome()# 打开chrome,如果用Firefox,换成webdriver.Firefox()51Testing软件测试网p1? q]L5_9h
driver.maximize_window()# 最大化浏览器窗口
P%Eb Z;v.W3n;~1e0
driver.implicitly_wait(8)# 设置隐式时间等待51Testing软件测试网 |;I2ZnJ!GDR
51Testing软件测试网$Oj*Fmv R*B0p#Y
driver.get("https://www.baidu.com")# 地址栏输入百度地址51Testing软件测试网t:s;i-M&\x5I,u }
# driver.find_element_by_xpath("//*[@id='kw']").send_keys("selenium")
[$F{ z,i I0
driver.find_element_by_id("kw").send_keys("selenium")# 搜索输入框输入Selenium
[n8f7l&OQ'pE`0
# driver.find_element_by_xpath("//*[@id='su']").click()
~4o$v`4U-g#TW0
driver.find_element_by_id("su").click()#点击百度一下按钮
!y%NW;XX M'Vh0
51Testing软件测试网IL^4mwt
time.sleep(2)# 导入time模块,等待2秒
m!_;`?h0

4nr!svh }_#OZ7?0
# 这里通过元素XPath表达式来确定该元素显示在结果列表,从而判断Selenium官网这个链接显示在结果列表。
3d `:zaT0
ele_string=driver.find_element_by_xpath("//*[@id='1']/h3/a").text51Testing软件测试网7P`'Z1y ]Lq6X$h
if(ele_string =="Selenium - Web Browser Automation"):51Testing软件测试网 lm"f4\c;zGHP
print("Testing is successful!")
p]9XTZL:[0driver.quit()51Testing软件测试网$u6H[;E!v^

pr(K5ao\|k0

TAG:

 

评分:0

我来说两句

Open Toolbar