Automation - web testing with selenium

  • View

  • Download

Embed Size (px)

Text of Automation - web testing with selenium

Automation & Selenium

Automation Tests with Selenium By Tzirla Rozental

Agenda:What is QA Automation?What and How to Automate?Create ProjectCode Planning & DesignSelenium selectorsRun testFailures

What is QA Automation Tests?Software executes and replaces tasks that done manuallyAutomates tasks that are impossible to do manually

What and How to Automate?

2. What is the interface that needs to be tested? (CLI, API, GUI ?)


How to pick the right tool?Ease of UseTool availabilitySupport all kinds of tests you needAble to create Automated Tests Without ProgrammingAutomated Test ScriptingMore: compare results, logging, exporting, support multi kinds of environments etc.

Features TestCompleteSeleniumUFTRecord and PlaybackYesLimitedYesScripting LanguagesPython, VBScript, JScript, C++, C#, and DelphiJava, C#, Ruby, Python, Perl, PHP , JavascriptVBScriptIDE IntegrationsVisualStudio and RADStudioIntellij, Eclipse, Visual StudioNoneUnit Testing SupportPyUnit, Ruby, PHPUnit, JUnit, NUnit, and TestNGJava, C#, Ruby, Python,Perl, PHP , JavascriptVBScriptBDD/TDD SupportYesManualNoneData-Driven TestingYesManualYesSource Control ManagementGit, Subversion, Visual SourceSafe, CVS, Team CoherenceManualGit and Subversion

Writing the web Automation tests with Selenium Web Driver

Install and Create the Project:Install javaInstall Eclipse and select WorkspaceInstall Selenium (last version) Maven (for Maven project) From eclipse MarketplaceCreate a Maven ProjectInstall TestNG and configure to right version From eclipse MarketplaceDownload jar for browser (for example: chromedriver.exe for running tests on Chrome)I


Select the Workspace:

Create maven projectFrom Top menu select File ->New -> Other

In the pop-up window select Maven and continue according the steps in above link:

See full scenario:

Install plugins from Eclipse MarketplaceIn top menu select Help -> Eclipse Marketplace

Search for plugin and install

Code Planning & Design

Before Starting:test package and src package

3 Layer model:


Common Package static classesGeneral static arguments that are sets one a runSeleniumActions include all selenium selectors functionsUtils manage the activation of the run

Inheritance in tests layer Actions in BaseTest set the logger and driver

@BeforeClass set logger and Driver@AfterClass stop the driver

Check actions that needed for test -> TODO

Page Layer

Inheritance in page

Inheritance in page child pages classes extends from the

Finding Elements:Using inspect in browserSelenium elements locatorsCss and xpath findElement() and findElements()

Can see more in:

Inspect in browser

Selenium element locators:Id > driver.findelement( -> driver.findelement( 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))

Css and XpathBy css for example:Id: #elementidClass: .elementclassOtherattribute: th[style=style]Otherattribute not specific tag:[style=style]Contains: [class*=cl]Absolute path: tbody>tr>tdNot absolute path: tbody tdBy xpath for example://table[@id=tableid]//table[@class=classname]//table[@disabled=false]//*[@style=style]


findElement() and findElements()findElement()findElements()0 matchesthrow exception (NoSuchElement exception)returns empty list1 matchreturn the found elementreturns list with one element2+ matchesreturns only the first one that foundreturns list with all found elements

Actions on ElementSelenium Element.Click()Element.Clear()Element.Sendkeys(text)Selenium execute script with java script query:jsClick()mouseover()

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);

Business Logic Layer

BusinessLogic layer Mediator between the Test and the pageProcessing 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 decisionsPerforming calculationsPage Object BL layer get and returns an object with data from page

Write the @TestUse method created before in page layer and BL layerWrite as the steps order in manual testAdd logs:Explain what each step is going to checkAssert apply the checkingLeave clean area at the end of the test

@AnnotationsTestNG annotations - @Test, @BeforeMethod, @AfterMethod etc.Java,lang annotations - @Override, @Deprecated etc.Org.openqa.selenium.supportannotations - @FindBy, @FindAll etc.

Run / Debug Test with TestNG

Run / Debug Configuration:Select Class and Method

Set system property (if needed)

OOPS FailuresCheck Test FailedtackeScreenshot() Method will keep the site appearance when test failedCheck ExceptionCheck in logFailures reasons: automation code issue/ dev changes / bug

Good Luck!