Automation - web testing with selenium
-
Upload
tzirla-rozental -
Category
Presentations & Public Speaking
-
view
110 -
download
4
Transcript of Automation - web testing with selenium
![Page 1: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/1.jpg)
Automation Tests with Selenium
© By Tzirla Rozental
![Page 2: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/2.jpg)
Agenda:What is QA Automation?What and How to Automate?Create ProjectCode Planning & DesignSelenium selectorsRun testFailures
![Page 3: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/3.jpg)
What is QA Automation Tests?Software executes and replaces
tasks that done manually Automates tasks that are
impossible to do manually
![Page 4: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/4.jpg)
What and How to Automate?
![Page 5: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/5.jpg)
![Page 6: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/6.jpg)
![Page 7: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/7.jpg)
![Page 8: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/8.jpg)
![Page 9: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/9.jpg)
![Page 10: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/10.jpg)
![Page 11: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/11.jpg)
2. What is the interface that needs to be tested? (CLI, API, GUI ?)
? ?
![Page 12: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/12.jpg)
![Page 13: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/13.jpg)
![Page 14: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/14.jpg)
How to pick the right tool?
Ease of Use Tool availability Support all kinds of tests you need Able to create Automated Tests Without
Programming Automated Test Scripting More: compare results, logging, exporting,
support multi kinds of environments etc.
![Page 15: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/15.jpg)
Features TestComplete Selenium UFTRecord and Playback Yes Limited Yes
Scripting Languages
Python, VBScript, JScript, C++, C#,
and Delphi
Java, C#, Ruby, Python, Perl, PHP ,
JavascriptVBScript
IDE Integrations VisualStudio and RADStudio
Intellij, Eclipse, Visual Studio None
Unit Testing Support
PyUnit, Ruby, PHPUnit, JUnit, NUnit,
and TestNG
Java, C#, Ruby, Python,Perl, PHP ,
JavascriptVBScript
BDD/TDD Support Yes Manual None
Data-Driven Testing Yes Manual Yes
Source Control Management
Git, Subversion, Visual SourceSafe,
CVS, Team Coherence
Manual Git and Subversion
![Page 16: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/16.jpg)
Writing the web Automation tests
with Selenium Web
Driver
![Page 17: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/17.jpg)
Install and Create the Project:
1. Install java2. Install Eclipse and select Workspace3. Install Selenium (last version)
http://www.softwaretestinghelp.com/webdriver-eclipse-installation-selenium-tutorial-9/4. Install Maven (for Maven project) – From eclipse Marketplace5. Create a Maven Project6. Install TestNG and configure to right version – From eclipse Marketplace7. Download jar for browser (for example: ‘chromedriver.exe’ for running tests
on Chrome)I
![Page 18: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/18.jpg)
Select the Workspace:
![Page 19: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/19.jpg)
Create maven project
From Top menu select File ->New -> Other
In the pop-up window select Maven and continue according the steps in above link:
See full scenario:http://toolsqa.com/java/maven/create-new-maven-project-eclipse/
![Page 20: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/20.jpg)
Install plugins from Eclipse MarketplaceIn top menu select Help -> Eclipse Marketplace
Search for plugin and install
![Page 21: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/21.jpg)
Code Planning & Design
![Page 22: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/22.jpg)
Before Starting:‘test’ package and ‘src’ package
![Page 23: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/23.jpg)
3 Layer model:
Test
BusinessLogic
Page
![Page 24: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/24.jpg)
Common Package – static classes
General – static arguments that are sets one a run
SeleniumActions – include all selenium selectors functions
Utils – manage the activation of the run
![Page 25: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/25.jpg)
Inheritance in ‘tests’ layer – Actions in BaseTest – set the logger and driver
@BeforeClass – set logger and Driver
@AfterClass – stop the driver
![Page 26: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/26.jpg)
Check actions that needed for test -> TODO
![Page 27: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/27.jpg)
Page Layer
![Page 28: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/28.jpg)
Inheritance in page – BasePage.java
![Page 29: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/29.jpg)
Inheritance in page – child pages classes extends from the BasePage.java
HomePage.java RegistrationPage.java
![Page 30: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/30.jpg)
Finding Elements:• Using inspect in browser• Selenium elements locators• Css and xpath • findElement() and findElements()
Can see more in:http://www.slideshare.net/LivePersonDev/selenium-webdriver-element-locators
![Page 31: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/31.jpg)
Inspect in browser
![Page 32: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/32.jpg)
Selenium element locators:
Id –> driver.findelement(By.id(“id”)) Name -> driver.findelement(By.name(“name
attribute”)) Tag name -> driver.findelement(By.tagname(“a”)) LinkText->
driver.findelement(By.linktext(“text_on_link”)) Css -> driver.findelement(By.cssselector(“#id”)) xpath -> driver.findelement(By.xpath(“//*[@id=‘id’]”)) Text -> driver.findelement(By.text(“visible text”))
![Page 33: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/33.jpg)
Css and Xpath
By css – for example: Id: “#elementid” Class: “.elementclass” Otherattribute:
“th[style=‘style’]” Otherattribute – not specific
tag:“[style=‘style’]”
Contains: “[class*=‘cl’]” Absolute path: “tbody>tr>td” Not absolute path: “tbody td”
By xpath – for example: “//table[@id=‘tableid’]” “//table[@class=‘classname’]” “//table[@disabled=‘false’]” “//*[@style=‘style’]”
“//table[contains(@style,’top’)]”
“//table/tbody/tr/td” “tbody//td”
![Page 34: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/34.jpg)
findElement() and findElements()
findElement() findElements()
0 matches
throw exception (NoSuchElement
exception) returns empty list
1 match return the found elementreturns list with one
element2+
matchesreturns only the first one
that foundreturns list with all found
elements
![Page 35: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/35.jpg)
Actions on Element
Selenium Element.Click() Element.Clear() Element.Sendkeys(text) Selenium execute script with java script
query: jsClick() mouseover()
![Page 36: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/36.jpg)
Init page – PageFactory @FindBy
(how = How.ID, using = “elementId")WebElement element
@FindAll({@FindBy(how = How.ID, using = “elementId1"),@FindBy(how = How.ID, using = “elementId2") })WebElement someElement
Init page syntacs :Wrong: Page page1 = new Page();Correct: Page page1 = PageFactory.initElement(WebDriver driver, Page.class);
![Page 37: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/37.jpg)
Business Logic Layer
![Page 38: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/38.jpg)
BusinessLogic layer – Mediator between the Test and the page Processing commands (send to click on element) Coordinating workflow (test sent to got message after click on
element) Maintaining application state (current data in page) Accessing data(from page or other, get data from displayed
message) Making logical decisions Performing calculations Page Object – BL layer get and returns an object with data from
page
![Page 39: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/39.jpg)
Write the @Test
Use method created before in page layer and BL layer
Write as the steps order in manual test Add logs:
Explain what each step is going to check Assert – apply the checking Leave clean area at the end of the test
![Page 40: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/40.jpg)
@Annotations
TestNG annotations - @Test, @BeforeMethod, @AfterMethod etc.
Java,lang annotations - @Override, @Deprecated etc.
Org.openqa.selenium.supportannotations - @FindBy, @FindAll etc.
![Page 41: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/41.jpg)
Run / Debug Test with TestNG
![Page 42: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/42.jpg)
Run / Debug Configuration:
Select Class and MethodSet system property (if needed)
![Page 43: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/43.jpg)
OOPS… FailuresCheck Test FailedtackeScreenshot() Method will keep the
site appearance when test failedCheck ExceptionCheck in logFailures reasons: automation code issue/
dev changes / bug
![Page 44: Automation - web testing with selenium](https://reader036.fdocuments.us/reader036/viewer/2022081505/588556491a28ab47268b53ff/html5/thumbnails/44.jpg)
Good Luck!