ui automation quirks
TRANSCRIPT
![Page 1: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/1.jpg)
Test Automation
![Page 2: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/2.jpg)
• UI Automation Quirks
• Break
• Scalable Test Automation
Agenda
![Page 3: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/3.jpg)
UI Automation Quirks
![Page 4: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/4.jpg)
• http://www.linkedin.com/in/lucaspang
• http://www.twitter.com/bdcareers
Website
• http://www.builddirect.com/careers
About Me
![Page 5: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/5.jpg)
Testing Pyramid
Never forget the pyramid!
![Page 6: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/6.jpg)
• 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
![Page 7: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/7.jpg)
• Methods to increase code re-use
• Learn some differences between various browsers
• Learn from BD experiences
Goals of this Talk
![Page 8: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/8.jpg)
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
![Page 9: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/9.jpg)
Workaround
• Disable it!
iOS
![Page 10: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/10.jpg)
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();");
![Page 11: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/11.jpg)
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");
![Page 12: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/12.jpg)
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);
![Page 13: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/13.jpg)
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
![Page 14: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/14.jpg)
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();
![Page 15: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/15.jpg)
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);
![Page 16: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/16.jpg)
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();
![Page 17: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/17.jpg)
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(); }
![Page 18: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/18.jpg)
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();
![Page 19: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/19.jpg)
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);
![Page 20: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/20.jpg)
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"));
![Page 21: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/21.jpg)
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);
![Page 22: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/22.jpg)
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
![Page 23: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/23.jpg)
Workaround
• Only take screenshots on failed steps
• Have a way to easily toggle screenshots on or off
Screenshots
![Page 24: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/24.jpg)
• Each browser has its own quirks
• Be flexible in your automation design
• Limit the amount of browser specific code
Summary
![Page 25: UI Automation Quirks](https://reader035.vdocuments.net/reader035/viewer/2022062417/587cc0661a28ab38028b7b69/html5/thumbnails/25.jpg)
Questions?