前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Selenium2Library实现基于GUI的测试

Selenium2Library实现基于GUI的测试

作者头像
顾翔
发布2024-09-10 15:10:56
690
发布2024-09-10 15:10:56
举报
文章被收录于专栏:啄木鸟软件测试

设置

代码语言:javascript
复制
程序库               Selenium2Library
变量文件              var.py

变量

代码语言:javascript
复制
@{words}          软件测试    大数据    云计算    C++    Java    Python    编译原理    数据库    软件工程

用例

访问百度

代码语言:javascript
复制
    open browser    https://www.baidu.com    firefox
    ${SearchWords}    Set Variable    软件测试
    Input Text    name=wd    ${SearchWords}
    Click Button    id=su
    Wait Until Element Is Visible    class=n    20
    ${title}    Get Title
    Should be Equal    ${title}    ${SearchWords}_百度搜索
    Close Browser

切换iframe

代码语言:javascript
复制
    open browser    http://www.3testing.com/    firefox
    Select Frame    xpath=/html/body/iframe[1]
    Click link    id=introduce
    Page Should Contain    顾翔
    Close Browser

切换windows

代码语言:javascript
复制
    open browser    https://www.baidu.com    firefox
    Click link    name=tj_briicon
    ${handles}    Get Window Handles
    Switch Window    ${handles[0]}
    Close Window
    Switch Window    ${handles[1]}
    Wait Until Element Is Visible    xpath=//*[@id="content"]/h3[1]    20
    Page Should Contain    文心一言
    Close Window
    Close Browser

移动鼠标

代码语言:javascript
复制
    open browser    https://www.baidu.com    firefox
    ${SearchWords}    Set Variable    软件测试
    Input Text    name=wd    ${SearchWords}
    Click Button    id=su
    Wait Until Element Is Visible    class=n    20
    ${title}    Get Title
    Should be Equal    ${title}    ${SearchWords}_百度搜索
    Mouse Over    name=tj_settingicon
    Click link    class=last
    Page Should Contain    隐私设置
    Close Browser

键盘操作

代码语言:javascript
复制
    open browser    https://www.baidu.com    firefox
    ${SearchWords}    Set Variable    软件测试
    Input Text    name=wd    ${SearchWords}
    Press Key    id=su    Keys.ENTER
    Wait Until Element Is Visible    class=n    20
    ${title}    Get Title
    Should be Equal    ${title}    ${SearchWords}_百度搜索
    ${SearchWords}    Set Variable    大数据
    Input Text    name=wd    ${SearchWords}
    Press Key    id=su    \\10
    Wait Until Page Contains    ${SearchWords}    20
    ${title}    Get Title
    Should be Equal    ${title}    ${SearchWords}_百度搜索
    Close Browser

电子商务网站操作

代码语言:javascript
复制
    open browser    http://127.0.0.1:8000 firefox
    Input Text    name=username    cindy
    Input Text    name=password    123456
    Submit Form    name=myForm
    Wait Until Element Is Visible    name=good    20
    ${title}    Get Title
    Should be Equal    ${title}    电子商务系统
    Close Browser

cookies操作

代码语言:javascript
复制
    open browser    http://127.0.0.1:8000/    firefox
    Input Text    name=username    cindy
    Input Text    name=password    123456
    Submit Form    name=myForm
    Wait Until Element Is Visible    name=good    20
    ${title}    Get Title
    Should be Equal    ${title}    电子商务系统
    Add Cookie    1    1
    Add Cookie    2    2
    go to    http://127.0.0.1:8000/goods_view/
    Page Should Contain    查看购物车2
    click link    /view_chart/
    Element Should Be Visible    xpath=/html/body/div[2]/div[1]/div/table/tbody/tr[1]/td[4]/form
    Close Browser

单复选框

代码语言:javascript
复制
    open browser    http://127.0.0.1:8080/sec/33/index.html    firefox
    Click Element    xpath=//input[@type='radio' and @value='Traditional_Chinese']
    Element Should Be Focused    xpath=//input[@type='radio' and @value='Traditional_Chinese']
    ${condition}    Get Element Attribute    id=c1    @checked
    Run Keyword If    '${condition}' == 'true'    Log    复选框已被选中
    ...    ELSE    Click Element    id=c1
    Checkbox Should Be Selected    id=c1
    Close Browser

选择复选框中所有内容

代码语言:javascript
复制
@{list}    Create List    1    2    3
    open browser    http://127.0.0.1:8080/sec/33/index.html    firefox
    @{checkboxes}    Get Webelements    xpath=/html/body/form[2]
    FOR    ${item}    IN    @{list}
        Click Element    id=c${item}
    END
    FOR    ${item}    IN    @{list}
        Checkbox Should Be Selected    id=c${item}
    END
    Close Browser

下拉条

代码语言:javascript
复制
open browser    http://127.0.0.1:8080/sec/32/index.html    firefox
    sleep    3
    Select From List By Value    id=ph    华为
    Click Button    id=button
    Alert Should Be Present    我选择的是华为
    Select From List By Label    id=ph    中兴
    Click Button    id=button
    Alert Should Be Present    我选择的是中兴
    Close Browser

关键字

代码语言:javascript
复制
 open browser    https://www.baidu.com    firefox
    ${SearchWords}    Set Variable    ${words}[${integer}]
    Input Text    name=wd    ${SearchWords}
    Click Button    id=su
    Wait Until Element Is Visible    class=n    20
    ${title}    Get Title
    Should be Equal    ${title}    ${SearchWords}_百度搜索
    Close Browser

var.py

代码语言:javascript
复制
import random
__all__ =['scalar','var1','integer','words']
scalar = 'Hello World!'
var1 =['Hello','World','Python']
integer = random.randint(0,8)
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2024-05-22,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
腾讯云服务器利旧
云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档