Selenium training

  • 4,465 views
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 comment
No Downloads

Views

Total Views
4,465
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
59
Comments
0
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • Browser support: Firefox 2, Firefox 3, IE 7, IE 8 , Safari 2, Safari 3, Opera 8, Opera 9 Programming language support: C#, Java, Perl, PHP, Python, Ruby Testing framework support: Bromine, JUnit, NUnit, RSpec (Ruby), Test::Unit (Ruby), TestNG (Java), unittest (Python), Robot Framework SeleniumLibrary From SeleniumHQ( December 2010) http://seleniumhq.org/
  • Features: Easy record and playback Intelligent field selection will use IDs, names, or XPath as needed Autocomplete for all common Selenium commands Walk through tests Debug and set breakpoints Save tests as HTML, Ruby scripts, or any other format Support for Selenium user-extensions.js file Option to automatically assert the title of every page Easy customization through plugins
  • Selenium-RC provides an API (Application Programming Interface) and library for each of its supported languages: HTML, Java, C#, Perl, PHP, Python, and Ruby. This ability to use Selenium-RC with a high-level programming language to develop test cases also allows the automated testing to be integrated with a project’s automated build environment.
  • Selenium IDE is an integrated development environment for Selenium tests. It is implemented as a Firefox extension, and allows you to record, edit, and debug tests. You can even use it generate code to run the tests with Selenium Remote Control. Limitations o Browser (Firefox Only) o Language Support (Selenese Only) Selenium RC : Selenium RC can be used for automating web applications for different web browsers on different platforms using your favorite language like JAVA, C#, Perl, Python, Ruby etc. To write your scripts, you can use Selenium RC with or without Selenium IDE because selenium IDE would help you writing scripts. Limitations o Slow o Limited number of concurrent tests Selenium-Grid Selenium-Grid allows the Selenium-RC solution to scale for large test suites or test suites that must be run in multiple environments. With Selenium-Grid, multiple instances of Selenium-RC are running on various operating system and browser configurations; Each of these when launching register with a hub. When tests are sent to the hub they are then redirected to an available Selenium-RC, which will launch the browser and run the test. This allows for running tests in parallel, with the entire test suite theoretically taking only as long to run as the longest individual test.
  • How to setup and install the Selenium IDE Explain – 3 Slides Show picture and explain how to install the IDE tool What is needed machine wise to setup the tool
  • For more information, please visit the below link http://seleniumhq.org/docs/04_selenese_commands.html
  • Explain – 7 – 10 slides This section should contain an example of a test case and how it’s written in Selenium IDE (both using the recorder and scripting)
  • Explain – 6 – 8 slides This section should contain slides that talk about how to run a test, review results and setup the test A simple exercise should also be included in this section so that the testers can try for themselves
  • Start from the Middle: This also is used for debugging. To set a start point, select a command, right-click, and from the context menu select Set/Clear Start Point. Run Any Single Command : It lets you immediately test a command you are constructing, when you are not sure if it is correct. You can double-click it to see if it runs correctly. This is also available from the context menu.
  • Show code in selenium for this Show the recorded steps in the record pane Show what the tester should see and this slide will help the instructor show the students what the answer is Explain what was done – 1 – 2 slides
  • 2 Example HTML code for locating element: Visit http://www.w3schools.com/htmldom/default.asp for more information about DOM Visit http://www.w3schools.com/css/default.asp for more information about CSS Visit http://www.w3schools.com/xpath/default.asp for more information about XPath
  • Explain – 3 Slides Just an overview of tools that are used with Selenium Explain that other programming languages are available for Selenium, but keep this section simple. Eclipse is a multi-language software development platform comprising an IDE and a plug-in system to extend it. It is written primarily in Java and is used to develop applications in this language and, by means of the various plug-ins, in other languages as well as C/C++, Cobol, Python, Perl, PHP and more. IntelliJ IDEA is a commercial Java IDE by the company JetBrains. Intellij provides a set of integrated refactoring tools that allow programmers to quickly redesign their code. IntelliJ IDEA provides close integration with popular open source development tools such as CVS, Subversion, Apache Ant and JUnit. * http://seleniumhq.org/docs/appendix_installing_java_driver_client.html#configuring-selenium-rc-intellij-reference . CubicTest is a graphical Eclipse plug-in for writing Selenium and Watir tests. It makes tests faster and easier to write, and provides abstractions to make tests more robust and reusable.
  • Explain – 3 Slides Just an overview of tools that are used with Selenium Explain that other programming languages are available for Selenium, but keep this section simple. Eclipse is a multi-language software development platform comprising an IDE and a plug-in system to extend it. It is written primarily in Java and is used to develop applications in this language and, by means of the various plug-ins, in other languages as well as C/C++, Cobol, Python, Perl, PHP and more. IntelliJ IDEA is a commercial Java IDE by the company JetBrains. Intellij provides a set of integrated refactoring tools that allow programmers to quickly redesign their code. IntelliJ IDEA provides close integration with popular open source development tools such as CVS, Subversion, Apache Ant and JUnit. * http://seleniumhq.org/docs/appendix_installing_java_driver_client.html#configuring-selenium-rc-intellij-reference . CubicTest is a graphical Eclipse plug-in for writing Selenium and Watir tests. It makes tests faster and easier to write, and provides abstractions to make tests more robust and reusable.
  • Purpose of this exercise: know how to use wait in selenium, using regular expression, locate element in different ways,…
  • In this section, review the OOP concept. Require learner must know Java and OOP.
  • TestNG using Selenium RC to automate test case on web. For more information about TestNG, please visit: http://testng.org/
  • For more information, please visit the below link http://seleniumhq.org/docs/04_selenese_commands.html

