AUTOMATED TESTING
OF
WEB APPLICATIONS
SAMUEL BORG
AUTOMATED TESTING
• Most software applications today are web-based applications running on a
web browser
• Test automation means using a software tool to run repetitive tests using
different, pre-defined test cases on the system under test (SUT)
• Advantages:
• Cheaper and Efficient
• Although developing automation may take time, the code can be executed for unlimited amount
of times
• Speed of execution and percentage of test coverage is better than that of a human tester
• Running tests 24/7
• Tests can be scheduled to run over night to return results in the morning
ADVANTAGES OF AUTOMATED TESTING
• Reusability
• No need redo all the steps or change the code every time
• In some cases, it is independent of the OS or browser
• Same test can be used for other applications / scenarios of same application
• Multilingual applications
• Consistency
• Since it is not prone to human-error
• All screens/features are not ignored
• Volume
• Run on thousands of devices/platforms simultaneously
• Perform unlimited amount of test cases
• Example: Creating thousands of users, each with different parameters
LIMITATIONS OF AUTOMATED TESTING
Manual Testing may be more appropriate if:
• User Interface is prone to change constantly in the near
future
• Any automation would need to be rewritten anyway
• Time Restriction
• Automation scripting takes time
• If project is within a tight deadline, and there is no test automation
available then the priority is to get testing done rather than automating it
and carrying it out repeatedly
• Exploratory Testing
• Need to creative use of the application
https://youtu.be/RbSlW8jZFe8?t=5s
LET’S NARROW IT
DOWN A LITTLE…
SELENIUM
• A software testing framework for web
applications
• Suite of tools used to automate
• many web browsers
• across different operating systems
• controlled by many programming
languages and testing frameworks
• Open-source
• Free to use
SELENIUM
Selenium
Grid
Selenium
WebDrive
r
Selenium
Remote
Control
Selenium
IDE
SELENIUM IDE
Selenium
IDE
• An Integrated Development environment for Selenium
tests
• A Firefox Add-On for Firefox 2.0+
• Allows recording, editing, monitoring and debugging tests
• Records and processes commands automatically, supports
manual editing complete with support for auto completion
and moving around
SELENIUM IDE
Selenium
IDE
DEMO
SELENIUM GRID
Selenium
Grid
• Runs multiple tests on different machines using
different browsers in parallel
• Two reasons to opt for Selenium Grid:
1. To run your cross-browser compatibility tests
against multiple browsers, multiple versions
of browser, and browsers running on different
operating systems.
2. To reduce the time it takes for the test suite to
complete a test pass
One same test case for 100 different
environments
SELENIUM REMOTE CONTROL
Selenium
Remote
Control
• A client/server system written in
Java
• Accepts commands via HTTP for
the browser
• There are client libraries to write in
any language from PHP, Python,
Ruby, .NET, Perl and Java.
• Thanks to a test domain-
specific language, Selenese
Selenium
Grid
Selenium
Remote
Control
SELENIUM WEB DRIVER
Selenium
WebDrive
r
• Accepts commands (in Selenese or via Client API)
and processes them to automate the browser
• Implemented through browser-specific driver
• Unlike Selenium Remote Control, WebDriver does
not need a special server to execute tests therefore
making it faster
• WebDriver uses native operating system level
control rather than browser-based JavaScript
commands to drive the browser
• Handles popups, alerts, multiple windows, AJAX,
Drag-and-drop
SELENIUM WEB DRIVER
Selenium
WebDrive
r
WebDriver
Java
C#
JavaScript
PHPPerl
Python
Ruby
SELENIUM WEB DRIVER
Selenium
WebDrive
r
WebDriver
Firefox
Internet
Explorer
Edge
Google
Chrome
Safari
Opera
WEBDRIVER CLIENTS
• Download zip file from:
http://docs.seleniumhq.org/download
/
• One should have:
• 2 .jar files
• Changelog
• ‘libs’ folder
WEBDRIVER CLIENTS
• …or just use a build tool like Maven:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.0</version>
</dependency>
WEBDRIVER CLIENTS
• Also important, import JUnit test framework
• JUnit is a Java test framework
• Alternatives are TestNG and, for C#, NUnit
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
</dependency>
WEBDRIVERS
• Download the driver according to your web browser
• ChromeDriver For Chrome:
https://sites.google.com/a/chromium.org/chromedriver/downloads
• GeckoDriver (version Marionette) for Firefox:
https://github.com/mozilla/geckodriver/releases
WEBDRIVERS
WebDriver driver;
@Before
public void setup() {
System.setProperty("webdriver.chrome.driver",
"/users/Samuel/Downloads/chromedriver.exe");
driver = new ChromeDriver();
}
WEBDRIVER COMMANDS
• driver.navigate().to(“http://google.com”);
• driver.navigate().back();
• driver.navigate().refresh();
• driver.sendKeys(“test”);
• driver.click();
• driver.getText();
• driver.getCssvalue();
• driver.close();
WEBDRIVER COMMANDS – TYPES OF LOCATORS
driver.findElement(By.id(“ElementID”));
WEBDRIVER COMMANDS - XPATH
driver.findElement(By.xpath(“/html/body/div[1]/div[2]/div/div[2]/article/div/table/tbody/tr[2]/td[1]”)).getText();
WEBDRIVER COMMANDS
FINDING ELEMENTS USING XPATH
• For Firefox:
• FirePath (https://addons.mozilla.org/en-US/firefox/addon/firepath/)
• Requires FireBug Add-On !
• WebDriver Element Locator (https://addons.mozilla.org/en-
us/firefox/addon/element-locator-for-webdriv/)
• For Chrome:
• XPath Helper (https://chrome.google.com/webstore/detail/xpath-
helper/hgimnogjllphhhkhlmebbmlgjoejdpjl?hl=en)
WEBDRIVER COMMANDS – FURTHER INFORMATION
• driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
• promptAlert .accept();
• // Create new WebDriver wait
WebDriverWait wait = new WebDriverWait(driver, 10);
// Wait for Alert to be present
Alert myAlert =
wait.until(ExpectedConditions.alertIsPresent());
WEBDRIVER COMMANDS – FURTHER INFORMATION
WebElement From = driver.findElement(By.xpath(".//*[@id='userChecklists']/li[1]/a/span"));
WebElement To = driver.findElement(By.xpath(".//*[@id='userChecklists']/li[4]/a/span"));
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(From)
.moveToElement(To)
.release(To)
.build();
dragAndDrop.perform();
TESTNG FRAMEWORK - TESTNG
• Ability to produce HTML Reports, after execution
• Results of test cases
• Annotations to organize methods and for the framework
to execute accordingly
• Testing methods in parallel is possible
• Test cases can be grouped and prioritised easily
• Ability to pass parameters
AUTOMATION FRAMEWORKS
TESTNG ANNOTATIONS
Annotation Description
@BeforeSuite The annotated method will be run only once before all tests in this suite have run.
@AfterSuite The annotated method will be run only once after all tests in this suite have run.
@BeforeClass The annotated method will be run only once before the first test method in the current class is
invoked.
@AfterClass The annotated method will be run only once after all the test methods in the current class have
run.
@BeforeTest The annotated method will be run before any test method belonging to the classes inside the
<test> tag is run.
@AfterTest The annotated method will be run after all the test methods belonging to the classes inside the
<test> tag have run.
@BeforeGroups The list of groups that this configuration method will run before. This method is guaranteed to run
shortly before the first test method that belongs to any of these groups is invoked.
@AfterGroups The list of groups that this configuration method will run after. This method is guaranteed to run
shortly after the last test method that belongs to any of these groups is invoked.
@BeforeMethod The annotated method will be run before each test method.
@AfterMethod The annotated method will be run after each test method.
@Parameters Describes how to pass parameters to a @Test method.
@Test Marks a class or a method as a part of the test.
AUTOMATION FRAMEWORKS – DATA DRIVEN APPROACH
AUTOMATION FRAMEWORKS – DATA DRIVEN APPROACH
1. Download Apache POI Jar files
1. Apache POI is a Java API for Microsoft Documents access
2. Add Jar files to project library
3. Place an Excel file in the package location
4. Set location using setExcelFile()
5. Use FileInputStream() to open Excel file and read
1. Declare XSSFWorkbook()
2. .getSheet() to access Excel sheet
More information: http://toolsqa.com/selenium-webdriver/data-driven-testing-
excel-poi/
AUTOMATION FRAMEWORKS – DATA DRIVEN APPROACH
ONE MORE SLIDE…
REFERENCES
• http://www.seleniumhq.org/docs/
• http://toolsqa.com/selenium-webdriver/
• https://www.tutorialspoint.com/software_testing_dictionary/automated_softwa
re_testing.htm
• tps://www.tutorialspoint.com/selenium/s
• https://testobject.com/blog/2015/07/top-10-benefits-of-automated-
testing.html
• https://www.youtube.com/watch?v=DO8KVe00kcU
• http://www.slideshare.net/pekkaklarck/introduction-to-test-automation
• https://poi.apache.org/
THANK YOU FOR YOUR ATTENTION!
ANY QUESTIONS?
:)

Automated Testing on Web Applications

  • 1.
  • 2.
    AUTOMATED TESTING • Mostsoftware applications today are web-based applications running on a web browser • Test automation means using a software tool to run repetitive tests using different, pre-defined test cases on the system under test (SUT) • Advantages: • Cheaper and Efficient • Although developing automation may take time, the code can be executed for unlimited amount of times • Speed of execution and percentage of test coverage is better than that of a human tester • Running tests 24/7 • Tests can be scheduled to run over night to return results in the morning
  • 3.
    ADVANTAGES OF AUTOMATEDTESTING • Reusability • No need redo all the steps or change the code every time • In some cases, it is independent of the OS or browser • Same test can be used for other applications / scenarios of same application • Multilingual applications • Consistency • Since it is not prone to human-error • All screens/features are not ignored • Volume • Run on thousands of devices/platforms simultaneously • Perform unlimited amount of test cases • Example: Creating thousands of users, each with different parameters
  • 4.
    LIMITATIONS OF AUTOMATEDTESTING Manual Testing may be more appropriate if: • User Interface is prone to change constantly in the near future • Any automation would need to be rewritten anyway • Time Restriction • Automation scripting takes time • If project is within a tight deadline, and there is no test automation available then the priority is to get testing done rather than automating it and carrying it out repeatedly • Exploratory Testing • Need to creative use of the application
  • 5.
  • 6.
  • 7.
    SELENIUM • A softwaretesting framework for web applications • Suite of tools used to automate • many web browsers • across different operating systems • controlled by many programming languages and testing frameworks • Open-source • Free to use
  • 8.
  • 9.
    SELENIUM IDE Selenium IDE • AnIntegrated Development environment for Selenium tests • A Firefox Add-On for Firefox 2.0+ • Allows recording, editing, monitoring and debugging tests • Records and processes commands automatically, supports manual editing complete with support for auto completion and moving around
  • 10.
  • 11.
    SELENIUM GRID Selenium Grid • Runsmultiple tests on different machines using different browsers in parallel • Two reasons to opt for Selenium Grid: 1. To run your cross-browser compatibility tests against multiple browsers, multiple versions of browser, and browsers running on different operating systems. 2. To reduce the time it takes for the test suite to complete a test pass One same test case for 100 different environments
  • 12.
    SELENIUM REMOTE CONTROL Selenium Remote Control •A client/server system written in Java • Accepts commands via HTTP for the browser • There are client libraries to write in any language from PHP, Python, Ruby, .NET, Perl and Java. • Thanks to a test domain- specific language, Selenese
  • 13.
  • 14.
    SELENIUM WEB DRIVER Selenium WebDrive r •Accepts commands (in Selenese or via Client API) and processes them to automate the browser • Implemented through browser-specific driver • Unlike Selenium Remote Control, WebDriver does not need a special server to execute tests therefore making it faster • WebDriver uses native operating system level control rather than browser-based JavaScript commands to drive the browser • Handles popups, alerts, multiple windows, AJAX, Drag-and-drop
  • 15.
  • 16.
  • 17.
    WEBDRIVER CLIENTS • Downloadzip file from: http://docs.seleniumhq.org/download / • One should have: • 2 .jar files • Changelog • ‘libs’ folder
  • 18.
    WEBDRIVER CLIENTS • …orjust use a build tool like Maven: <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>2.53.0</version> </dependency>
  • 19.
    WEBDRIVER CLIENTS • Alsoimportant, import JUnit test framework • JUnit is a Java test framework • Alternatives are TestNG and, for C#, NUnit <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.4</version> </dependency>
  • 20.
    WEBDRIVERS • Download thedriver according to your web browser • ChromeDriver For Chrome: https://sites.google.com/a/chromium.org/chromedriver/downloads • GeckoDriver (version Marionette) for Firefox: https://github.com/mozilla/geckodriver/releases
  • 21.
    WEBDRIVERS WebDriver driver; @Before public voidsetup() { System.setProperty("webdriver.chrome.driver", "/users/Samuel/Downloads/chromedriver.exe"); driver = new ChromeDriver(); }
  • 22.
    WEBDRIVER COMMANDS • driver.navigate().to(“http://google.com”); •driver.navigate().back(); • driver.navigate().refresh(); • driver.sendKeys(“test”); • driver.click(); • driver.getText(); • driver.getCssvalue(); • driver.close();
  • 23.
    WEBDRIVER COMMANDS –TYPES OF LOCATORS driver.findElement(By.id(“ElementID”));
  • 24.
    WEBDRIVER COMMANDS -XPATH driver.findElement(By.xpath(“/html/body/div[1]/div[2]/div/div[2]/article/div/table/tbody/tr[2]/td[1]”)).getText();
  • 25.
    WEBDRIVER COMMANDS FINDING ELEMENTSUSING XPATH • For Firefox: • FirePath (https://addons.mozilla.org/en-US/firefox/addon/firepath/) • Requires FireBug Add-On ! • WebDriver Element Locator (https://addons.mozilla.org/en- us/firefox/addon/element-locator-for-webdriv/) • For Chrome: • XPath Helper (https://chrome.google.com/webstore/detail/xpath- helper/hgimnogjllphhhkhlmebbmlgjoejdpjl?hl=en)
  • 26.
    WEBDRIVER COMMANDS –FURTHER INFORMATION • driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); • promptAlert .accept(); • // Create new WebDriver wait WebDriverWait wait = new WebDriverWait(driver, 10); // Wait for Alert to be present Alert myAlert = wait.until(ExpectedConditions.alertIsPresent());
  • 27.
    WEBDRIVER COMMANDS –FURTHER INFORMATION WebElement From = driver.findElement(By.xpath(".//*[@id='userChecklists']/li[1]/a/span")); WebElement To = driver.findElement(By.xpath(".//*[@id='userChecklists']/li[4]/a/span")); Actions builder = new Actions(driver); Action dragAndDrop = builder.clickAndHold(From) .moveToElement(To) .release(To) .build(); dragAndDrop.perform();
  • 28.
    TESTNG FRAMEWORK -TESTNG • Ability to produce HTML Reports, after execution • Results of test cases • Annotations to organize methods and for the framework to execute accordingly • Testing methods in parallel is possible • Test cases can be grouped and prioritised easily • Ability to pass parameters
  • 29.
    AUTOMATION FRAMEWORKS TESTNG ANNOTATIONS AnnotationDescription @BeforeSuite The annotated method will be run only once before all tests in this suite have run. @AfterSuite The annotated method will be run only once after all tests in this suite have run. @BeforeClass The annotated method will be run only once before the first test method in the current class is invoked. @AfterClass The annotated method will be run only once after all the test methods in the current class have run. @BeforeTest The annotated method will be run before any test method belonging to the classes inside the <test> tag is run. @AfterTest The annotated method will be run after all the test methods belonging to the classes inside the <test> tag have run. @BeforeGroups The list of groups that this configuration method will run before. This method is guaranteed to run shortly before the first test method that belongs to any of these groups is invoked. @AfterGroups The list of groups that this configuration method will run after. This method is guaranteed to run shortly after the last test method that belongs to any of these groups is invoked. @BeforeMethod The annotated method will be run before each test method. @AfterMethod The annotated method will be run after each test method. @Parameters Describes how to pass parameters to a @Test method. @Test Marks a class or a method as a part of the test.
  • 30.
    AUTOMATION FRAMEWORKS –DATA DRIVEN APPROACH
  • 31.
    AUTOMATION FRAMEWORKS –DATA DRIVEN APPROACH 1. Download Apache POI Jar files 1. Apache POI is a Java API for Microsoft Documents access 2. Add Jar files to project library 3. Place an Excel file in the package location 4. Set location using setExcelFile() 5. Use FileInputStream() to open Excel file and read 1. Declare XSSFWorkbook() 2. .getSheet() to access Excel sheet More information: http://toolsqa.com/selenium-webdriver/data-driven-testing- excel-poi/
  • 32.
    AUTOMATION FRAMEWORKS –DATA DRIVEN APPROACH
  • 33.
  • 34.
    REFERENCES • http://www.seleniumhq.org/docs/ • http://toolsqa.com/selenium-webdriver/ •https://www.tutorialspoint.com/software_testing_dictionary/automated_softwa re_testing.htm • tps://www.tutorialspoint.com/selenium/s • https://testobject.com/blog/2015/07/top-10-benefits-of-automated- testing.html • https://www.youtube.com/watch?v=DO8KVe00kcU • http://www.slideshare.net/pekkaklarck/introduction-to-test-automation • https://poi.apache.org/
  • 35.
    THANK YOU FORYOUR ATTENTION! ANY QUESTIONS? :)

Editor's Notes

  • #2 What I’ll be talking about ISB Story
  • #7 Ok so we’ve seen what automated testing is, what are its advantages, so we got a pretty good introduction, now we move on to web automating. And for that I’m going to skip straight to the de-facto solution, Selenium
  • #8 It is only a framework! Try looking up some tools that use these API to make life even more easy. Fun fact: Selenium name was for against Mercury competitor – imagine calling your company, a competitor to Apple being Blender
  • #9 4 tools, one for different use and purpose
  • #13 At the end: But here’s the twist…
  • #14 Why mention them? Although not supported, you might still need to use them because, even though their own limitations, there are still some functionalities they do better than WebDriver. Also it gives a good knowledge of what WebDriver is, a merge of both. WebDriver and Selenium had a baby…
  • #24 WebElement object
  • #30 Log4J – Java Logging Framework
  • #31 Log4J – Java Logging Framework