Интеграционное тестирование
Сергей Жигалов
Интеграционное тестирование
Сергей Жигалов
Курс разработки интерфейсов, 2014 г.
Призраки и приведения
CasperJS API
- The casper module
- The clientutils module
- The colorizer module
- The mouse module
- The tester module
- The utils module
CasperJS API
- The casper module
- The clientutils module
- The colorizer module
- The mouse module
- The tester module
- The utils module
CasperJS run
- casperjs selftest
- WebStorm
- casperjs test.js
DEMO 01
CasperJS tester
- assert(Boolean condition[, String message])
- assertEquals(mixed testValue, mixed expected[, String message])s
- assertExists(String selector[, String message])
- assertTitle(String expected[, String message])
- assertVisible(String selector[, String message])
- assertSelectorHasText(String selector, String text[, String message])
- ...
DEMO 02 && DEMO 03
capture
CasperJS capture
- capture(String targetFilepath, [Object clipRect, Object imgOptions])
- clipRect: { top: 0, left: 0, width: 800, height: 600 }
- imgOptions: { format: 'jpg', quality: 75 }
- // bmp, jpg, jpeg, png, ppm, tiff, xbm and xpm
- captureBase64(String format[, Mixed area])
- String: area is a CSS3 selector string
- clipRect: { top: 0, left: 0, width: 800, height: 600 }
DEMO 04
Асинхронность
CasperJS wait
- wait(Number timeout[, Function then])
- waitFor(Function testFx[, Function then, Function onTimeout, Number timeout, Object details])
- waitForAlert(Function then[, Function onTimeout, Number timeout])
- waitForUrl(String|RegExp url[, Function then, Function onTimeout, Number timeout])
- waitForSelector(String selector[, Function then, Function onTimeout, Number timeout])
- waitUntilVisible(String selector[, Function then, Function onTimeout, Number timeout])
- ...
DEMO 05
Karma Install
- $ npm install karma --save-dev
- $ npm install karma-mocha --save-dev
- $ npm install karma-chai karma-chai-plugins --save-dev
- $ npm install karma-chrome-launcher --save-dev
- $ npm install karma-... --save-dev
- $ npm install -g karma-cli
Karma Config
- basePath: ''
- frameworks: ['mocha', 'chai'],
- files: [ 'test/*.test.js' ]
- autoWatch: true
- browsers: ['Chrome']
- ...
- $ karma init my.conf.js
DEMO 01
Protractor How it works
Protractor Install
- $ npm install -g protractor
- $ webdriver-manager update
- $ webdriver-manager start
- $ npm install -g mocha
- $ npm install chai
- $ npm install chai-as-promised
Protractor chai
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
var expect = chai.expect;
expect(browser.getTitle()).to.eventually.equal('URL encoded');
Protractor Config
{
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: [ 'test/*.test.js' ],
framework: 'mocha',
mochaOpts: { reporter: 'spec', timeout: 4000 },
capabilities: { 'browserName': 'chrome', 'version': 'ANY' },
baseUrl: 'http://localhost:63342'
}
Protractor Browser
browser.get(destination, opt_timeout)
browser.sleep(timeout)
browser.back()
browser.forward()
browser.refresh()
browser.getCookie(name)
...
DEMO 02
Protractor Angular
browser.ignoreSynchronization = true;
DEMO 03
Protractor Locators
by.css('.myclass')
by.id('myid')
by.tagName('div')
element(by.css('some-css')).element(by.tagName('tag-within-css'));
Protractor Actions
var el = element(locator);
el.isPresent();
el.isDisplayed();
el.click();
el.sendKeys('my text');
el.clear();
el.getAttribute('value');
el.getText().then(function(text) {
console.log(text);
});
DEMO 04
Protractor wait
browser.wait(fn, timeout, opt_message)
DEMO 05
DEMO 06