使用webdriver实现基于GUI的测试

前面介绍了如何使用Selenium2Library实现基于GUI的测试,Selenium2Library是Selenium的插件,而本文介绍的webdriver是playwright的插件


*** Settings ***

Library Browser

*** Test Cases ***

基本测试


New Page https://www.baidu.com

${SearchWords} Set Variable 软件测试

Fill Text id=kw ${SearchWords}

Click id=su

Get Title contains ${SearchWords}_百度搜索

Close Page

Frame切换


Set Browser Timeout 50000 # Timeout为隐私等待时长

New Page http://www.3testing.com/

Click id=head >>> id=introduce #>>>为Frame切换

Get Title contains 顾翔

Close Page

Windows切换 


New Page https://www.baidu.com

Click xpath=//*[@id="s-top-left"]/div/a

Close page

Get Title contains 百度产品大全

Close Page

鼠标悬停


New Browser firefox headless=false #使用firefox,不使用无头浏览器进行测试

${SearchWords} Set Variable 软件测试

New Page http://www.baidu.com

Fill Text id=kw ${SearchWords}

Click id=su

Get Title contains ${SearchWords}_百度搜索

Hover xpath=//*[@id="u"]/a[2] #Hover鼠标悬停

Click css=#u > div.bdpfmenu > a.last > span

Close Page

Close Browser

窗口滚动


New Browser headless=false

New Page https://www.jd.com

Hover body

Mouse Wheel 0 5000 #Mouse Wheel窗口滚动

Sleep 5

Close Page

Close Browser

键盘操作  


New Page https://www.baidu.com

${SearchWords} Set Variable 软件测试

Fill Text id=kw ${SearchWords}

Keyboard Key press Enter #Enter回车

Wait For Condition Title should start with ${SearchWords}

${title} Get Title

Should be Equal ${title} ${SearchWords}_百度搜索

Close Page

访问电子商务 


New Page http://127.0.0.1:8000

Fill Text css=input[name=username] cindy

Fill Text css=input[name=password] 123456

Click css=body > div > form > button

${title} Get Title

Should be Equal ${title} 电子商务系统

Close Page

cookies操作  


New Page http://127.0.0.1:8000

Fill Text css=input[name=username] cindy

Fill Text css=input[name=password] 123456

Click css=body > div > form > button

${title} Get Title

Should be Equal ${title} 电子商务系统

Add Cookie 1 1 http://127.0.0.1:8000 #设置Cookie

Go To http://127.0.0.1:8000/goods_view/

Get Text xpath=//*[@id="navbar"]/ul[1]/li[3]/a contains 查看购物车1

Click css=#navbar > ul:nth-child(1) > li:nth-child(3) > a

Get Attribute [value=修改] type

Close Page

单复选框  


New Page http://127.0.0.1:8080/sec/33/index.html

Click xpath=//input[@type='radio' and @value='Traditional_Chinese']

Check Checkbox xpath=//input[@type='radio' and @value='Traditional_Chinese'] force=true

${condition} Check Checkbox id=c1 force=false

Run Keyword If '${condition}' == 'true' Log 复选框已被选中

... ELSE Click id=c1

Check Checkbox id=c1 force=true

Close Page

选择复选框所有选项 


@{list} Create List 1 2 3

New Page http://127.0.0.1:8080/sec/33/index.html

FOR ${item} IN @{list}

Click id=c${item}

END

FOR ${item} IN @{list}

Check Checkbox id=c${item} force=true

END

Close Page

下拉条 


New Page http://127.0.0.1:8080/sec/32/index.html

Select Options By select[name=phones] value 华为

Get Selected Options //select[1] label == 华为

${promise} = Promise To Wait For Alert action=accept

Click id=button

${text} = Wait For ${promise}

Should Be Equal ${text} 我选择的是华为

Close Page

最后感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:【文末自行领取】

这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值