Successfully reported this slideshow.
Your SlideShare is downloading. ×

Selenium Tips & Tricks - StarWest 2015

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad

Check these out next

1 of 82 Ad

Selenium Tips & Tricks - StarWest 2015

Download to read offline

These are the slides presented at StarWest 2015 in Anaheim, CA. The slides are showcasing all of the advanced usages of selenium or add ons to improve your selenium test cases

These are the slides presented at StarWest 2015 in Anaheim, CA. The slides are showcasing all of the advanced usages of selenium or add ons to improve your selenium test cases

Advertisement
Advertisement

More Related Content

Slideshows for you (20)

Similar to Selenium Tips & Tricks - StarWest 2015 (20)

Advertisement

Recently uploaded (20)

Selenium Tips & Tricks - StarWest 2015

  1. 1. Selenium
 Tips & Tricks by Andrew Krug @andrewmkrug andrew@revcontent.com
  2. 2. Who is this person? • Worked in Test Automation entire career • Currently Lead Test Automation Engineer for Revcontent • Market Leader for Native Advertising • Worked at Ceridian HCM/FIS/Ceridian HCM • Windows, Mac, iOS, Android, Window Phone and Blackberry
  3. 3. Revcontent • Market Leader for Native Advertising • 2-3 times greater RPM than Competitors • Related Stories Around the Web
  4. 4. Revcontent We’re Hiring!
  5. 5. !Plagiarized • These Slides are adapted with permission from Dave Haeffner’s Selenium Tips & Tricks • Runs Elemental Selenium bit.ly/se-weekly-tips • Weekly Tip Newsletter • Selenium Guidebook bit.ly/se-guidebook • Title speaks for itself • Bootcamp bit.ly/se-bootcamp
  6. 6. Selenium • Sent from the Future • Is a toolbox • ! Tool
  7. 7. Expected Outcome foreach attendee in here: AssertThat( learnedNewSelenium = True) To do that just raise your hand every time you learn
  8. 8. ! Talking • Appium • Mobile Device Testing • FBSimulatorControl • >1 iOS Simulators on 1 Mac • SWD Recorder • Generates Page Objects • Docker-Selenium • Hub & Node Containers • SeleniumGridScaler • On Demand Nodes for Test • Selenium Grid Extras • Grid Hub on Steroids
  9. 9. See what I did there?
  10. 10. Topics • Headless • Visual Testing • Proxy Servers • Load Testing! • A/B Testing • Files Handling • Notifications • Mobile Browser Emulation • !Mobile Devices • Music Playing • Bonuses are sprinkled throughout
  11. 11. –Johnny Appleseed “Sprinkles are for winners.”
  12. 12. You are all winners!
  13. 13. Headless
  14. 14. Not This Headless Horseman https://www.flickr.com/photos/fanabouttown/10719478555
  15. 15. Or This Horseless Headsman http://www.framestore.com/work/snickers-horseless-headsman
  16. 16. What is it? • No GUI • Generally
  17. 17. Benefits • Speed • Grid Maintenance • Screenshots
  18. 18. Headless with Xvfb for *nix
  19. 19. Xvfb? • X virtual frame buffer • In-memory display server • run graphical applications with out display
  20. 20. Xvfb Option 1 • Start Xvfb on a port • Tell terminal to use the port • Run Test Xvfb :99 export DISPLAY=:99 ruby example.rb
  21. 21. Option 2 • Use Xvfb-run to launch tests xvfb-run ruby example.rb
  22. 22. Option 3 • Use the headless gem
  23. 23. Headless with PhantomJS • phantomjs.org • not limited by OS
  24. 24. PhantomJS Options 1.Add to path WebDriver = new PhantomJSDriver(); 2.Start with WebDriver Flag phantomjs --webdriver=8910 3.Pass in Executable Path Similar to Chromedriver or IEDriverServer
  25. 25. Visual Testing
  26. 26. What?!?!?
  27. 27. How Awesome! • Check UI appears correctly • Find layout bugs • Font, layout, rendering differences • Verify Content • Charts • Are Multiple Libraries • Time for some Sprinkles!!! • Few Lines of Code!!!
  28. 28. Challenges • Complex • False Positives • Shifted content • Dynamic content
  29. 29. Training Skynet
  30. 30. Why Applitools • https://applitools.com • Compare Layout of Page • Disregard areas • Finds related problems • Deals with the Challenges • I can do more stuff!!!
  31. 31. Before Test driver.get(“the-internet.heroku.com/login”); driver.findElement(By.id(“username”)) .sendKeys(“tomsmith”); driver.findElement(By.id(“password”)) .sendKeys(“SuperSecretPassword”); driver.findElement(By.id(“login”)).submit();
  32. 32. With Eyeballs driver.get(“the-internet.heroku.com/login”); Eyes eyes = new Eyes(); eyes.setApiKey(apikey); eyes.CheckWindow(“Login”); driver.findElement(By.id(“username”)).sendKeys(“tomsmith”); driver.findElement(By.id(“password”)).sendKeys(“SuperSecretPassword”); driver.findElement(By.id(“login”)).submit(); eyes.checkWindow(“Logged In”);
  33. 33. With Eyeballs driver.get(“the-internet.heroku.com/login”); Eyes eyes = new Eyes(); eyes.setApiKey(apikey); eyes.CheckWindow(“Login”); driver.findElement(By.id(“username”)).sendKeys(“tomsmith”); driver.findElement(By.id(“password”)).sendKeys(“SuperSecretPassword”); driver.findElement(By.id(“login”)).submit(); eyes.checkWindow(“Logged In”);
  34. 34. With Eyeballs in Test Context driver.get(“the-internet.heroku.com/login”); eyes.CheckWindow(“Login”); driver.findElement(By.id(“username”)).sendKeys(“tomsmith”); driver.findElement(By.id(“password”)).sendKeys(“SuperSecret Password”); driver.findElement(By.id(“login”)).submit(); eyes.checkWindow(“Logged In”);
  35. 35. Why can’t Selenium get HTTP Status Codes?
  36. 36. https://shanicea2mediablog.wordpress.com/2012/04/16/bbfc- mpaa/ Copyright 2015
  37. 37. – Every Selenium Contributor Ever “No.”
  38. 38. Still want HTTP Status Codes? • Proxy • BrowserMob Proxy
  39. 39. Where does a proxy fit? What does a proxy do
  40. 40. Why is it Awesome? • Blacklisting • Bad Image Checking • Performance Testing! • Sort of • Load Testing! • Sort of
  41. 41. How to use BrowserMob • Browser profile with BrowserMob Proxy • Firefox • Chrome • Java jar • Built-in Configuration options
  42. 42. Blacklisting • Add it to the Blacklist • Forces all requests to specified URL to be returned as 404
  43. 43. Broken Image Checking • Proxy Server • HTTP Library • JavaScript
  44. 44. Proxy Image Checking • Get HAR • HAR = HTTP Archive • Find all image elements • Go thru all entries in HAR • Validate that each image source was not 404
  45. 45. HTTP Library • Mostly same as before • Use library to make a request to each source • Validate response = 200
  46. 46. JavaScript • Validate each image has a width executeScript(“return arguments[0].complete && typeof arguments[0].naturalWidth != ”undefined” && arguments[0].naturalWidth > 0”, image)
  47. 47. Performance Testing • HAR = HTTP Archive • Validate page load times are under SLA • Bonus • Send metrics to a dashboard for monitoring
  48. 48. Load Testing • Sort of • HAR -> JMX • https://flood.io/har2jmx
  49. 49. Forgotten Password? Click Here
  50. 50. Options • Gmail API to going to Open Auth • Mailosaur • Exchange • Yahoo Mail
  51. 51. Mailosaur Sample MailboxApi mailbox = new MailboxApi(mailbox, apikey); Email[] emails = mailbox.getEmailsByRecipient("anything. 1eaaeef6@mailosaur.in"); assertEquals("The subject should be something", "something", emails[0].Subject);
  52. 52. Mailosaur Sample MailboxApi mailbox = new MailboxApi(mailbox, apikey); Email[] emails = mailbox.getEmailsByRecipient("anything. 1eaaeef6@mailosaur.in"); assertEquals("The subject should be something", "something", emails[0].Subject);
  53. 53. A/B Testing
  54. 54. Options A & B for A/B Testing A. Forge Cookies B. Appending a query to the URL
  55. 55. Cookie Forging driver.manage.add_cookie(name: ‘optimizlyOptOut’, value: ‘true’)
  56. 56. URL Appending driver.get(‘the-internet.herokuapp.com/ abtest?optimizley_op_out=true')
  57. 57. URL Appending driver.get(‘the-internet.herokuapp.com/ abtest?optimizley_op_out=true')
  58. 58. File Handeling
  59. 59. Uploading • Don’t use AutoIt or AppleScript • Takes over OS • If error tests may or may not continue • Instead • Send path to input field ...
  60. 60. Downloading • Configure Profile to download locally • Use HTTP library • Check Headers for • Content Type • Length ...
  61. 61. Let’s Do Some More Selenium Stuff
  62. 62. Highlight Elements
  63. 63. Highlighting in JS • Get current element styling • Execute JS “arguments[0].setAttribute(arguments[1], arguments[2])”, element, “style”, “border: 2px solid red;” “arguments[0].setAttribute(arguments[1], arguments[2])”, element, “style”, original_style
  64. 64. Highlighting in JS • Get current element styling • Execute JS “arguments[0].setAttribute(arguments[1] , arguments[2])”, element, “style”, “border: 2px solid red;” “arguments[0].setAttribute(arguments[1] , arguments[2])”, element, “style”, original_style
  65. 65. Growl Notifications
  66. 66. Growl? • What is it? • Step by Step code execution • Long running tests • Non-Testing
  67. 67. Growl Options • JavaScript • Growl
  68. 68. JavaScript • Add jQuery to the page • Add growl.js to the page • Tell growl to display message
  69. 69. Video Time
  70. 70. Growl • Add Growl to main machine point tests to send notification to growl • Bonus • Forward events to other computers or mobile devices
  71. 71. Growl Sample growl=gntp.notifier.GrowlNotifier ( applicationName = "My App Name", notifications = ["New Updates","New Messages"], defaultNotifications = ["New Messages"], hostname = "localhost", # Default password = "" # Default ) growl.register() growl.notify( noteType = "New Messages", title = "You have a new message", description = "A longer message description", icon = "http://example.com/ icon.png", sticky = False, priority = 1, )
  72. 72. Mobile Device Emulation!
  73. 73. What!?!?! • From Chrome go to Developer Tools • Click This -> • Top left corner • Reload Page
  74. 74. Mobile Emulation Magic Map<String, String> mobileEmulation = new HashMap<String, String>(); mobileEmulation.put("deviceName", "Google Nexus 5"); Map<String, Object> chromeOptions = new HashMap<String, Object>(); chromeOptions.put("mobileEmulation", mobileEmulation); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions); WebDriver driver = new ChromeDriver(capabilities);
  75. 75. Mobile Emulation Magic Map<String, String> mobileEmulation = new HashMap<String, String>(); mobileEmulation.put("deviceName", "Google Nexus 5"); Map<String, Object> chromeOptions = new HashMap<String, Object>(); chromeOptions.put("mobileEmulation", mobileEmulation); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions); WebDriver driver = new ChromeDriver(capabilities);
  76. 76. Training the Terminator
  77. 77. Huh?? • Jason Huggins • @hugs • Creator of Selenium • Likes Robots • Built Robot
  78. 78. Robot Playing Music https://youtu.be/9F-Vb9EhdIc
  79. 79. More Selenium Resources • bit.ly/se-bootcamp • bit.ly/se-guidebook • bit.ly/se-weekly-tips • Selenium Conference YouTube Channel • the-internet.herokuapp.com • Great resource for practicing Selenium
  80. 80. Questions?
  81. 81. Thanks for Staying @andrewmkrug andrew@revcontent.com Thanks
  82. 82. Revcontent We’re Hiring!

×