Алексей Петров, Mail.Ru Group, "Организация конвейера автоматизации тестирования"
Обзор автоматизации тестирования на JavaScript
-
Upload
comaqaby -
Category
Technology
-
view
235 -
download
4
Transcript of Обзор автоматизации тестирования на JavaScript
![Page 1: Обзор автоматизации тестирования на JavaScript](https://reader036.fdocuments.net/reader036/viewer/2022062823/587290ec1a28ab36118b62d7/html5/thumbnails/1.jpg)
Viacheslau Bushyla
JavaScript in test automation
![Page 2: Обзор автоматизации тестирования на JavaScript](https://reader036.fdocuments.net/reader036/viewer/2022062823/587290ec1a28ab36118b62d7/html5/thumbnails/2.jpg)
Viacheslau BushylaSenior Software Test Automation Engineer
![Page 3: Обзор автоматизации тестирования на JavaScript](https://reader036.fdocuments.net/reader036/viewer/2022062823/587290ec1a28ab36118b62d7/html5/thumbnails/3.jpg)
3
Node js platform to execute JS
Node.JS = V8 + I/O + libraries
V8 - fast - modern (all standards) - efficiently uses resources
I/O - files - network - input/output
NPM - installs libraries
JavaScript and Node js
![Page 4: Обзор автоматизации тестирования на JavaScript](https://reader036.fdocuments.net/reader036/viewer/2022062823/587290ec1a28ab36118b62d7/html5/thumbnails/4.jpg)
4
var employee = { active: true, age: 20, name: "Ivan", skills: ['Java', 'AT', 'JavaScript'], employer: {company: "Epam"}, workStation: null, summary: undefined, toString: function () { console.log("Name: ", this.name, "Age: ", this.age); }}
typeof(employee.active)"boolean"typeof(employee.age)"number"typeof(employee.name)"string"typeof(employee.skills)"object"typeof(employee.employer)"object"typeof(employee.workStation)"object"typeof(employee.summary)"undefined"typeof(employee.toString)"function"
JavaScript types
![Page 5: Обзор автоматизации тестирования на JavaScript](https://reader036.fdocuments.net/reader036/viewer/2022062823/587290ec1a28ab36118b62d7/html5/thumbnails/5.jpg)
5
JSON - JavaScript Object Notation
var objectToString = JSON.stringify(employee);
"{ "active":true, "age":20, "name":"Ivan", "skills":["Java","AT","JavaScript"], "employer":{"company":"Epam"}, "workStation":null}"
var stringToObject = JSON.parse(objectToString)
Object
Object {active: true, age: 20, name: "Ivan", skills: Array[3], employer: Object…}
HTTP
DB
File
Browser
JavaScript and JSON
![Page 6: Обзор автоматизации тестирования на JavaScript](https://reader036.fdocuments.net/reader036/viewer/2022062823/587290ec1a28ab36118b62d7/html5/thumbnails/6.jpg)
6
Stack
Input/Output
console.log("start");var file = fs.readFile('/etc/passwd')console.log("done");
main()
readFileconsole.log("end")console.log("done")console.log("start")fs.readFile(cb)
start
done
task queue
console
Synchronous JavaScript
![Page 7: Обзор автоматизации тестирования на JavaScript](https://reader036.fdocuments.net/reader036/viewer/2022062823/587290ec1a28ab36118b62d7/html5/thumbnails/7.jpg)
7
Stack
webapis/IO
event loop
cb
console.log("start");fs.readFile('/etc/passwd', (err, data) => { if (err) throw err; console.log("done");});console.log("end");
main()
cbconsole.log("end")console.log("done")console.log("start")fs.readFile(cb)
startend
done
task queue
console
Asynchronous JavaScript
![Page 8: Обзор автоматизации тестирования на JavaScript](https://reader036.fdocuments.net/reader036/viewer/2022062823/587290ec1a28ab36118b62d7/html5/thumbnails/8.jpg)
8
Stack
driver
console.log("start");driver.findElement(locator).then(function (q) { console.log("done");}).then(function () { console.log("end");});
main()
driver.findElementconsole.log("done")console.log("end")console.log("start"
)driver.findElement()
startdone
end
console
Synchronization with Promises
![Page 9: Обзор автоматизации тестирования на JavaScript](https://reader036.fdocuments.net/reader036/viewer/2022062823/587290ec1a28ab36118b62d7/html5/thumbnails/9.jpg)
9
Promise - represents the eventual result of an asynchronous operation.
Then method, which registers callbacks to receive either a promise’s eventual value or the reason why the promise cannot be fulfilled.
<pending>
fulfilled
rejected
Promises
![Page 10: Обзор автоматизации тестирования на JavaScript](https://reader036.fdocuments.net/reader036/viewer/2022062823/587290ec1a28ab36118b62d7/html5/thumbnails/10.jpg)
10
Web Browser Web Serverrequest url
HTML page
AJAX request
response
constant long polling requests....
Synchronization
![Page 11: Обзор автоматизации тестирования на JavaScript](https://reader036.fdocuments.net/reader036/viewer/2022062823/587290ec1a28ab36118b62d7/html5/thumbnails/11.jpg)
11
● Run test framework with CLI and configuration file● Integration with popular JavaScript test framework - Jasmine, Cucumber● Maintains a queue of pending promises to keep execution organized● Provides Api to locate and perform actions on DOM elements● Provides synchronization with Angular application
Protractor test framework
![Page 12: Обзор автоматизации тестирования на JavaScript](https://reader036.fdocuments.net/reader036/viewer/2022062823/587290ec1a28ab36118b62d7/html5/thumbnails/12.jpg)
12
Page
http pending requests
Browser
DriverWD request
SyncAngular
WD response
Synchronization with Angular
![Page 13: Обзор автоматизации тестирования на JavaScript](https://reader036.fdocuments.net/reader036/viewer/2022062823/587290ec1a28ab36118b62d7/html5/thumbnails/13.jpg)
13
RunnerProtractor
Selenium
WDApi
AdapterJasmine
Cucumber
Mocha
Protractor decomposition
![Page 14: Обзор автоматизации тестирования на JavaScript](https://reader036.fdocuments.net/reader036/viewer/2022062823/587290ec1a28ab36118b62d7/html5/thumbnails/14.jpg)
14
// C#public class LoginPage{ [FindsBy(How = How.Id, Using = "bbcid_unique")] private IWebElement userName;
[FindsBy(How = How.Id, Using = "bbcid_password")] private IWebElement password;
[FindsBy(How = How.Id, Using = "bbcid_submit_button")] private IWebElement signInButton;
[FindsBy(...)] private IList<IWebElement> someElements;
public LoginPage() { PageFactory.InitElements(DriverManager.getDriver(), this); }
public void login(string login, string password) { userName.SendKeys(login); password.SendKeys(password); signInButton.Click(); }}
// JSvar LoginPage = function() { this.userName = element(by.id('bbcid_unique')); this.password = element(by.id('bbcid_password')); this.signInButton = element(by.id('bbcid_submit_button')); this.someElements = element.all(by.tagName('img')); this.login = function (login, password) { userName.sendKeys; password.sendKeys(password); signInButton.click(); };};
module.exports = LoginPage;
Page Object
![Page 15: Обзор автоматизации тестирования на JavaScript](https://reader036.fdocuments.net/reader036/viewer/2022062823/587290ec1a28ab36118b62d7/html5/thumbnails/15.jpg)
15
Page Element- verifyValidationError- checkElement
Clickable Element- click
Custom Element- setElement
Dropdown- setElementByValue- setElementBydate- setElementByIndex
Radiogroup- setElementByIdFragment- setElementByIndex
Textfield- fillElement
BooleanRadioGroup- setElementByIdFragment
Page Elements
![Page 16: Обзор автоматизации тестирования на JavaScript](https://reader036.fdocuments.net/reader036/viewer/2022062823/587290ec1a28ab36118b62d7/html5/thumbnails/16.jpg)
16
carRegNumber: {set: {value: 'MF15MYC'}},
findCarButton: 'click',
licenceIssued: {check: {idFragment: 1}},
carRegNumber: {set: {value: false}},
howLongHeldLicenceYear: "verifyValidationError",
Interaction with JSON profile
![Page 17: Обзор автоматизации тестирования на JavaScript](https://reader036.fdocuments.net/reader036/viewer/2022062823/587290ec1a28ab36118b62d7/html5/thumbnails/17.jpg)
17
1. Support by Angular community2. High Level abstraction (built-in factories,
builders, workers etc, configuration through config file)
3. Supports JS test frameworks (mocha, jasmine, cucumber)
4. Improved Control Flow (Promises chaining)5. Integration with CI (Bamboo Atlassian, Jenkins,
Teamcity etc.)
1. Tests quite slow2. Build in Solutions make you dependent3. Easy make simple solution build-in for
integration tests4. You have to create complex solution if create
tests as user do
Protractor pros and cons
![Page 18: Обзор автоматизации тестирования на JavaScript](https://reader036.fdocuments.net/reader036/viewer/2022062823/587290ec1a28ab36118b62d7/html5/thumbnails/18.jpg)
18
1. Native support JSON2. NPM - build in solutions(REST, BD, reports, IO
libraries)3. Integration with modern web UI solution4. Integration with services, support and
documentation5. Popular Node JS ecosystem6. Easy to start7. Small community
1. Slower than others platform2. Doesn’t support strong typisation3. Slow down development4. Platform depended5. Dinamic6. Async7. Non-standard approaches and code design
patterns
Conclusions
![Page 19: Обзор автоматизации тестирования на JavaScript](https://reader036.fdocuments.net/reader036/viewer/2022062823/587290ec1a28ab36118b62d7/html5/thumbnails/19.jpg)
19
https://developer.mozilla.org/ru/docs/Web/JavaScript - mozila development network
https://nodejs.org - Node JS official
https://www.npmjs.com/ - NPM official
https://www.npmjs.com/package/selenium-webdriver - WebDriver JS official documentation
http://protractortest.org - Protractor official
http://jasmine.github.io/ - Jasmine official
https://cucumber.io/ - Cucumber official
Info sources