Upload
future-processing
View
1.563
Download
3
Embed Size (px)
DESCRIPTION
Prezentacja Przemysława Secha z III edycji konferencji Quality Excites.
Citation preview
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.Rev 5058-CO900E
PUBLIC INFORMATION
Automatyczne testy end-to-endaplikacji JavaScript
Przemysław SechSoftware Test Engineer31.05.2014
Email: [email protected]: @PrzemekSech
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 2
Agenda
Demo
Protractor
Selenium
Środowisko
Stos technologiczny
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 3
Rodzaje testów
Testy jednostkoweUnit Tests – A unit test is a software development life cycle (SDLC) component in which a comprehensive testing procedure is individually applied to the smallest parts of a software program for fitness or desired operation.
Testy funkcjonalneFunctional testing is a software testing process used within software development in which software is tested to ensure that it conforms to all requirements. Functional testing is a way of checking software to ensure that it has all the required functionality that's specified within its functional requirements.
Testy End-to-EndEnd-to-end testing is a methodology used to test whether the flow of an application is performing as designed from start to finish. The purpose of carrying out end-to-end tests is to identify system dependencies and to ensure that the right information is passed between various system components and systems.
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 4
Stos technologicznyAplikacja
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 5
Stos technologicznyTesty
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 8
Agenda
Demo
Protractor
Selenium
Środowisko
Stos technologiczny
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 9
Środowisko
Device Hub
iOS Phone
Android Phone
Środowisko rzeczywiste
Selenium Grid
Selenium Node Selenium Node + SDK
Build Server
Środowisko wirtualne
Selenium Node
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 10
Agenda
Demo
Protractor
Selenium
Środowisko
Stos technologiczny
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 11
Selenium
Narzędzie do automatycznej symulacji interakcji użytkownika z przeglądarką.
Selenium IDE
Selenium WebDriver
Selenium Grid
Selenium RC + WebDriver (Selenium 1) = Selenium 2.0
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 12
SeleniumWebDriver (Node)
Sterowniki przeglądarek – niezależne Dostępne języki API – oficjalnie
Sterowniki przeglądarek – wbudowane
Dostępne języki API – nieoficjalnie
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 13
SeleniumGrid (Hub)
HUB
NODE 1(ANDROID)
NODE 2(IE on Windows)
NODE 3(Firefox on Ubuntu)
NODE 4(Safari on MacOS)
NODE 5(Safari on iOS)
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 14
SeleniumWebDriver
localhost
TEST WebDriver
Uruchomienie WD> java -jar selenium-server-standalone.jar
Adres docelowy:http://127.0.0.1:4444/wd/hub
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 15
192.168.0.1
SeleniumWebDriver
localhost
TEST
Uruchomienie WD> java -jar selenium-server-standalone.jar
Adres docelowy:http://192.168.0.1:4444/wd/hub
WebDriver
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 16
SeleniumGrid (Hub)
16
Lokalnie
WebDriverHUB role
TEST WebDriverNODE role
WebDriverNODE role
Lokalnie
WebDriverHUB role
TEST WebDriverNODE role
WebDriverNODE role
Uruchomienie Serwera Grid (Hub)> java -jar selenium-server-standalone.jar -role hub
Uruchomienie Klienta WD (Node)> java -jar selenium-server-standalone.jar -role node -hub http://localhost:4444/grid/register -port xxxxAdres docelowy serwera grid:http://127.0.0.1:4444/grid/console
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 17
192.168.0.3
SeleniumGrid (Hub)
17
Lokalnie
192.168.0.1
WebDriverHUB role
TEST
192.168.0.2
WebDriverNODE role
WebDriverNODE role
WebDriverNODE role
Appium
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 18
Agenda
Demo
Protractor
Selenium
Środowisko
Stos technologiczny
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 20
Protractor
Narzędzie do tworzenia i uruchamianiatestów „end to end” w środowisku przeglądarki, symulując interakcjęużytkownika,
Program wykonywany w obrębie silnika Node.js, Stworzony na bazie WebDriverJS, którego w pełni implementuje i wystawia
całość jego API jako interfejs, Rozszerza API WebDriverJS o funkcjonalności AngularJS Do opisu składni testów pierwotnie wykorzystywał Jasmine, na chwilę
obecną można korzystać z dowolnego frameworka obsługującego JavaScript np. Mocha,
Wspiera testy asynchroniczne wykorzystując technologię Promises, Zawiera wbudowany webdriver-manager pozwalający uruchamiać
samodzielną instancję klienta WebDiver (node).
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 21
Protractor
Projekt utrzymywany jako open-sourcepod kontrolą GitHub:
https://github.com/angular/protractor
Pełna dokumentacja:
https://github.com/angular/protractor/blob/master/docs/api.md
Dostępny jako pakiet npm:
npm install -g protractor
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 22
WebDriverJS
Wszystkie implementacje frameworka WebDriver komunikujące się z przeglądarką lub serwerem Grid za pomocą protokołu na bazie RESTfull web service. Protokół ten wykorzystuje do komunikacji dane w formacie JSON over HTTP.
WebDriverJS jest jedną z implementacji JSON wire protocol udostępniającą metody wyższego poziomu.
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION
Jasmine
23
Jasmine jest frameworkiem z rodziny BDD (Behavior Driven Development) służącymdo testowania aplikacji stworzonych z wykorzystaniem języka JavaScript.
• niezależny od innych framworków JavaScript,• nie wymaga istnienia struktury DOM,• posiada czytelną, zrozumiałą składnię pozwalającą na szybkie pisanie
testów
Jasmine-node dla node.js jest dostępny jako pakiet npm:
npm install -g jasmine-node
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 24
Jasmine / Protractorprzykład
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION
Webdriver-manager
25
Narzędzie wbudowane w Protractor, pozwalające na łatwą instalację, aktualizację i uruchomienie lokalnej instancji klienta WebDriver (node)
Instalacja i aktualizacja:
Uruchomienie:
Automatycznie uruchamia sterownik ChromeDriver
> webdriver-manager update
> webdriver-manager start
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 26
Protractorkonfiguracja testów
Uruchomienie testów:
Plik konfiguracyjny pozwala zdefiniować: seleniumAddress – adres instancji Selenium (hub lub node) pod którą
należy wysłać testy, specs – lista plików zawierających testy, capabilities – parametry środowiska, decydują o środowisku
uruchomieniowym testów;multiCapabilities – opisują tablicę środowisk na których testy zostaną uruchomione współbieżnie,
baseUrl: bazowy adres aplikacji testowej, onPrepare – funkcja wykonująca się przed rozpoczęciem testów
reporter – metoda generowania raportu z testów
> protractor config.js
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 27
Protractorraportowanie
Protractor pozwala wyświetlać postępbieżących testów oraz ich status zapomocą paska postępu
Raportowanie do pliku XML dzięki bibliotece Jasmine-ReportersonPrepare: function () { "use strict"; require('jasmine-reporters'); jasmine.getEnv().addReporter(new jasmine .JUnitXmlReporter('./results/chrome', true, 'Chrome'));},
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 28
ProtractorPage Object Model
Page Object Model (POM) jest wzorcemprojektowym bazującym na MVC.
Zadania: Opisanie struktury stron o odrębnych klasach (View) Opisanie zależności i interakcji między stronami (Control) Budowa testów w oparciu o opisane interakcje na elementach strony
Zalety: Redukcja zduplikowanego kodu Łatwiejsze utrzymanie testów, podczas częstych zmian aplikacji (Agile)
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 29
Demo
GitHub: https://github.com/psech/QualityExcites2014-Demo
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 30
Pytania i odpowiedzi
GoogleDrive: http://goo.gl/m46H8J
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.
www.rockwellautomation.com
Follow ROKAutomation on Facebook & Twitter.Connect with us on LinkedIn.
Rev 5058-CO900F
PUBLIC INFORMATION
Dziękuję
Email: [email protected]: @PrzemekSech