- WebdriverIO 教程
- WebdriverIO - 首页
- WebdriverIO - 简介
- WebdriverIO - 预备条件
- WebdriverIO - 架构
- WebdriverIO - NodeJS 入门
- WebdriverIO - NPM 安装
- WebdriverIO - VS Code 安装
- WebdriverIO - package.json
- WebdriverIO - Mocha 安装
- Selenium 独立服务器安装
- WebdriverIO - 配置文件生成
- WebdriverIO - VS Code 智能提示
- WebdriverIO - wdio.conf.js 文件
- WebdriverIO - XPath 定位器
- WebdriverIO - CSS 定位器
- WebdriverIO - 链接文本定位器
- WebdriverIO - ID 定位器
- WebdriverIO - 标签名定位器
- WebdriverIO - 类名定位器
- WebdriverIO - 名称定位器
- 断言的 Expect 语句
- WebdriverIO - 正向流程
- WebdriverIO - 通用浏览器命令
- WebdriverIO - 处理浏览器大小
- WebdriverIO - 浏览器导航命令
- 处理复选框和下拉菜单
- WebdriverIO - 鼠标操作
- 处理子窗口/弹出窗口
- WebdriverIO - 隐藏元素
- WebdriverIO - 框架
- WebdriverIO - 拖放
- WebdriverIO - 双击
- WebdriverIO - Cookie
- WebdriverIO - 处理单选按钮
- Web元素上的 Chai 断言
- WebdriverIO - 多个窗口/标签页
- WebdriverIO - 滚动操作
- WebdriverIO - 警报
- WebdriverIO - 调试代码
- WebdriverIO - 截取屏幕截图
- WebdriverIO - JavaScript 执行器
- WebdriverIO - 等待
- WebdriverIO - 并行运行测试
- WebdriverIO - 数据驱动测试
- 从命令行参数运行测试
- 使用 Mocha 选项执行测试
- 从 Allure 生成 HTML 报告
- WebdriverIO 有用资源
- WebdriverIO - 快速指南
- WebdriverIO - 有用资源
- WebdriverIO - 讨论
WebdriverIO - 处理单选按钮
在使用 WebdriverIO 自动化测试时,我们可以处理 UI 中的单选按钮。单选按钮在 html 代码中被标识为标签名为 input,类型为 radio。
您的电脑上将出现以下屏幕:
单选按钮的方法
与单选按钮一起工作的一些方法如下:
click()
它用于选择一个单选按钮。
语法
语法如下:
const l = $('.rad')
l.click()
isSelected()
它用于检查类型为 radio 的元素是否被选中。它返回一个布尔值(如果选中则为 true,否则为 false)。
语法
语法如下:
const l = $('.rad')
l.isSelected()
首先,请按照标题为“使用 WebdriverIO 的正向流程”一章中的步骤 1 到步骤 5 进行操作,步骤如下:
步骤 1 - 安装 NodeJS。有关如何执行此安装的详细信息,请参阅标题为“NodeJS 入门”一章。
步骤 2 - 安装 NPM。有关如何执行此安装的详细信息,请参阅标题为“NPM 安装”一章。
步骤 3 - 安装 VS Code。有关如何执行此安装的详细信息,请参阅标题为“VS Code 安装”一章。
步骤 4 - 创建配置文件。有关如何执行此安装的详细信息,请参阅标题为“配置文件生成”一章。
步骤 5 - 创建一个规范文件。有关如何执行此安装的详细信息,请参阅标题为“Mocha 安装”一章。
步骤 6 - 将以下代码添加到创建的 Mocha 规范文件中。
// test suite name
describe('Tutorialspoint application', function(){
//test case
it('Radio Button', function(){
// launch url
browser.url('https://tutorialspoint.com/selenium/selenium_automation_practice.htm')
//identify radio button with CSS then click
const p = $("input[value='1']")
p.click()
//verify if selected
console.log(p.isSelected())
});
});
使用以下命令运行配置文件 - wdio.conf.js 文件:
npx wdio run wdio.conf.js
有关如何创建配置文件的详细信息,请参阅标题为“wdio.conf.js 文件”和“配置文件生成”的两章。
您的电脑上将出现以下屏幕:
命令成功执行后,布尔值将打印在控制台中。这是由 isSelected() 函数返回的,该函数返回 true,因为单选按钮在上一步中已被选中。
广告