javacro'14 - automatized testing with selenium 2 – juraj Ćutić and aleksander radovan
Upload: hujak-hrvatska-udruga-java-korisnika-croatian-java-user-association
Post on 28-Nov-2014
974 views
DESCRIPTION
When developing software, due to short implementation deadlines, there is very little room for what is considered a key stage: testing. This means testing needs to be efficient and simple for implementation and execution. Selenium is a testing framework for web application, which uses DOM interaction for testing. It can be easily integrated with JUnit, and with the help of WebDriver API, testing for all popular web browsers can be simulated, in addition to web applications adapted to mobile devices. Also, it can be used in interaction with a large number of programming languages. Testing is done from a point of view of the application user, which enables realistic testing scenarios and acceptance tests. In our presentation, we will show an example of using Selenium and present its most important functionalities.TRANSCRIPT
![Page 1: JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander Radovan](https://reader033.vdocuments.mx/reader033/viewer/2022050919/5478e9045906b562048b45d0/html5/thumbnails/1.jpg)
Automatizirano testiranje sa
Seleniumom 2
Juraj Ćutić Aleksander Radovan
![Page 2: JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander Radovan](https://reader033.vdocuments.mx/reader033/viewer/2022050919/5478e9045906b562048b45d0/html5/thumbnails/2.jpg)
Why testing
• Povećanje kvalitete i pouzdanosti proizvoda
• Jednostavnije održavanje
![Page 3: JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander Radovan](https://reader033.vdocuments.mx/reader033/viewer/2022050919/5478e9045906b562048b45d0/html5/thumbnails/3.jpg)
Manual or Automated?
• Ne može osigurati 100% detekciju bugova
• Može biti skupo i dugotrajno
• Ovisi o iskustvu testera
• Može se obavljati i tijekom builda
• Podiže moral
• Ne može u potpunosti zamijeniti testere
![Page 4: JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander Radovan](https://reader033.vdocuments.mx/reader033/viewer/2022050919/5478e9045906b562048b45d0/html5/thumbnails/4.jpg)
Automated testing
Illustracija od tvrtke Segue Technologies
![Page 5: JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander Radovan](https://reader033.vdocuments.mx/reader033/viewer/2022050919/5478e9045906b562048b45d0/html5/thumbnails/5.jpg)
What is Selenium
Framework za automatizirano testiranje web aplikacija
Selenium IDE – GUI za snimanje testiranja
Selenium Web Driver – API za testiranje
Selenium Grid – paralelno testiranje na više različitih browsera
![Page 6: JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander Radovan](https://reader033.vdocuments.mx/reader033/viewer/2022050919/5478e9045906b562048b45d0/html5/thumbnails/6.jpg)
Support
![Page 7: JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander Radovan](https://reader033.vdocuments.mx/reader033/viewer/2022050919/5478e9045906b562048b45d0/html5/thumbnails/7.jpg)
Element locators
• Id - findElement(By.id("elementId"))
• Name - findElement(By.name("elementName"))
• Xpath - findElements(By.xpath("//input[@name='username']"))
• Link Text - findElement(By.linkText("linkText"))
• jQuery (DOM) - ((JavascriptExecutor)driver)
.executeScript("return $('.cheese')[0]")
• CSS - findElement(By.cssSelector("#food span.dairy.aged"))
• By: Class Name, Tag Name, Partial Link Text
![Page 8: JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander Radovan](https://reader033.vdocuments.mx/reader033/viewer/2022050919/5478e9045906b562048b45d0/html5/thumbnails/8.jpg)
Usage
Jednostavna integracija sa Junit-om ili TestNG-om i Jenkinsom
WebDriver webdriver = new FirefoxDriver();
webdriver.get("https://github.com");
List<WebElement> webElements = webdriver.findElements(By
.xpath("//ul[@class='nav logged_out']/li"));
Assert.assertEquals(5, webElements.size());
webdriver.quit();
![Page 9: JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander Radovan](https://reader033.vdocuments.mx/reader033/viewer/2022050919/5478e9045906b562048b45d0/html5/thumbnails/9.jpg)
Components
• Action builds
Actions builder = new Actions(driver);
builder.moveToElement(el).click();
builder.perform();
• Event listeners
beforeClickOn(WebElement element, WebDriver driver)
• Validacije testova (ako je false)
Assert – zaustavlja izvršavanje test
Verify - bilježi grešku u log te nastavlja izvršavati preostale akcije
![Page 10: JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander Radovan](https://reader033.vdocuments.mx/reader033/viewer/2022050919/5478e9045906b562048b45d0/html5/thumbnails/10.jpg)
Selenium Grid
![Page 11: JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander Radovan](https://reader033.vdocuments.mx/reader033/viewer/2022050919/5478e9045906b562048b45d0/html5/thumbnails/11.jpg)
Grid usage
• Potrebna je konfiguracija za svaku instancu WebDrivera
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("firefox");
capabilities.setVersion("7");
capabilities.setPlatform("MAC");
WebDriver webdriver = new RemoteWebDriver(capabilities);
• Junit : - @RunWith(Parameterized.class) – anotacija nad klasom
- @Parameters – anotacija nad metodom u testu
• TestNG : - konfiguracija testova u XML-u
- @Parameters – anotacija nad metodom u testu
![Page 12: JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander Radovan](https://reader033.vdocuments.mx/reader033/viewer/2022050919/5478e9045906b562048b45d0/html5/thumbnails/12.jpg)
Design Pattern
Page Factory – reduciranje nepotrebnog koda
@DefaultUrl("http://www.google.com")
public class SearchPage extends PageObject {
@FindBy(id = "searchString")
@CacheLookup
WebElement searchField; ...}
Page Object :
- OOP korištenje WebDrivera
- preglednost i reduciranje nepotrebnog koda
![Page 13: JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander Radovan](https://reader033.vdocuments.mx/reader033/viewer/2022050919/5478e9045906b562048b45d0/html5/thumbnails/13.jpg)
Advantage
• Simulira realnu interakciju s browserom
• Velika podrška platformi, browsera i jezika za implementaciju
• Isti kod moguće koristi za više različitih browsera
• Mogućnost kreiranja screenshota aplikacije u određenom trenutku
• Open source framework
![Page 14: JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander Radovan](https://reader033.vdocuments.mx/reader033/viewer/2022050919/5478e9045906b562048b45d0/html5/thumbnails/14.jpg)
Practice
• Sporost pri učitavanju stranica u browser
• Veliki promet preko HTTP-a (slike, css ili .js fileovi)
• Aplikacija na kojoj se vrši testiranje mora biti startana
• Problemi u komunikaciji mogu uzrokovati greške u testovima
• Izmjene u funkcionalnosti ili sučelju mogu utjecati na ispravnost testove (potrebno je i njih editirati)
![Page 15: JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander Radovan](https://reader033.vdocuments.mx/reader033/viewer/2022050919/5478e9045906b562048b45d0/html5/thumbnails/15.jpg)
Who Uses Selenium?
![Page 16: JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander Radovan](https://reader033.vdocuments.mx/reader033/viewer/2022050919/5478e9045906b562048b45d0/html5/thumbnails/16.jpg)
Demo
![Page 17: JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander Radovan](https://reader033.vdocuments.mx/reader033/viewer/2022050919/5478e9045906b562048b45d0/html5/thumbnails/17.jpg)
Conclusion
• Automatizirano testiranje je najbolje koristiti kod ponavljajućih i predvidljivih slijedova aktivnosti
• Ne može u potpunosti zamijeniti „ručno” testiranje
• Ne može se testirati sve
• Preporuča uvesti ga u kasnijim fazama razvoja, kad nema jako puno velikih promjena
![Page 18: JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander Radovan](https://reader033.vdocuments.mx/reader033/viewer/2022050919/5478e9045906b562048b45d0/html5/thumbnails/18.jpg)
The end