Date post: | 16-Jan-2017 |
Category: |
Engineering |
Upload: | lucas-pang |
View: | 239 times |
Download: | 0 times |
Test Automation
• UI Automation Quirks
• Break
• Scalable Test Automation
Agenda
UI Automation Quirks
• http://www.linkedin.com/in/lucaspang
• http://www.twitter.com/bdcareers
Website
• http://www.builddirect.com/careers
About Me
Testing Pyramid
Never forget the pyramid!
• Target audience is for people who have experience using Selenium WebDriver
• At BuildDirect we use:• Selenium WebDriver for desktop
• http://www.seleniumhq.org• Appium for mobile/tablet
• http://appium.io• My experience is with C# bindings only. Other languages should be similar.
Background
• Methods to increase code re-use
• Learn some differences between various browsers
• Learn from BD experiences
Goals of this Talk
Statement
• I do not want my test runs interrupted by any OS level dialog windows
Sample
Problem
• iOS automatically downloads and prompts for update
iOS
Workaround
• Disable it!
iOS
Statement
• I want to run custom javascript during my test to do different actions (like open a new browser window).
Sample
Problem
• iOS restricts this due to security reasons
iOS
((IJavaScriptExecutor)Driver).ExecuteScript("window.open();");
Workaround
• Skip tests that run on iOS devices
or
• If you’re running tests against a simulator, Appium has a capability option to allow Safari to open new browsers
iOS
var dc = DesiredCapabilities.IPhone(); dc.SetCapability(“safariAllowPopups", “true");
Statement
• I want to send “action” keys to a textbox to cause a Javascript blur event
Sample
Problem
• Some keys will send an emoji character instead
• Tab will send
iOS
Driver.FindElement(By.Id(“username")).SendKeys(Keys.Tab);
Workaround
• We were using the Keys.Tab to cause a Javascript blur event
• We were able to do the same by changing focus to another element
iOS
Statement
• I want to easily interact with elements on Android devices
Sample
Problem
• Sometimes, elements cannot be interacted with if they are not in the view
Android
Driver.FindElement(By.Id("loginButton")).Click();
Workaround
• Add scrolling functionality to prior to clicking on element
• Install a keyboard app called “Null Keyboard” that permanently hides the keyboard
• Appium has a method to close the keyboard
Android
var ele = Driver.FindElement(By.Id("loginButton")); var js = (IJavaScriptExecutor) Driver; js.ExecuteScript("arguments[0].scrollIntoView(true);", ele);
Statement
• I want to click on the element so that I can do actions on IE browser
Sample
Problem
• Sometimes IE will not execute the click properly and the view will not change
Internet Explorer
Driver.FindElement(By.Id("loginButton")).Click();
Workaround
• Wrap the Click() method and have it retry if first click failed
Internet Explorer
driver.FindElement(elementToClick).Click();
// element still on screen, retry only when testing using IE if (driver.FindElement(elementToClick) != null && driver is InternetExplorerDriver){ driver.FindElement(elementToClick).Click(); }
Statement
• I want to be able to delete all the cookies so my browser has a clean session before running the test
Sample
Problem
• IE cannot manipulate httpOnly cookies
Internet Explorer
Driver.Manage().Cookies.DeleteAllCookies();
Workaround
• When instantiating the InternetExplorerDriver we can set options to ensure that the session is cleared
• Note that his means you have to start a new browser for each test
Internet Explorer
var opts = new InternetExplorerOptions { EnsureCleanSession = true };
Driver = new InternetExplorerDriver(opts);
Statement
• I want to write my automation once so I don’t have to have special code paths for different device views
Sample
Problem
• A responsive view might have multiple elements with the same locator value and your FindElement() might not get the one you want
Responsive Design
Driver.FindElement(By.Id("loginButton"));
Workaround
• Use the same locator value for all the designs
• From the test make sure your FindElement searches for Displayed == true elements only
• Add special helper variables to help determine if you are in mobile, tablet, or desktop view
• Limit use of these though as it could increase test maintenance work
Responsive Design
Driver.FindElements(By.Id("loginButton")).First(e => e.Displayed);
Statement
• I am running tests remotely and want screenshots during test run for debugging
Problem
• Screenshots can increase test run time. Some devices/browsers more than others
• IE takes a full webpage by taking multiple screenshots and combining them
• Android/iOS devices are slow when taking screenshots
Screenshots
Workaround
• Only take screenshots on failed steps
• Have a way to easily toggle screenshots on or off
Screenshots
• Each browser has its own quirks
• Be flexible in your automation design
• Limit the amount of browser specific code
Summary
Questions?