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
969 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
Automatizirano testiranje sa
Seleniumom 2
Juraj Ćutić Aleksander Radovan
Why testing
• Povećanje kvalitete i pouzdanosti proizvoda
• Jednostavnije održavanje
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
Automated testing
Illustracija od tvrtke Segue Technologies
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
Support
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
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();
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
Selenium Grid
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
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
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
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)
Who Uses Selenium?
Demo
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
The end