劉艾霖 (Alin)
2017 Testing Day
const {Builder, By, until} = require('webdriver');
var driver = new Builder()
.forBrowser('firefox')
.build();
driver.get('http://www.google.com/ncr')
.then(_ => driver.findElement(By.name('q')).sendKeys('webdriver'))
.then(_ => driver.findElement(By.name('btnG')).click())
.then(_ => driver.wait(until.titleIs('webdriver - Google Search'), 1000))
.then(_ => driver.quit());
driver.get('http://www.google.com');
driver.findElement(webdriver.By.id('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.id('btnG')).click();
client.url('http://google.com')
.setValue('#q', 'webdriver')
.click('#btnG')
describe('Protractor Demo App', function() {
it('should add one and two', function() {
browser.get('http://juliemr.github.io/protractor-demo/');
element(by.model('first')).sendKeys(1);
element(by.model('second')).sendKeys(2);
element(by.id('gobutton')).click();
expect(element(by.binding('latest')).getText()).
toEqual('5'); // This is wrong!
});
});
const assert = require('assert');
describe('angularjs', () => {
it('should add one and two ', () => {
browser.url('http://juliemr.github.io/protractor-demo/');
$('[ng-model=first]').setValue(1);
$('[ng-model=second]').setValue(2);
$('#gobutton').click();
browser.pause(7000);
assert.equal($('.ng-binding').getText(), 3);
});
});
class Page {
constructor() {
this.title = 'My Page';
}
open(path) {
browser.url('/' + path);
}
}
module.exports = new Page();
var Page = require('./page')
class LoginPage extends Page {
get username() { return browser.element('#username'); }
get password() { return browser.element('#password'); }
get form() { return browser.element('#login'); }
get flash() { return browser.element('#flash'); }
open() { super.open('login'); }
submit() { this.form.submitForm(); }
}
module.exports = new LoginPage();
var expect = require('chai').expect;
var LoginPage = require('../pageobjects/login.page');
describe('login form', function () {
it('登入失敗流程', function () {
LoginPage.open();
LoginPage.username.setValue('alincodeeeeee');
LoginPage.password.setValue('hello');
LoginPage.submit();
expect(LoginPage.flash.getText()).to.contain('這個帳號不存在');
});
it('登入成功流程', function () {
LoginPage.open();
LoginPage.username.setValue('alincode');
LoginPage.password.setValue('hello');
LoginPage.submit();
expect(LoginPage.flash.getText()).to.contain('你登入成功');
});
});
LoginPage.open();
LoginPage.username.setValue('alincode');
LoginPage.password.setValue('hello');
LoginPage.submit();
Selenium node
Selenium Grid Hub
Selenium standalone
VNC server
現在已經 2017 了