Tips From Our Codebase To Help You Write Reliable Selenium Tests

Posted by Santiago Suarez Ordoñez in EventsSelenium ResourcesVideos

As part of our new "Test Like A Ninja Webinar Series," I held an improv webinar last week that covered how to write better Selenium tests. Most of the content came from my own Selenium experience, as well as experience gleaned from working on our own customers' issues. Without further ado, here's the video:

And here are some of the code snippets I talked about:

Implicit waits in Selenium 1: https://gist.github.com/1107375.js?file=implicit_wait_selenium.py

Ignoring Open and waitForPageToLoad failures, as well as reporting pass/fail status automatically: https://gist.github.com/1107711.js?file=selenium_test_case.py

Reporting pass/fail status automatically on python for Selenium 2 tests: https://gist.github.com/1107750.js?file=selenium2_test_case.py

Happy testing!

Free Trial

Get access to a free 14-day trial version, or contact Sales for more information.

\n

\n

Ignoring Open and waitForPageToLoad failures, as well as reporting pass/fail status automatically: https://gist.github.com/1107711.js?file=selenium_test_case.py
\n\n

\n

Reporting pass/fail status automatically on python for Selenium 2 tests: https://gist.github.com/1107750.js?file=selenium2_test_case.py
\n\n

\n

Happy testing!

