2019/7/19
升级谷歌浏览器到版本 75.0.3770.142(正式版本) (64 位),解决了“This version of ChromeDriver only supports Chrome version 75”的问题。
测试通过。
清华大学出版社《软件测试实战教程》中有简单介绍Appium,需要对webdriverio有所了解。
webdriverio是针对Node.js的Webdriver测试框架。
以下在Windows 7环境进行
准备
node.js v8.11.2以上版本
设置项目
创建一个文件夹E:\TestLab\webdriverio-test
在安装依赖之前,需要初始化一个空白的NPM项目。
进入文件夹webdriver-test,在CMD命令窗口输入命令,
cd E:/TestLab/webdriver-test
npm init -y
-y是对命令的所有提示默认回答为yes,可以省略-y以便指定项目的选项。
webdriverio v5下用下面的命令安装WebdriverIO CLI:
npm --registry http://registry.npm.taobao.org i --save-dev @wdio/cli
这里--registry http://registry.npm.taobao.org是为了解决默认的国外npm仓库访问受阻,如果网络好可以省略这个选项。
用下面的命令生成配置文件:
E:/TestLab/webdriverio-test/node_modules/.bin/wdio config
这 一步没有成功,未能生成配置文件?
原因是下载安装 chromedriver 失败,可以用下面的命令安装 chromedriver:
npm install chromedriver --chromedriver_cdnurl=http://cdn.npm.taobao.org/dist/chromedriver
再生成配置文件,成功。
创建Spec文件
创建一个文件夹E:\TestLab\webdriverio-test\test\specs
在新建的文件夹下创建一个文件basic.js
const assert = require('assert');
describe('webdriver.io page', () => {
it('should have the right title', () => {
browser.url('https://webdriver.io');
const title = browser.getTitle();
assert.strictEqual(title, 'WebdriverIO · Next-gen WebDriver test framework for Node.js');
});
});
如果使用async模式代替sync模式,basic.js文件就应该修改为:
const assert = require('assert');
describe('webdriver.io page', () => {
it('should have the right title', async () => {
await browser.url('https://webdriver.io');
const title = await browser.getTitle();
assert.strictEqual(title, 'WebdriverIO · Next-gen WebDriver test framework for Node.js');
});
});
执行测试
E:/TestLab/webdriverio-test/node_modules/.bin/wdio wdio.conf.js