Photo Credit: https://flic.kr/p/GvVU5
We can choose any model we prefer:
Chrome, IE, Safari, Firefox...
Photo Credit: https://flic.kr/p/dtWtC5
capabilities: [{
// options: firefox, chrome, internet explorer, phantomjs ...
browserName: 'chrome',
version: '27.0',
platform: 'XP',
chromeOptions: {
args: [
'use-fake-device-for-media-stream',
'use-fake-ui-for-media-stream'
]
}
}]
capabilities: [{
browserName: 'chrome'
}, {
browserName: 'firefox',
specs: [
'test/ffOnly/*'
]
},{
browserName: 'phantomjs',
exclude: [
'test/spec/alert.js'
]
}]
Drives the car
WebDriver driver = new HtmlUnitDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
// Find the text input element by its name
WebElement element = driver
.findElement(By.name("q"));
// Enter something to search for
element.sendKeys("Cheese!");
// Now submit the form.
element.submit();
Reads the Dashboard
// Check the title of the page
System.out.println("Page title is: "
+ driver.getTitle());
Photo Credit: https://flic.kr/p/5LpzsN
npm install -g selenium-standalone
selenium-standalone install
selenium-standalone start
webdriverio.remote({
host: 'hub.browserstack.com',
port: 80,
user: 'username',
key: 'hunter2'
}).init();
Drives the car
client
.url('http://cssdevconf.com')
.click('#myButton')
.setValue('.input', 'test123')
Reads the Dashboard
client
.getCssProperty('#someElement', 'width')
.then(function(width) {
console.log(width);
// outputs the following:
// {
// property: 'width',
// value: '100px',
// parsed: {
// type: 'number',
// string: '100px',
// unit: 'px',
// value: 100
// }
// }
});
Feature: Search the Web
As a human
I want to search the web
So I can find information
Scenario: Search for Xolv.io
Given I have visited Google
When I search for "Xolv.io"
Then I see "Xolv.io"
this.When(/^I go to my projects$/, function(done) {
this.browser.url(process.env.ROOT_URL + 'projects')
.waitForVisible('.projects-list')
.call(done);
});
Write the test case
Define the step
Asserting the Speed
car
.getSpeed()
.then(function(speed){
expect(speed).to.equal(20);
})
Photo Credit: https://flic.kr/p/6r2Q4C
Other Styles
mySpeed.should.equal(20);
assert.equal(mySpeed, 20);
client
.url('https://github.com/')
.getElementSize('.header-logo-wordmark', function(err, result) {
expect(result.height).to.equal(26);
expect(result.width).to.equal(89);
})
.getTitle(function(err, title) {
expect(title).to.equal('GitHub · Where software is built');
})
.getCssProperty('a[href="/plans"]', 'color', function(err, result){
expect(result.value).to.equal('rgba(64,120,192,1)');
})
describe('car driving to work', function() {
it('should turn left at 32nd', function() {
slowDown();
turnWheel(360deg);
expect(direction).to.equal('north');
speedUp();
});
it('should turn right at 41st', function() {
slowDown();
turnWheel(-360deg);
expect(direction).to.equal('east');
speedUp();
});
it('should turn left at 53rd', function() {
slowDown();
turnWheel(360deg);
expect(direction).to.equal('north');
speedUp();
});
});
describe('car driving to work', function() {
beforeEach(function() {
slowDown();
});
it('should turn left at 32nd', function() {
turnWheel(360deg);
expect(direction).to.equal('north');
});
it('should turn right at 41st', function() {
turnWheel(-360deg);
expect(direction).to.equal('east');
});
it('should turn left at 53rd', function() {
turnWheel(360deg);
expect(direction).to.equal('north');
});
afterEach(function() {
speedUp();
});
})
describe('car driving to work', function() {
before(function() {
startCar();
});
beforeEach(function() {
slowDown();
});
it('should turn left at 32nd', function() {
turnWheel(360deg);
expect(direction).to.equal('north');
});
afterEach(function() {
speedUp();
});
after(function() {
turnCarOff();
});
})
it('should turn left at 32nd', function () {
car.turnWheel(360deg);
expect(car.direction).to.equal('north');
return car;
});
Photo Credit: https://flic.kr/p/2br6Ww
expect(car.direction).to.equal('north');
car.turnWheel(360deg);
Executes as:
it('should turn left at 32nd', function () {
car
.turnWheel(360deg)
.then(function(){
expect(car.direction).to.equal('north');
});
return car;
});
it('should turn left at 32nd', function () {
car
.turnWheel(360deg)
.getDirection().should.eventually.equal('north');
return car;
});
Alternate (chai-as-promised)