正如标题所述,Nightwatch.js和Webdriver.io有什么区别?
看起来他们有相同的语法,并做几乎相同的事情.他们有什么不同?
我需要在它们之间做出选择.
我想建立Android和iOS平台(React Native)移动应用程序的自动化测试流程。为此,我使用Appium和WebdriverIO。作为示例,我使用现有的appium-boilerplate代码库和现成的应用程序来运行测试。我在Android 模拟器中运行该应用程序。基本设置如下所示。
1.阿皮姆
2.WebdriverIO
wdio.shared.conf.js
exports.config = {
// ====================
// Runner and framework
// Configuration
// ====================
runner: 'local',
framework: 'jasmine',
jasmineNodeOpts: {
// Updated the timeout to 30 seconds due to possible longer appium calls
// When using XPATH
defaultTimeoutInterval: 90000,
helpers: [require.resolve('@babel/register')],
},
sync: true,
logLevel: 'silent',
deprecationWarnings: true,
bail: 0,
baseUrl: 'http://the-internet.herokuapp.com',
waitforTimeout: 10000,
connectionRetryTimeout: 90000,
connectionRetryCount: 3,
reporters: ['spec'],
// ====================
// …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法来继承webdriverio返回的WebElement对象,没有猴子修补和TS类型支持(自动完成是必须的).有没有办法做这样的事情?
class Checkbox extends WebdriverIOWebElement {
constructor() {
super($('div'))
}
// overriding base method
isDisplayed(): boolean {
// blabla some new logic here
}
check() {
if(!this.isChecked()) {
this.click()
}
}
uncheck() {
if(this.isChecked()) {
this.click()
}
}
}
Run Code Online (Sandbox Code Playgroud) javascript webdriver selenium-webdriver typescript webdriver-io
我正在使用chimp.js,它通过一些光纤魔法来增强webdriver.io,以便可以以同步方式定义代码.这是代码:
var c = require('./config');
module.exports = function () {
this.When(/^I try to login with wrong credentials$/, function () {
browser.setValue(userNameField, wrongUser);
browser.setValue(passwordField, wrongPassword);
browser.click('button[value="Login"]');
});
this.When(/^I try to login with the correct credentials$/, function () {
browser.setValue(userNameField, c.userName);
browser.setValue(passwordField, c.password);
console.log('before pressig the button');
browser.click('button[value="Login"]');
console.log('logged in');
});
};
Run Code Online (Sandbox Code Playgroud)
第一个When执行得很好.第二个When也有效,我只是没有看到
登录
在控制台上.两者都在同一个网站上运行,并且都点击了同一个按钮.在第二种情况下,登录成功后,浏览器将重定向到角度SPA.这里的一切都正确加载,但就是这样.回调永远不会发生.
用--debug --log=command我运行测试看到这是最后一行(在超时之前)
[1;30m[01:30:18]: [0m [0;35mCOMMAND [0mPOST "/wd/hub/session/7c334efe-2417-4184-b43c-082ba4441291/element/11/click"
Run Code Online (Sandbox Code Playgroud)
将日志级别切换为详细,并等待〜5min我收到以下错误:
[chimp][selenium.stderr] 01:36:59.561 DEBUG - Executed: [0560aaa14e4cf874afd72336c19e299b, clickElement {id=0.6384125368203968-3}]
[chimp][selenium.stderr] 01:37:02.449 WARN …Run Code Online (Sandbox Code Playgroud) 我刚刚升级到最新版本的 Chrome 87。无论 Chrome 窗口是在前台还是后台,我的 Webdriver.io/Selenium 测试都可以正常运行。现在,升级后,如果窗口在前台,则测试通过,但如果它在后台则不通过。
我没有最小化运行我的测试的 Chrome 窗口。我只是按 Alt+Tab,这样我的 IDE 就在 Chrome 前面,它在后面。
我知道 Chrome 87 有一个新的“功能”,如果它不在前台,它会使用更少的 CPU。有没有办法使用 Chrome 或 Chromedriver 设置关闭它?
似乎我的测试是找到要点击的按钮,但 Chrome 没有注册点击。
有关WebdriverIO与Selenium的反馈意见吗?我处于两难境地,想要消除这种困惑.
我花了几天时间学习WebdriverIO并做了一些实践,但得出的结论还不够成熟.调试确实是一个挑战.
我有两个测试.第一次测试成功通过.然后在第二个测试中有一个url方法调用,但它不会更改浏览器中的url.
wdio.conf.js中的baseUrl设置为http://localhost/web/es/index.html#
测试:
var assert = require('assert');
describe('user login ', function(){
it('user login', function(){
browser
.url('/system/login')
.setValue('[name="username"]','test')
.setValue('[name="password"]','test')
.click('=Potvr?');
assert(browser.waitUntil('=test test'));
});
it('user form', function(){
browser
.url('/user/form');
});
});
Run Code Online (Sandbox Code Playgroud)
在第一次测试/ system/login中正确打开.但在第二次测试中,网址永远不会更改为/ user/form
我刚开始使用webdriverio所以我错过了什么?
我正在使用spectron对我的电子应用程序运行集成测试.除了尝试测试应用程序设置在应用程序重新启动之间正确保留之外,一切正常.
在运行测试时,我的应用程序启动userData每个测试的新临时目录,以确保测试被隔离.这意味着持久性测试需要理想地在单个测试中进行,为实现这一点,我必须在测试过程中重新启动应用程序.有一种app.restart方法,所以必须得到支持吗?
我正在使用以下光谱测试代码:
// save some settings here
await app.restart();
await app.client.waitUntilWindowLoaded()
// do some more checking to ensure the app is fully loaded
// check the settings here
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
Error: waitUntilWindowLoaded Promise was rejected with the following reason:
Error: A session id is required for this command but wasn't found in the response payload
Run Code Online (Sandbox Code Playgroud)
这样做的正确方法是什么?我也尝试停止Application实例并启动一个具有类似结果的新实例.
貌似wdio有fibers作为依赖,使用node-gyp,这显然不会没有的Python 2.7在Windows上运行.
现在我已经安装了,我没有得到"missing PYTHON"错误,但它永远挂在命令正在做的任何事情 - 光纤.
在您指出之前,是的,我知道这似乎是多个问题的重复。
但是,我实现了建议的所有3个修复程序;
jest.setTimeout()在测试中使用以设置异步超时test()传递扩展的异步超时限制done完成后调用函数但是,在自动Linux机器(Jenkins)上运行我的笑话测试时,它仍然会抛出相同的错误。另外,值得一提的是,这在运行NodeJS v10的MacOS计算机上运行良好,而自动化的Linux计算机运行NodeJS V8.8.3(最新的LTS版本)
这就是我开玩笑的测试结果。
const webdriverio = require('webdriverio');
const options = {
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
args: ["--no-sandbox", "disable-web-security", "--disable-dev-shm-usage"]
}
}
};
const client = webdriverio.remote(options);
beforeEach(async () => {
await client.init();
})
test('Google Search for WebdriverIO has correct title', async (done) => {
jest.setTimeout(30000)
await client.url('https://www.google.com/ncr');
await client.setValue('input[name=q]', 'WebdriverIO');
await client.click('input[value="Google Search"]');
const title = await client.getTitle();
expect(title).toBe('WebdriverIO - Google Search');
done();
}, 30000);
afterEach(async …Run Code Online (Sandbox Code Playgroud) webdriver-io ×10
javascript ×4
node.js ×3
webdriver ×2
android ×1
angularjs ×1
appium ×1
chimp.js ×1
electron ×1
java ×1
jestjs ×1
node-gyp ×1
react-native ×1
selenium ×1
spectron ×1
typescript ×1
wdio-v4 ×1
wdio-v5 ×1
yarnpkg ×1