","useMarkdown":true}), document.getElementById("react_KQtLlGyUYEyYIgKBEeqyXQ")); ReactDOM.render(React.createElement(Components.RichTextArea, {}), document.getElementById("react_tssyM7xskKXw9bt1OVccQ")); ReactDOM.render(React.createElement(Components.Share, {"title":"Share","href":"http://sauce-labs.saucelabs-host.publishwithagility.com/blog/tips-from-our-codebase-to-help-you-write-reliable-selenium-tests"}), document.getElementById("react_d7fZ45vbUqj7bV1xJLWvA")); ReactDOM.render(React.createElement(Components.ButtonGroup, {"buttons":[{"key":3630,"text":"Subscribe to our blog","href":"/blog/rss.xml","target":"_blank","styles":["tertiaryFilled"]}],"styles":["extraBottomMargin"]}), document.getElementById("react_lwOOnt7v0yZ3x6wREIUw")); ReactDOM.render(React.createElement(Components.Heading, {"text":"Categories","tag":"h3","styles":["h2LineHeight"]}), document.getElementById("react_W9sLxiTZcUuf6XlGRGaOw")); ReactDOM.render(React.createElement(Components.BlogCategoryList, {"categories":[{"key":1546,"title":"Agile","href":"/blog/category/agile"},{"key":1547,"title":"AngularJS","href":"/blog/category/angularjs"},{"key":1548,"title":"Appium","href":"/blog/category/appium"},{"key":1549,"title":"Appium Resources","href":"/blog/category/appium-resources"},{"key":1550,"title":"Automation","href":"/blog/category/automation"},{"key":1551,"title":"Best Practice","href":"/blog/category/best-practice"},{"key":1552,"title":"Contests","href":"/blog/category/contests"},{"key":1553,"title":"Continuous Delivery","href":"/blog/category/continuous-delivery"},{"key":1554,"title":"Continuous Integration","href":"/blog/category/continuous-integration"},{"key":1555,"title":"Continuous Testing","href":"/blog/category/continuous-testing"},{"key":3587,"title":"Cross Browser Testing","href":"/blog/category/cross-browser-testing"},{"key":1556,"title":"DevOps","href":"/blog/category/devops"},{"key":1557,"title":"Events","href":"/blog/category/events"},{"key":1558,"title":"Guest Blog Posts","href":"/blog/category/guest-blog-posts"},{"key":3584,"title":"Java","href":"/blog/category/java"},{"key":1559,"title":"JavaScript","href":"/blog/category/javascript"},{"key":3607,"title":"Jenkins","href":"/blog/category/jenkins"},{"key":3476,"title":"JUnit","href":"/blog/category/junit"},{"key":1560,"title":"Mobile","href":"/blog/category/mobile"},{"key":1561,"title":"Mobile Development & Testing","href":"/blog/category/mobile-development-testing"},{"key":1562,"title":"News & Product Updates","href":"/blog/category/news-product-updates"},{"key":1563,"title":"Open Sauce","href":"/blog/category/open-sauce"},{"key":1564,"title":"Press","href":"/blog/category/press"},{"key":1565,"title":"Product Updates","href":"/blog/category/product-updates"},{"key":1566,"title":"Protractor","href":"/blog/category/protractor"},{"key":1567,"title":"QA","href":"/blog/category/qa"},{"key":1568,"title":"Quality Assurance","href":"/blog/category/quality-assurance"},{"key":1569,"title":"Quality Engineering","href":"/blog/category/quality-engineering"},{"key":1570,"title":"Releases","href":"/blog/category/releases"},{"key":1571,"title":"Ruby","href":"/blog/category/ruby"},{"key":1572,"title":"Sauce Product Info","href":"/blog/category/sauce-product-info"},{"key":3573,"title":"Scrum","href":"/blog/category/scrum"},{"key":1573,"title":"Security Testing","href":"/blog/category/security-testing"},{"key":1574,"title":"Selenium","href":"/blog/category/selenium"},{"key":1575,"title":"Selenium Resources","href":"/blog/category/selenium-resources"},{"key":1576,"title":"Software Development & Testing","href":"/blog/category/software-development-testing"},{"key":1577,"title":"The Story of Sauce","href":"/blog/category/the-story-of-sauce"},{"key":1578,"title":"Uncategorized","href":"/blog/category/uncategorized"},{"key":1579,"title":"Videos","href":"/blog/category/videos"},{"key":1580,"title":"WebdriverIO","href":"/blog/category/webdriverio"},{"key":1581,"title":"Webinars","href":"/blog/category/webinars"}]}), document.getElementById("react_u0mCCsPs5Eie80ahUZyRw")); ReactDOM.render(React.createElement(Components.ButtonGroup, {"buttons":[{"key":2497,"text":"Free Trial","href":"/signup/trial","styles":["inverted"]},{"key":2498,"text":"Contact Us","href":"/contact","styles":["inverted"]}],"styles":["center","noMargin"]}), document.getElementById("react_bEL7l6sHkedyu1X87qwRw")); ReactDOM.render(React.createElement(Components.SiteHeader, {"navigation":{"links":[{"key":149,"title":"Solutions","children":[{"key":160,"title":"Enterprise","href":"/enterprise","children":[{"key":162,"title":"Automated Testing Platform","href":"/enterprise#automated-testing-platform","children":[],"isActive":false},{"key":161,"title":"Cross Browser Testing","href":"/enterprise#cross-browser-testing","children":[],"isActive":false},{"key":2373,"title":"Mobile Testing","href":"/enterprise#mobile-testing","children":[],"isActive":false},{"key":2374,"title":"Manual Testing","href":"/enterprise#manual-testing","children":[],"isActive":false},{"key":163,"title":"Request a Quote","href":"http://info.saucelabs.com/enterprise-request-lp.html","target":"_blank","children":[],"isActive":false}],"isActive":false},{"key":775,"title":"Small Team","href":"/small-team","children":[{"key":772,"title":"Automated Testing Platform","href":"/small-team#automated-testing-platform","children":[],"isActive":false},{"key":771,"title":"Cross Browser Testing","href":"/small-team#cross-browser-testing","children":[],"isActive":false},{"key":2375,"title":"Mobile Testing","href":"/small-team#mobile-testing","children":[],"isActive":false},{"key":2376,"title":"Manual Testing","href":"/small-team#manual-testing","children":[],"isActive":false},{"key":774,"title":"Pricing","href":"/pricing","children":[],"isActive":false}],"isActive":false},{"key":944,"title":"Open Source","href":"/open-source","children":[{"key":942,"title":"Automated Testing Platform","href":"/open-source#automated-testing-platform","children":[],"isActive":false},{"key":941,"title":"Cross Browser Testing","href":"/open-source#cross-browser-testing","children":[],"isActive":false},{"key":2377,"title":"Mobile Testing","href":"/open-source#mobile-testing","children":[],"isActive":false},{"key":2378,"title":"Manual Testing","href":"/open-source#manual-testing","children":[],"isActive":false},{"key":943,"title":"Signup","href":"https://saucelabs.com/beta/signup/OSS/None","target":"_blank","children":[],"isActive":false}],"isActive":false},{"key":1356,"title":"Additional Products","children":[{"key":2280,"title":"JavaScript Unit Testing","href":"/products/javascript-unit-testing","children":[],"isActive":false},{"key":1357,"title":"Open Source Frameworks","href":"/products/open-source-frameworks","children":[],"isActive":false},{"key":1358,"title":"Integrations","href":"/products/integrations","children":[],"isActive":false},{"key":3466,"title":"Platforms","href":"/platforms","children":[],"isActive":false}],"isActive":false}],"isActive":false},{"key":150,"title":"Stories","children":[{"key":249,"title":"Enterprise","href":"/enterprise/stories","children":[{"key":491,"title":"Case Studies","href":"/enterprise/case-studies","children":[],"isActive":false},{"key":492,"title":"Industry Examples","href":"/enterprise/stories#industry-examples","children":[],"isActive":false},{"key":493,"title":"Testimonials","href":"/enterprise/stories#testimonials","children":[],"isActive":false}],"isActive":false},{"key":790,"title":"Small Team","href":"/small-team/stories","children":[{"key":786,"title":"Case Studies","href":"/small-team/case-studies","children":[],"isActive":false},{"key":787,"title":"Industry Examples","href":"/small-team/stories#industry-examples","children":[],"isActive":false},{"key":788,"title":"Testimonials","href":"/small-team/stories#testimonials","children":[],"isActive":false}],"isActive":false},{"key":950,"title":"Open Source","href":"/open-source/stories","children":[{"key":946,"title":"Case Studies","href":"/open-source/case-studies","children":[],"isActive":false},{"key":947,"title":"Industry Examples","href":"/open-source/stories#industry-examples","children":[],"isActive":false},{"key":948,"title":"Testimonials","href":"/open-source/stories#testimonials","children":[],"isActive":false},{"key":949,"title":"Community","href":"/community","children":[],"isActive":false}],"isActive":false}],"isActive":false},{"key":1425,"title":"Pricing","href":"/pricing","children":[],"isActive":false},{"key":152,"title":"Resources","href":"/resources","children":[{"key":1271,"title":"Featured Resources","href":"/resources","children":[],"isActive":false},{"key":607,"title":"Blog","href":"/blog","children":[],"isActive":true},{"key":841,"title":"Compare Us","href":"/compare-us","children":[],"isActive":false},{"key":1272,"title":"Videos","href":"/resources/videos","children":[],"isActive":false},{"key":606,"title":"Articles","href":"/resources/articles","children":[],"isActive":false},{"key":700,"title":"White Papers","href":"/resources/white-papers","children":[],"isActive":false},{"key":698,"title":"Data Sheets","href":"/resources/data-sheets","children":[],"isActive":false},{"key":654,"title":"Case Studies","href":"/case-studies","children":[],"isActive":false},{"key":634,"title":"Webinars","href":"/resources/webinars","children":[],"isActive":false},{"key":2855,"title":"Best Practices","href":"/resources/best-practices","children":[],"isActive":false}],"isActive":false},{"key":153,"title":"Support","href":"/support","children":[{"key":3325,"title":"Overview","href":"/support","children":[],"isActive":false},{"key":810,"title":"Knowledge Base","href":"/support#knowledge-base","children":[],"isActive":false},{"key":811,"title":"Documentation","href":"/support#documentation","children":[],"isActive":false},{"key":813,"title":"Training","href":"https://training.saucelabs.com/","target":"_blank","children":[],"isActive":false},{"key":3326,"title":"Services","href":"/support#services","children":[],"isActive":false},{"key":809,"title":"Contact Support","href":"/support#contact","children":[],"isActive":false}],"isActive":false},{"key":154,"title":"Company","href":"/company","children":[{"key":1156,"title":"Company","href":"/company","children":[{"key":1198,"title":"Team","href":"/company/team","children":[],"isActive":false},{"key":1157,"title":"Values","href":"/company/values","children":[],"isActive":false},{"key":1448,"title":"Careers","href":"/company/careers","children":[],"isActive":false},{"key":1167,"title":"Partners","href":"/company/partners","children":[],"isActive":false},{"key":1430,"title":"Contact Us","href":"/contact","children":[],"isActive":false}],"isActive":false},{"key":1238,"title":"News","href":"/news","children":[{"key":1239,"title":"Press Releases","href":"/news/category/press-releases","children":[],"isActive":false},{"key":1240,"title":"Press Coverage","href":"/news/category/press-coverage","children":[],"isActive":false},{"key":1241,"title":"Awards","href":"/news/category/awards","children":[],"isActive":false}],"isActive":false},{"key":1042,"title":"Community","href":"/community","children":[{"key":1043,"title":"Join Secret Sauce","href":"/community#secretsauce","children":[],"isActive":false},{"key":1044,"title":"Events","href":"/community#events","children":[],"isActive":false},{"key":1132,"title":"Appium","href":"/community#appium","children":[],"isActive":false},{"key":1133,"title":"Selenium","href":"/community#selenium","children":[],"isActive":false}],"isActive":false}],"isActive":false}],"cta":{"text":"Free Trial","href":"/signup/trial"},"signIn":{"text":"Sign In","href":"/beta/login"}}}), document.getElementById("react_JL8EZcZIUGtokBwgQqF0A")); ReactDOM.render(React.createElement(Components.SiteFooter, {"lang":{"captoraHeading":"Trending Topics","copyright":"© 2016 Sauce Labs. All rights reserved.","subscribeButtonText":"Join","subscribeEmailLabel":"Email*","subscribeFormID":"385","subscribeHeading":"Join our mailing list"},"links":[{"key":108,"title":"Solutions","children":[{"key":323,"title":"Enterprise","href":"/enterprise","children":[],"isActive":false},{"key":767,"title":"Small Team","href":"/small-team","children":[],"isActive":false},{"key":951,"title":"Open Source","href":"/open-source","children":[],"isActive":false}],"isActive":false},{"key":112,"title":"Stories","children":[{"key":376,"title":"Enterprise","href":"/enterprise/stories","children":[],"isActive":false},{"key":800,"title":"Small Team","href":"/small-team/stories","children":[],"isActive":false},{"key":952,"title":"Open Source","href":"/open-source/stories","children":[],"isActive":false}],"isActive":false},{"key":122,"title":"Resources","href":"/resources","children":[{"key":1273,"title":"Featured Resources","href":"/resources","children":[],"isActive":false},{"key":609,"title":"Blog","href":"/blog","children":[],"isActive":true},{"key":993,"title":"Compare Us","href":"/compare-us","children":[],"isActive":false}],"isActive":false},{"key":802,"title":"Support","href":"/support","target":"_blank","children":[{"key":803,"title":"Contact Support","href":"/support#contact","children":[],"isActive":false},{"key":805,"title":"Knowledge Base","href":"/support#knowledge-base","children":[],"isActive":false},{"key":806,"title":"Documentation","href":"/support#documentation","children":[],"isActive":false},{"key":808,"title":"Training","href":"https://training.saucelabs.com/","target":"_blank","children":[],"isActive":false},{"key":3566,"title":"Status","href":"https://status.saucelabs.com/","target":"_blank","children":[],"isActive":false}],"isActive":false},{"key":144,"title":"Company","href":"/company","children":[{"key":1160,"title":"Team","href":"/company/team","children":[],"isActive":false},{"key":1158,"title":"Values","href":"/company/values","children":[],"isActive":false},{"key":1237,"title":"Careers","href":"/company/careers","children":[],"isActive":false},{"key":2879,"title":"Partners","href":"/company/partners","children":[],"isActive":false},{"key":3467,"title":"Contact Us","href":"/contact","children":[],"isActive":false}],"isActive":false},{"key":2875,"title":"News","href":"/news","children":[{"key":2876,"title":"Press Releases","href":"/news/category/press-releases","children":[],"isActive":false},{"key":2877,"title":"Press Coverage","href":"/news/category/press-coverage","children":[],"isActive":false},{"key":2878,"title":"Awards","href":"/news/category/awards","children":[],"isActive":false}],"isActive":false},{"key":116,"title":"Community","href":"/community","children":[{"key":1045,"title":"Join Secret Sauce","href":"/community#secretsauce","children":[],"isActive":false},{"key":1046,"title":"Events","href":"/community#events","children":[],"isActive":false},{"key":1134,"title":"Appium","href":"/community#appium","children":[],"isActive":false},{"key":1135,"title":"Selenium","href":"/community#selenium","children":[],"isActive":false}],"isActive":false}],"disclaimerLinks":[{"key":354,"title":"Terms of Service","href":"/terms-of-service","children":[],"isActive":false},{"key":355,"title":"Privacy Policy","href":"/privacy-policy","children":[],"isActive":false}],"copyright":"© 2016 Sauce Labs. All rights reserved.","socialLinks":[{"key":1462,"service":"Facebook","href":"https://www.facebook.com/saucelabs","icon":"facebook"},{"key":1463,"service":"Twitter","href":"https://twitter.com/saucelabs","icon":"twitter"},{"key":1464,"service":"Google Plus","href":"https://plus.google.com/111293610298852124914","icon":"google-plus"},{"key":1465,"service":"LinkedIn","href":"https://www.linkedin.com/company/891955","icon":"linkedin"}],"marketoId":"468-XBT-687","captora":"\n\n"}), document.getElementById("react_owdgxB2cQUGccJKUHxZYjQ"));