Selenium tips and tricks- Selenium Israel Meetup #5

8
Bvupnbujpo!! ’! Tfmfojvn Yanir Taflev [email protected] Best practices Java

description

Tips and Tricks when working with selenium. #1 - Working with frames #2 - Working with windows #3 - Taking screenshot on failures #4 - Dealing with waits (Synchronization)

Transcript of Selenium tips and tricks- Selenium Israel Meetup #5

Page 1: Selenium tips and tricks- Selenium Israel Meetup #5

Yanir Taflev [email protected]

Best practices

Java

Page 2: Selenium tips and tricks- Selenium Israel Meetup #5

Yanir Taflev Customer success engineer

BSc - Computers Science Previous Titles: Automation engineer, SW Architect, Lead developer, R&D Startups: Loca-To, somon.me

Technologies: Selenium, Appium, UFT/QTP, CodedUI, Java, C#, RoR, ASP.NET, OOD/OOSE, Web, Android, Client-Server, Python and more…

il.linkedin.com/in/yanirta/

Page 3: Selenium tips and tricks- Selenium Israel Meetup #5

#1 - Working with frames.#2 - Working with tabs/windows.#3 - Taking screenshots on failures.#4 - Waits.

Page 4: Selenium tips and tricks- Selenium Israel Meetup #5

“Automation with frames is not trivial, In order to access the elements within a frame we need to tell Selenium to switch to it”

driver.switchTo().frame(“iframe”);

• Nested frames requires harder work: ie. accessing /Level1/Level2/…/LevelN driver.switchTo().frame(“Level1”); driver.switchTo().frame(“Level2”); etc… driver.switchTo().frame(“LevelN”);

• Switching back if accessing outside the frame: driver_.switchTo().defaultContent();

Page 5: Selenium tips and tricks- Selenium Israel Meetup #5

“The same as with frames, when new window/tab created in browser we need to tell Selenium to switch to it”

driver.switchTo().window(newWindowHandle);

• To identify new window we take list of windows handles and subtract it from the old list before new window was inserted.

Set<String> newHandles = driver_.getWindowHandles();

Page 6: Selenium tips and tricks- Selenium Israel Meetup #5

“Taking screenshots is one of the basics in automation to understand whats’ failed”• Prefer to set screenshot taking in base class.• Take screenshots only on failures.

(Unless there is real need i.e. UI Automated Testing)• Preserve order in naming so it will easy to find the images.

((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

Page 7: Selenium tips and tricks- Selenium Israel Meetup #5

“Wait are usually required for synchronization with the Application under test (AUT)”

• Implicit wait - The amount of time given to findElement method before it fails (Raise an Exception)Note: There default implicit wait in Selenium is 0 driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS)

• Explicit wait - Polling mechanism to fulfil a condition within a given timeout. (new WebDriverWait(driver, 10)).until(<Condition>);*Condition can be either one of builtin ExpectedConditions or Custom predicate.