Automatyczne testy end-to-end aplikacji JavaScript.

28
Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved. Rev 5058-CO900E PUBLIC INFORMATION Automatyczne testy end-to-end aplikacji JavaScript Przemysław Sech Software Test Engineer 31.05.2014 Email: [email protected] Twitter: @PrzemekSech

description

Prezentacja Przemysława Secha z III edycji konferencji Quality Excites.

Transcript of Automatyczne testy end-to-end aplikacji JavaScript.

Page 1: Automatyczne testy end-to-end aplikacji JavaScript.

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

Page 2: Automatyczne testy end-to-end aplikacji JavaScript.

Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 2

Agenda

Demo

Protractor

Selenium

Środowisko

Stos technologiczny

Page 3: Automatyczne testy end-to-end aplikacji JavaScript.

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.

Page 4: Automatyczne testy end-to-end aplikacji JavaScript.

Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 4

Stos technologicznyAplikacja

Page 5: Automatyczne testy end-to-end aplikacji JavaScript.

Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 5

Stos technologicznyTesty

Page 6: Automatyczne testy end-to-end aplikacji JavaScript.

Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 8

Agenda

Demo

Protractor

Selenium

Środowisko

Stos technologiczny

Page 7: Automatyczne testy end-to-end aplikacji JavaScript.

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

Page 8: Automatyczne testy end-to-end aplikacji JavaScript.

Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 10

Agenda

Demo

Protractor

Selenium

Środowisko

Stos technologiczny

Page 9: Automatyczne testy end-to-end aplikacji JavaScript.

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

Page 10: Automatyczne testy end-to-end aplikacji JavaScript.

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

Page 11: Automatyczne testy end-to-end aplikacji JavaScript.

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)

Page 12: Automatyczne testy end-to-end aplikacji JavaScript.

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

Page 13: Automatyczne testy end-to-end aplikacji JavaScript.

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

Page 14: Automatyczne testy end-to-end aplikacji JavaScript.

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

Page 15: Automatyczne testy end-to-end aplikacji JavaScript.

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

Page 16: Automatyczne testy end-to-end aplikacji JavaScript.

Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 18

Agenda

Demo

Protractor

Selenium

Środowisko

Stos technologiczny

Page 17: Automatyczne testy end-to-end aplikacji JavaScript.

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).

Page 18: Automatyczne testy end-to-end aplikacji JavaScript.

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

Page 19: Automatyczne testy end-to-end aplikacji JavaScript.

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.

Page 20: Automatyczne testy end-to-end aplikacji JavaScript.

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

Page 21: Automatyczne testy end-to-end aplikacji JavaScript.

Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 24

Jasmine / Protractorprzykład

Page 22: Automatyczne testy end-to-end aplikacji JavaScript.

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

Page 23: Automatyczne testy end-to-end aplikacji JavaScript.

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

Page 24: Automatyczne testy end-to-end aplikacji JavaScript.

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'));},

Page 25: Automatyczne testy end-to-end aplikacji JavaScript.

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)

Page 26: Automatyczne testy end-to-end aplikacji JavaScript.

Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 29

Demo

GitHub: https://github.com/psech/QualityExcites2014-Demo

Page 27: Automatyczne testy end-to-end aplikacji JavaScript.

Copyright © 2014 Rockwell Automation, Inc. All Rights Reserved.PUBLIC INFORMATION 30

Pytania i odpowiedzi

GoogleDrive: http://goo.gl/m46H8J

Page 28: Automatyczne testy end-to-end aplikacji JavaScript.

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