- 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 中使用的浏览器导航命令:
browser.navigateTo(URL)
此命令用于导航到 URL 作为参数传递的应用程序。
语法
语法如下:
browser.navigateTo('https://the-internet.herokuapp.com/redirector')
browser.back()
此命令用于在浏览器历史记录中后退。
语法
语法如下:
browser.back()
browser.forward()
此命令用于在浏览器历史记录中前进。
语法
语法如下:
browser.forward()
browser.refresh()
此命令用于刷新当前网页。
语法
语法如下:
browser.refresh()
首先,请按照标题为“使用 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('Navigation', function(){
// launch url
browser.url('https://tutorialspoint.com/about/about_careers.htm')
// navigate to another url
browser.navigateTo("https://tutorialspoint.com/codingground.htm")
//navigate back in history
browser.back()
//get title back in browser history
console.log('Back in Browser history: ' + browser.getTitle())
//navigate forward in history
browser.forward()
//get title forward in browser history
console.log('Forward in Browser history: ' + browser.getTitle())
//refresh browser
browser.refresh()
//get title after refresh
console.log('Page Title after refresh: ' + browser.getTitle())
});
});
运行配置文件 - wdio.conf.js 文件,使用以下命令:
npx wdio run wdio.conf.js
有关如何创建配置文件的详细信息在标题为“wdio.conf.js 文件”和“配置文件生成”的章节中进行了详细讨论。
您的计算机上将显示以下屏幕:
成功执行命令后,将打印在浏览器历史记录中后退后获得的页面标题 - 关于 Tutorials Point 的职业生涯 - Tutorialspoint。
然后,打印在浏览器历史记录中前进后获得的页面标题 - 免费在线 IDE 和终端。
最后,打印页面刷新后获得的页面标题 - 免费在线 IDE 和终端。
广告