Transcript

  • 1. © 2010 LogiGear Corporation. All Rights ReservedSelenium OutlineFor LCTPIIHieu Pham – Dung Huynh – Tuan Tran
  • 2. © 2010 LogiGear Corporation. All Rights Reserved• Introduction to Selenium• Introduction to Selenium IDE• Introduction to Selenium RC• How Selenium works• How to install Selenium IDE• Using Selenium IDE• Create and Run a test in Selenium IDE• Useful Tools in Selenium IDE• Introduction to TestNG framework• Introduction to OOP in Java• How to setup TestNG in Eclipse IDE• Creating a simple test in TestNG• Running a test in TestNG• Data-driven test in TestNGOutline of Sections
  • 3. © 2010 LogiGear Corporation. All Rights ReservedSelenium OverviewSelenium is a suite of tools to automateweb-app testing across many platforms.• Selenium can work on any Javascriptsupported browsers.• Selenium can be controlled by manyprogramming languages and testingframeworks.• Selenium can simulate a user navigatingthrough pages and then assert for specificmarks on the pages
  • 4. © 2010 LogiGear Corporation. All Rights ReservedSelenium Features• Tests run directly in browser• Support multiple browsers• Intelligent field selection by using IDs, Names, XPath,Dom, CSS,…• Easy to convert to many formats (HTML, Java, C#,…)• Can be used for unit-testing, regression testing, smoke-testing, integration and acceptance testing.• Since Selenium is an Open Source tool, there are noLicensing costs and can be customized as per userrequest
  • 5. © 2010 LogiGear Corporation. All Rights ReservedIntroduction to Selenium IDEWhat is the Selenium IDE ?(Integrated Development Environment)• Selenium IDE is an integrated developmentenvironment for Selenium scripts.• It is implemented as a Firefox extension, andallows you to record, edit, and debug tests.• Selenium IDE includes the entire SeleniumCore, allowing you to easily and quickly recordand play back tests in the actual environment thatthey will run.
  • 6. © 2010 LogiGear Corporation. All Rights ReservedIntroduction to Selenium RCWhat is Selenium RemoteControl (RC)?• Selenium RC is a client/server systemthat allows you to control web browserslocally or on other computers, usingalmost any programming language andtesting framework.• A server which automatically launchesand kills browsers, and acts as a HTTPproxy for web requests from them.• Client libraries for your favoritecomputer language.• Selenium Core is the originalJavascript-based testing system.
  • 7. © 2010 LogiGear Corporation. All Rights ReservedHow Selenium Works• Using Selenium IDE to recordtest script, then export toappropriate programminglanguages• Edit test script on ProgrammingIDE (Ex: Eclipse)• Using Selenium RC to run testscript on Browsers (Firefox, IE,Chrome, Safari,…)• Selenium Grid extendsSelenium RC to distribute yourtests across multiple servers,saving you time by running testsin parallel
  • 8. © 2010 LogiGear Corporation. All Rights ReservedHow to install the Selenium IDE• Go to Selenium download page,find and install the latest seleniumIDE extension for Firefoxhttp://seleniumhq.org/download/• Select Install Now. The Firefox Add-ons window pops up, first showing aprogress bar, and when thedownload is complete, displays thefollowing windows.
  • 9. © 2010 LogiGear Corporation. All Rights ReservedHow to install the Selenium IDE• Restart Firefox. After Firefox reboots you will find the Selenium-IDElisted under the Firefox Tools menu
  • 10. © 2010 LogiGear Corporation. All Rights ReservedHow to install the Selenium IDE• Opening the IDETo run the Selenium-IDE, simplyselect it from the Firefox Toolsmenu. It opens as follows withan empty script-editing windowand a menu for loading, orcreating new test cases.• What is needed machine wise tosetup the tool ?– Firefox 2.0 +
  • 11. © 2010 LogiGear Corporation. All Rights ReservedUsing the Selenium IDE• Menu: The Options menuallows the changing ofsettings. The Help menu is thestandard Firefox Helpmenu; only one itemon this menu–UI-ElementDocumentation–pertains to Selenium-IDE.
  • 12. © 2010 LogiGear Corporation. All Rights ReservedUsing the Selenium IDE- Toolbar:The toolbar containsbuttons for controllingthe execution of yourtest cases, including astep feature fordebugging your testcases. The right-mostbutton, the one withthe red-dot, is therecord button.
  • 13. © 2010 LogiGear Corporation. All Rights ReservedUsing the Selenium IDE- Toolbar(cont.) : Apply Rollup Rules: This advanced feature allows repetitivesequences of Selenium commands to be grouped into a single action. Record: Records the user’s browser actions. Record: Records theuser’s browser actions. Step: Allows you to “step” through a test case by running it onecommand at a time. Use for debugging test cases.Record: Records the user’s browser actions.
  • 14. © 2010 LogiGear Corporation. All Rights ReservedUsing the Selenium IDE• Test case Pane:– Your script is displayed in the test case pane. It hastwo tabs, one for displaying the command and theirparameters in a readable “table” format.
  • 15. © 2010 LogiGear Corporation. All Rights ReservedUsing the Selenium IDE• The Command, Target, and Value entry fields display the currentlyselected command along with its parameters• If you start typing in the Command field, a drop-down list will bepopulated based on the first characters you type; you can thenselect your desired command from the drop-down.
  • 16. © 2010 LogiGear Corporation. All Rights ReservedUsing the Selenium IDE• Some popular Selenium commandsCommand Target DescriptionOpen URL (Ex: http://www.google.com ) Navigate to a pageClick Control id Click on a control base on idType Textbox id Type onto a textbox base on idverifyTextPresent String of text Check the existing of the text in the pageassertTitle String of text Check the title of the pageSelect Id of dropdown, select value Select an item in a drop down listCheck / Uncheck Check box id Check or Uncheck an check box base on idwaitForElementPresent Element id Test case will stop and only continue whenelement present in the pagechooseOkOnNextConfirmation/chooseCancelOnNextConfirmationChoose OK/ Cancel when a confirmationprompts appear
  • 17. © 2010 LogiGear Corporation. All Rights ReservedUsing the Selenium IDE• Log/Reference/UI-Element/Rollup Pane Log: When you run your test case, error messages andinformation messages showing the progress are displayed inthis pane automatically, even if you do not first select the Logtab.
  • 18. © 2010 LogiGear Corporation. All Rights ReservedUsing the Selenium IDE• Log/Reference/UI-Element/Rollup Pane Reference: is the default selection whenever you are enteringor modifying Selenese commands and parameters in Tablemode. In Table mode, the Reference pane will displaydocumentation on the current command.
  • 19. © 2010 LogiGear Corporation. All Rights ReservedCreating a Test in Selenium IDE• How to write test in Selenium IDE– With using recorder: Open Selenium IDE in FireFox
  • 20. © 2010 LogiGear Corporation. All Rights ReservedCreating a Test in Selenium IDE• How to write test in Selenium IDE– With using recorder(cont.) Choose HTML formatNotes: Notice that the red button is pressed mean it’s ready to record test case
  • 21. © 2010 LogiGear Corporation. All Rights ReservedCreating a Test in Selenium IDE• How to write test in SeleniumIDE– With using recorder(cont.)Here is an example test:TC name: Verify the user can login toyahoo mail successfully.Steps:1. Open new tab in FireFox andnavigate to Yahoo Mailpage(http://mail.yahoo.com )2. Enter username andpassword(example Username:kimlgr1@yahoo.com , Password: logigear)3. Click Sign InScripts will be generated in Selenium IDEVP: Verify the main page is loadedsuccessfully.
  • 22. © 2010 LogiGear Corporation. All Rights ReservedCreating a Test in Selenium IDE• How to write test inSelenium IDE (cont.)Guideline for verification: To verify that main page isloaded successfully, we couldcheck for existing of Sign outlink. Right click Sign out link Choose Show all availablecommands Choose verifyElementPresentlink = Sign Out
  • 23. © 2010 LogiGear Corporation. All Rights ReservedRunning a Test in Selenium• How to run a test?• How to debug a test?• Review results• Exercise for Selenium
  • 24. © 2010 LogiGear Corporation. All Rights ReservedRunning a Test in Selenium• How to run a test?The IDE allows many options for running your testcase. Run a Test: Click the Run button to run the currently displayed testcase. Run a Test Suite: Click the Run All button to run all the test cases inthe currently loaded test suite. Stop and Start: The Pause button can be used to stop the test casewhile it is running. The icon of this button then changes to indicate theResume button. To continue click Resume. Stop in the Middle: You can set a breakpoint in the test case to cause itto stop on a particular command. This is useful for debugging your testcase. To set a breakpoint, select a command, right-click, and from thecontext menu select Toggle Breakpoint.
  • 25. © 2010 LogiGear Corporation. All Rights ReservedRunning a Test in Selenium• How to run a test? (cont.)Start from the Middle: You can tell the IDE to beginrunning from a specific command in the middle of the testcase. This also is used for debugging.Run Any Single Command: Double-click any singlecommand to run it by itself. This is useful when writing asingle command.
  • 26. © 2010 LogiGear Corporation. All Rights ReservedRunning a Test in Selenium• How to debug a test?Debugging means finding and fixing errors in your test case.This is a normal part of test case development.o Breakpoints and Startpoints:o To set a breakpoint, select a command, right-click, and from the contextmenu select Toggle Breakpoint. Then click the Run button to run your testcase from the beginning up to the breakpointo To set a startpoint, select a command, right-click, and from the contextmenu select Set/Clear Start Point. Then click the Run button to execute thetest case beginning at that startpoint.
  • 27. © 2010 LogiGear Corporation. All Rights ReservedRunning a Test in Selenium• How to debug a test?o Stepping Through a Testcase:To execute a test case one command at a time(“step through” it), follow these steps:Start the test case running with the Run buttonfrom the toolbar.Immediately pause the executing test case withthe Pause button.Repeatedly select the Step button.
  • 28. © 2010 LogiGear Corporation. All Rights ReservedRunning a Test in Selenium• Review Results:– After test runsuccessfully, wecan view reportresult in Log panellike as picture
  • 29. © 2010 LogiGear Corporation. All Rights ReservedRunning a Test in Selenium• Exercises for Selenium:A simple exercise:– Open http://www.google.com in Firefox– Open Selenium IDE, Tools > Selenium IDE– Make sure that Selenium is in recording mode– Type in “LogiGear”– On the search results verify that “LogiGear” is one of the search results on thefirst page– Save the test case as “Google_ide”– Run the saved test case back again using the IDE– View the results in the IDE
  • 30. © 2010 LogiGear Corporation. All Rights ReservedExercise oneSearch with Google: The recordedsteps in the pane. The result is in theIDE
  • 31. © 2010 LogiGear Corporation. All Rights ReservedLocate by IDLocate by NameLocate by XPathLocate by CSSLocate by link TextLocate by DOMLocate Element in Selenium IDE
  • 32. © 2010 LogiGear Corporation. All Rights Reserved• Pattern table• How to Use in Selenium IDERegular Expression in SeleniumCommand Target Valueclick link=regexp:Film.*Television DepartmentverifyTitle regexp:.*Film.*Television.*PATTERN MATCH. any single character[ ] character class: any single character that appears inside the brackets* quantifier: 0 or more of the preceding character (or group)+ quantifier: 1 or more of the preceding character (or group)? quantifier: 0 or 1 of the preceding character (or group){1,5} quantifier: 1 through 5 of the preceding character (or group)| alternation: the character/group on the left or the character/group on the right( ) grouping: often used with alternation and/or quantifier
  • 33. © 2010 LogiGear Corporation. All Rights ReservedUseful Tools for Selenium• Useful tools for locating elements in Firefox– Firebug (for locating element id, name)– FirePath (for locating Xpath, CSS of an element)
  • 34. © 2010 LogiGear Corporation. All Rights ReservedUseful Tools for Selenium• Tools are used with Selenium:–Eclipse–Cubic Test–IntelliJ IDEA–Python–.Net…
  • 35. © 2010 LogiGear Corporation. All Rights ReservedUseful Tools for Selenium• Other programming languages areavailable for Selenium:Java: use either JUnit or TestNG as the test engine.Some development environments like Eclipse havedirect support for these via plug-insC# : The .NET Client Driver works withMicrosoft.NET. It can be used with any .NET testingframework like NUnit or the Visual Studio 2005 TeamSystem.
  • 36. © 2010 LogiGear Corporation. All Rights ReservedUseful Tools for Selenium• Other programming languages areavailable for Selenium:Python: Py-unit is the test framework to use forPythonRuby: Selenium-IDE generates reasonableRuby, but requires the old Selenium gem.
  • 37. © 2010 LogiGear Corporation. All Rights ReservedExercise two• Using IDE and necessary tools to record and locate element usingXpath, DOM, CSS• Login Yahoo Mail using this account logigearmail@yahoo.com / logigear1• Verify user is login success• Logout of Yahoo Mail• Verify user is logout success
  • 38. © 2010 LogiGear Corporation. All Rights ReservedIntroduction to OOP(*)(*)in JavaWhat is an Object?• An object is a software bundle of related state and behavior. Softwareobjects are often used to model the real-world objects that you find ineveryday life(*) :Object Oriented Programming• Consider a bicycle, for example:•Notes: For more information relate to Java statements, variables…please refer tohttp://download.oracle.com/javase/tutorial/java/index.htmlMethod(behavior)Field(state, property)
  • 39. © 2010 LogiGear Corporation. All Rights ReservedIntroduction to OOP in JavaWhat is a Class ?• A class is a blueprint or prototypefrom which objects are created• In object-oriented terms, we saythat your bicycle is an instance ofthe class of objects known asbicycles
  • 40. © 2010 LogiGear Corporation. All Rights ReservedIntroduction to OOP in JavaWhat is Inheritance?• Inheritance provides a powerful and natural mechanism for organizingand structuring your software• Object-oriented programming allows classes to inherit commonly usedstate and behavior from other classes
  • 41. © 2010 LogiGear Corporation. All Rights ReservedIntroduction to OOP in JavaWhat is Interface?• An interface is a contract between a class and the outside world. Whena class implements an interface, it promises to provide the behaviorpublished by that interface
  • 42. © 2010 LogiGear Corporation. All Rights ReservedIntroduction to OOP in JavaWhat is Package?• A package is a namespace for organizing classes and interfaces in alogical manner. Placing your code into packages makes large softwareprojects easier to manageUse Import to use package
  • 43. © 2010 LogiGear Corporation. All Rights ReservedIntroduction to TestNG• TestNG is a testing framework inspired from JUnit and NUnit but introducingsome new functionalities that make it more powerful and easier to use• TestNG is designed to cover all categories of tests: unit, functional, end-to-end, integration, etc...• TestNG features:– Annotations.–Run your tests in arbitrarily big thread pools with various policies available (all methods intheir own thread, one thread per test class, etc...).–Test that your code is multithread safe.–Flexible test configuration.–Support for data-driven testing (with @DataProvider).– Support for parameters.– Powerful execution model (no more TestSuite).– Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc...).– Embeds BeanShell for further flexibility.–Default JDK functions for runtime and logging (no dependencies).–Dependent methods for application server testing.
  • 44. © 2010 LogiGear Corporation. All Rights ReservedSetup TestNG in Selenium• Download and install eclipseIDE fromhttp://www.eclipse.org/downloads/• Run eclipse, Go to Help/ InstallNew Software…• Install TestNG by copy this urlinto Work with textboxhttp://beust.com/eclipse• Check TestNG• Click Next and do as theinstructions
  • 45. © 2010 LogiGear Corporation. All Rights ReservedSetup TestNG in Selenium• Go to http://seleniumhq.org/download/ and download Selenium RC• Extract the downloaded file.
  • 46. © 2010 LogiGear Corporation. All Rights ReservedCreate Project• Open Eclipse, Go toFile/New/Project to create newproject• In New Project windows, chooseJava/ Java Project and click Next
  • 47. © 2010 LogiGear Corporation. All Rights ReservedCreate Project• Enter project name• Choose Java Runtime Environment and click Next
  • 48. © 2010 LogiGear Corporation. All Rights ReservedCreate Project• In the New Java Project, click Add ExternalJARs…• Choose path to Selenium RC folder and addselenium-java-client-driver.jar and selenium-server.jar
  • 49. © 2010 LogiGear Corporation. All Rights ReservedAdd TestNG Library• To add TestNG Library, navigate to eclipse /plugins /org.testng.eclipse_5.14.3.20101203_1327/ and chooseeclipse-testng.jar
  • 50. © 2010 LogiGear Corporation. All Rights ReservedConfiguration Report output folder• Go to Window/ Preferences• Change Output directory :/Reports• Apply and click OK
  • 51. © 2010 LogiGear Corporation. All Rights ReservedCreate Package• Right click “src” folder• choose New/ Package• Type name of the package
  • 52. © 2010 LogiGear Corporation. All Rights ReservedProject structure• Create all package as the followingtemplate• BatchFiles: contain test suite filetestng.xml• Database: contain data file in excelformat• Functions: Contain java class of somecommon functions• Interfaces:• TestCases: Contain the test case• TestCases.[name]: the sub folder of thepackage, contain the test cases relatingto a module.
  • 53. © 2010 LogiGear Corporation. All Rights ReservedRun Configuration• Go to Run/ Run Configuration…
  • 54. © 2010 LogiGear Corporation. All Rights ReservedRun Configuration• Browse for file and runwith below choices:• Class: Run a Java Classthat contain one or moremethods• Method: Run a single testmethod• Groups: Run a group oftest method• Package: Run a Packageof Class• Suite: Run testng.xmlfile(Test Suite)
  • 55. © 2010 LogiGear Corporation. All Rights ReservedExercise 1• Setup Eclipse and install TestNG• Open Selenium IDE and record a simple google search test• Convert code into TestNG• Create a TestNG Project in Eclipse follow the framework• Copy created code in Selenium IDE into TestNG File• Edit and Run the test
  • 56. © 2010 LogiGear Corporation. All Rights ReservedExercise 2• Login Gmail using logigearmail@gmail.com / logigear1• Check for text present• Logout Gmail• Login Yahoo Mail using logigearmail@yahoo.com / logigear1• Check for text present• Logout Yahoo Mail
  • 57. © 2010 LogiGear Corporation. All Rights ReservedData-driven testing withSelenium and TestNG• Download java excel Api from the following linkhttp://sourceforge.net/projects/jexcelapi/files/jexcelapi/• Extract and add file jxl.jar into TestNG Project Library
  • 58. © 2010 LogiGear Corporation. All Rights ReservedData-driven testing withSelenium and TestNG• Create a TestNG project in Eclipse follow the framework.• We will start with a simple Login Yahoo using data provider
  • 59. © 2010 LogiGear Corporation. All Rights ReservedData-driven testing withSelenium and TestNG• Create a excel file for example data.xls using this format and name of the sheet isdatapooltestdata username passwordkimlgr1@yahoo.com logigearlogigearmail@yahoo.com logigear1testdata
  • 60. © 2010 LogiGear Corporation. All Rights ReservedData-driven testing withSelenium and TestNG• Use this code to read filefrom excel file.• Parameters• xlFilePath: path to theexcel file, in the exampleis “data.xls”• sheetName: name of thesheet, in the aboveexample is “datapool”• tableName: name of thedata table, in the aboveexample is “testdata”
  • 61. © 2010 LogiGear Corporation. All Rights ReservedData-driven testing withSelenium and TestNG• Write a DataProvider name DP1 and call the getTableArray function,pass the parameter• Edit the LoginYahoo method to receive the table dataName of the data providerTable column namePass parameters
  • 62. © 2010 LogiGear Corporation. All Rights ReservedExercise 3 – Data Driven Test• Let’s take our simple first example, but this time, instead ofhaving a static search string, we are going to go to multiplesites and verify that the site is what comes up• So, in this example, we need to create a spreadsheet or datafor the IDE• In the spreadsheet, we will create four sites, yahoo, google,msn, and ask• The test will go to each site and verify an attribute on thepage that identifies it as the site – for example, we might usethe window tag as verification that we have gone to Yahoo,or we can use different verification methods to insure that weare at the right site• The test will then loop through each of the data elements, goto the site and then verify through verification the site
  • 63. © 2010 LogiGear Corporation. All Rights ReservedExercise 4• In this exercise we are going to do a couple of things• The exercise should be a simple test, another google search forexample, but this time we are going to add active timing and lookat javascript• The active timing should have two examples, one sleep and onedynamic wait• We want to record the script and then go inside the code to addthe timing, in the first example, we use a static sleep and in thesecond exercise, we add a dynamic sleep.• I believe the method is called either click or clickAndwait method,one waits, while the other goes on• The select command and click commands are some of the basicbuilding blocks for IDE, and we need to show in this exercise howto use these but more importantly, we want to give the tester aview into the code that is being generated by the recorder• http://seleniumhq.org/docs/03_selenium_ide.html#building-test-cases
  • 64. © 2010 LogiGear Corporation. All Rights ReservedThe EndThank you for your attention!If you have any question/concern/unclear/suggest, pleasecontact to us:o Hieu Pham : hieu.pham@logigear.como Dung Huynh : dung.huynh@yahoo.como Tuan Tran : tuan.quoc.tran@logigear.com