by alincode
Java(5 years)
SDET
English
NodeJS
freelancer
freelancer / remote
full-time
5 years
8 months
7 months
8 months
NodeJS
Selenium restful API
Appium (base on selenium)
npm install wdio-junit-reporter --save-dev
// wdio.conf.js
module.exports = {
// ...
reporters: ['dot', 'junit'],
reporterOptions: {
junit: {
outputDir: './'
}
},
// ...
};
exports.config = {
sync: true
};
describe('getTitle', () => {
it('should return the url of the current webpage', async function () {
(await this.client.getUrl()).should.be.equal(conf.testPage.start)
})
})
client.url('http://webdriver.io')
.getUrl().then(function(url) {
console.log(url);
});
<div class="ng-binding">Hi my name is {{name}}</div>
var greeting = element(by.binding('name'));
無縫接軌 angular data bind
it('should have learn link.', function(done) {
browser.get('http://www.angularjs.org');
var myElement = element(by.css('.learn-link'))
expect(myElement.getText()).to.eventually.equal(
'Learn Angular in your browser for free!');
done();
});
it('no angularjs website', function(done) {
browser.driver.get('http://webdriver.io/');
var myElement = browser.driver.findElement(by.css('h2'));
expect(myElement.getText()).to.eventually.equal(
'Selenium 2.0 bindings for NodeJS');
done();
});
mkdir webdriverio-sandbox
cd webdriverio-sandbox
npm init -y
npm i webdriverio -D
./node_modules/webdriverio/bin/wdio
capabilities: [{
browserName: 'chrome'
}],
mochaOpts: {
timeout: 60000
},
mkdir -p ./test/specs/
mkdir -p ./errorShots/
var assert = require('assert');
describe('mokayo page', function() {
it('should have the right title', function() {
browser.url('http://blog.mokayo.com');
var title = browser.getTitle();
assert.equal(title, '教你所想學的,用眼樂讀 - blog.mokayo.com');
});
});
./node_modules/webdriverio/bin/wdio wdio.conf.js
npm run e2e-test
"scripts": {
"e2e-test": "wdio wdio.conf.js"
}
OR
Standalone Mode
The WDIO Testrunner
exports.config = {
specs: [
'test/spec/**'
],
capabilities: [{
browserName: 'chrome'
}, {
maxInstances: 5,
browserName: 'firefox',
specs: [
'test/ffOnly/*'
]
},{
browserName: 'phantomjs',
exclude: [
'test/spec/alert.js'
]
}],
sync: true,
screenshotPath: 'shots',
baseUrl: 'http://localhost:8080',
waitforTimeout: 1000, // Default timeout for all waitForXXX commands.
};
exports.config = {
// WebdriverCSS: https://github.com/webdriverio/webdrivercss
// WebdriverRTC: https://github.com/webdriverio/webdriverrtc
// Browserevent: https://github.com/webdriverio/browserevent
plugins: {
webdrivercss: {
screenshotRoot: 'my-shots',
failedComparisonsRoot: 'diffs',
misMatchTolerance: 0.05,
screenWidth: [320,480,640,1024]
},
webdriverrtc: {},
browserevent: {}
},
framework: 'mocha'
reporters: ['dot', 'allure'],
// Hooks
onPrepare: function (config, capabilities) {
}
};
// wdio.conf.js
exports.config = {
// define all tests
specs: ['./test/specs/**/*.spec.js'],
// define specific suites
suites: {
login: [
'./test/specs/login.success.spec.js',
'./test/specs/login.failure.spec.js'
],
otherFeature: []
}
}
wdio wdio.conf.js --suite login
wdio wdio.conf.js --suite login,otherFeature
webdriver instance
global object
browser.click('h2.subheading a');
browser.element('h2');
browser.elements('h2');
browser.click('#myButton');
var input = browser.element('.input');
input.setValue('test123');
browser.submitForm('#loginForm');
browser.getTitle();
browser.element('.input').getValue();
browser.submitForm('#loginForm');
browser.element('.h2');
browser.elements('li');
browser.url('http://webdriver.io');
browser.isEnabled(selector);
browser.isExisting(selector);
browser.isSelected(selector);
browser.element('.notification').waitForExist(5000);
browser.saveScreenshot('front_page.png');
client
.init()
.url('http://google.com')
.end();
// ends session and close browser
browser.pause(5000);
browser.addCommand();
browser.debug();
function Page() {}
Page.prototype.open = function(path) {
browser.url('/' + path)
}
module.exports = new Page();
// login.page.js
var Page = require('./page')
var LoginPage = Object.create(Page, {
// define elements
username: { get: function () { return browser.element('#username'); } },
password: { get: function () { return browser.element('#password'); } },
form: { get: function () { return browser.element('#login'); } },
flash: { get: function () { return browser.element('#flash'); } },
// define or overwrite page methods
open: { value: function() {
Page.open.call(this, 'login');
} },
submit: { value: function() {
this.form.submitForm();
} }
});
module.exports = LoginPage
// login.spec.js
var expect = require('chai').expect;
var LoginPage = require('../pageobjects/login.page');
describe('login form', function () {
it('登入失敗', function () {
LoginPage.open();
LoginPage.username.setValue('foo');
LoginPage.password.setValue('bar');
LoginPage.submit();
expect(LoginPage.flash.getText()).to.contain('Your username is invalid!');
});
it('登入成功', function () {
LoginPage.open();
LoginPage.username.setValue('tomsmith');
LoginPage.password.setValue('SuperSecretPassword!');
LoginPage.submit();
expect(LoginPage.flash.getText()).to.contain('login success');
});
});
by google testing blog
# 正常登入流程
使用者可從首頁點擊登入轉至登入頁,並可輸入帳號密碼,密碼驗證過後,頁面顯示登入成功。
# 正常登入流程
使用者輸入帳號密碼驗證後,發現密碼輸入錯誤,停留在登入頁,顯示登入錯誤原因。
# 正常登出流程
使用者可點擊登出按鈕,畢竟狀態真正為登出。
# 檢查所有從首頁,可正常連連結至分支頁
登入頁、分類頁、個人資訊頁、聯繫客服頁
# etc...
/html/body/section/div/section[2]/article/a[1]
$('.icon-search')