Integrating Selenium testing infrastructure into Scala Project

Uploaded on


More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to like this
No Downloads


Total Views
On Slideshare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. Test Automation Using Selenium Swati Email-
  • 2. History of The Selenium ● ● Selenium is invent by Jason Huggins He developed a Javascript library that could drive interactions with the page, allowing him to automatically rerun tests against multiple browsers.
  • 3. Test Automation ● Test automation is the use of software To set test preconditions. To control the execution of tests. To compare the actual outcomes to predicted outcomes. To report the Execution Status. ● Commonly, test automation involves automating a manual process already in place that uses a formalized testing process.
  • 4. Why and When To Automate? Frequent regression testing ● Repeated test case Execution is required ● User Acceptance Tests ● Faster Feedback to the developers ● Reduce the Human Effort ● Test same application on multiple environments ●
  • 5. Selenium ● ● ● Selenium is a robust set of tools that supports rapid development of test automation for web-based applications. Selenium provides a rich set of testing functions specifically geared to the needs of testing of a web application. Selenium operations are highly flexible, allowing many options for locating UI elements and comparing expected test results against actual application behavior.
  • 6. Selenium Features ● ● ● ● ● ● Supports Cross Browser Testing. The Selenium tests can be run on multiple browsers. Allows scripting in several languages like Java, C#, PHP and Python. Ajax/CSS support. Assertion statements provide an efficient way of comparing expected and actual results. Inbuilt reporting mechanism. Selenium is an open source tool
  • 7. Selenium Components ● Selenium IDE ● Selenium Remote Control ● Selenium Grid
  • 8. Selenium IDE ● ● ● ● ● ● Previously known as Selenium Recorder Selenium IDE is an integrated development environment for Selenium tests. It is implemented as a Firefox extension, and allows you to record, edit, and replay the test in firefox Selenium IDE allows you to save tests as HTML, Java, Ruby scripts, or any other format It allows you to automatically add assertions to all the pages. Allows you to add selenese commands as and when required
  • 9. Selence ● ● Selence special test scripting language for Selenium. Selenese provides commands for performing actions in a browser (click a link, select an option), and for retrieving data from the resulting pages.
  • 10. Selenium IDE Installation ● First download Mozilla Firefox browser. ● Click on the Firefox tab present at the top the browser window. ● In drop down menu click on Add-on. ● Go to add on page of Mozilla Firefox browser ● In the search box of Add on page search the term "Selenium IDE" and press enter ● Click on more link to the Selenium IDE add-on ● Go to ● Once installation is done the Mozilla Firefox browser will ask you to restart the browser.Just Restart it.
  • 11. Selenium IDE - UI Start and Stop Recording Replay Toolbar Editor Accessor Area Selenese Script Editor Selenium Log
  • 12. Recoding a Selenium Test Case ● ● ● ● ● ● Open Firefox that has the IDE installed Open the base URL of the application to record. Keep the application in a common base state. Go To Tools  Selenium IDE and the IDE will be opened Now perform the operations on the application as you are testing the application. Once you are done with the recording click on the stop recording button and save the test case through the file menu. By default it will be saved as a selenese script (HTML format)
  • 13. Creating a Test Suite ● ● In the Selenium IDE you can create any number of test cases and save them as test suite. To Run the test Suite click on the “Play entire test suite” button as shown below. Test Suite with Test1 & test2
  • 14. Running Options Run a Test Case Click the Run button to run the currently displayed test case. Run a Test Suite Click the Run All button to run all the test cases in the currently loaded test suite. Stop and Start The Pause button can be used to stop the test case while it is running. The icon of this button then changes to indicate the Resume button. To continue click Resume.
  • 15. Adding Assertions to the Script ● Selenese allows multiple ways of checking for UI elements. ● Verifications and assertions are used to check if ● an element is present somewhere on the page? ● specific text is somewhere on the page? ● specific text is at a specific location on the page? ● Verifications and assertions are not one and the same. ● If an assertion fails, the script will be aborted but if a verification fails the script will continue.
  • 16. Assertion Statements ● ● ● ● ● assertTextPresent This will assert if the text is present in the page. assertText This will assert if a particular element is having the particular text. assertTitle This will assert if the page is having a proper title. assertValue This will assert if a Text box or check box has a particular value assertElementPresent This will assert if a particular UI Element is present in the page.
  • 17. User Acceptance Testing (UAT) ● ● ● User Acceptance Testing (UAT) is the last phase of the software testing process. During UAT, actual software users test the software to make sure it can handle required tasks in real world scenarios, according to specifications. UAT is one of the final and critical software project procedures that must occur before newly developed software is rolled out to the market. UAT is also known as beta testing, application testing or end user testing.
  • 18. Steps Involved in In-House UAT ● ● ● ● ● Planning: The UAT strategy is outlined during the planning step. Designing test cases: Test cases are designed to cover all the functional scenarios of the software in real-world usage. Executing test cases and documenting: The testing team executes the designed test cases. All bugs are logged in a testing document with relevant comments. Bug fixing: Responding to the bugs found by the testing team, the software development team makes final adjustments to the code to make the software bug-free. Sign-off: When all bugs have been fixed, the testing team indicates acceptance of the software application. This shows that the application meets user requirements and is ready to be rolled out in the market.
  • 19. Importance of UAT ● ● UAT is important because it helps demonstrate that required business functions are operating in a manner suited to realworld circumstances and usage. UAT is an effective process with a high rate of return for those who take the time to implement and follow its discipline.
  • 20. How Selenium Work
  • 21. Common Problem in Web Testing ● Record/replay is not reusable, is fragile. ● Managing test cases. ● UI changesmake tests brittle.
  • 22. ScalaTest Using Selenium ● ● ScalaTest 2.0 includes a domain specific language (DSL) for writing browser-based tests using Selenium. To use ScalaTest's Selenium DSL, you'll first need to add Selenium to your project dependencies. For example, in your sbt build you might add: libraryDependencies += "org.seleniumhq.selenium" % "seleniumjava" % "2.23.1" % "test->default" ● Mix trait WebBrowser into your test class.This trait provides the DSL in its entirety except for one missing piece : an implicit org.openqa.selenium.WebDriver
  • 23. Element Locator ● ID: id=foo ● Name: name=foo ● First ID, then name: identifier=foo ● DOM: document.forms[‘myform’].myDropdown ● XPath: xpath=//table[@id='table1']//tr[4]/td[2] ● Link Text: link=sometext ● CSS Selector: css=a[href=“#id3”] ● Sensible defaults, e.g. xpath if starts with //
  • 24. Example of UAT class BlogSpec extends FlatSpec with ShouldMatchers with WebBrowser { implicit val webDriver: WebDriver = new HtmlUnitDriver val host = "http://localhost:9000/" "The blog app home page" should "have the correct title" in { go to (host + "index.html") pageTitle should be ("Awesome Blog") } }
  • 25. Terms of Test Cases ● Navigation: You can ask the browser to retrieve a page (go to a URL) like this: go to "" ● Checking input element values: textField("q").value should be ("Cheese!") textArea("body").value should be ("I saw something cool today!") ● Implicit wait : implicitlyWait(Span(10, Seconds)) ● Cleaning up: To close all windows, and exit the driver, use quit: quit()
  • 26. Test Code of Autocomplete Functionality ● Define the autocomplete test code in a trait so that it will be use by all the test class which extends this trait : trait Reattempt { def attemptOrReattempAutoComplete(func: By => WebElement, selector: String, searchText: String,Text: String, startWithCount: Int, maxNumberOfRetries: Int = 5): Unit = { if (startWithCount <= maxNumberOfRetries && searchText.length > 0) { func(By.cssSelector(selector)).clear func(By.cssSelector(selector)).sendKeys(searchText) try { if(searchText == Text) { func(By.cssSelector(“refrence of div where this search text element present")).click } else { func(By.cssSelector("refrence of div where this search text element presen")).sendKeys(Keys.ARROW_UP) } } catch { case e: TimeoutException => attemptOrReattempAutoComplete(func, selector, searchText.substring(0, searchText.length 1),Text: String, startWithCount + 1, maxNumberOfRetries) case e: ElementNotVisibleException => attemptOrReattempAutoComplete(func, selector, searchText.substring(0, searchText.length - 1), Text: String, startWithCount + 1, maxNumberOfRetries) } } } }
  • 27. Sequentially Running Test To run the whole test cases sequentially we have to put this line in build.sbt “parallelExecution in Test := false concurrentRestrictions in Global += Tags.limit(Tags.Test, 1) parallelExecution in ScctPlugin.ScctTest := false”
  • 28. Command For Run Acceptace Test ● To run single test sbt “test-only packageName.className” ● To run whole test sbt test ● To check the coverage report sbt scct:test
  • 29. Selenium Test in Headless Mode with Xvfb ● ➢ Follow the following steps to configure Xvfb (Virtual Framebuffer) to run test cases: install Xvfb on ubuntu using following command : sudo apt-get install xvfb ➢ Create .sh file in root /etc/init.d/ folder and paste the following script code in the script (.sh) file:
  • 30. XVFB=/usr/bin/Xvfb XVFBARGS=":1 -screen 0 1024x768x24 +extension GLX +render -noreset -nolisten tcp" PIDFILE=/var/run/ case "$1" in start) echo -n "Starting virtual X frame buffer: Xvfb" start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS echo "." ;; stop) echo -n "Stopping virtual X frame buffer: Xvfb" start-stop-daemon --stop --quiet --pidfile $PIDFILE echo "." ;; restart) $0 stop $0 start ;; *) echo "Usage: /etc/init.d/xvfb {start|stop|restart}" exit 1 esac exit 0
  • 31. Selenium Test in Headless Mode with Xvfb ● Now,open the terminal and go to your project and run : Xvfb :1 -screen 0 1920x1080x24 +extension GLX +render -noreset -nolisten tcp ● and open another tab of terminal and go to your project and run : export DISPLAY=:1 sbt test
  • 32. Thank You