{"id":12101,"date":"2018-04-02T06:42:00","date_gmt":"2018-04-02T06:42:00","guid":{"rendered":"https:\/\/viewmyprojects.com\/winwirewp\/?p=12101"},"modified":"2024-06-06T10:25:41","modified_gmt":"2024-06-06T10:25:41","slug":"best-practices-implementing-selenium-automation","status":"publish","type":"post","link":"https:\/\/viewmyprojects.com\/winwirewp\/blog\/best-practices-implementing-selenium-automation\/","title":{"rendered":"Best Practices of Implementing Selenium Test Automation"},"content":{"rendered":"\n<p>Selenium automation is becoming the most sought after automated testing tool. I reviewed different websites that dedicate their entire content to Selenium. As I observed endless theoretical backgrounds, examples, explanations, installations, and code segments, the one thing that I wanted to dig deeper into was why more and more organizations are migrating to Selenium?<\/p>\n\n\n\n<p>In order to clearly understand the benefits of Selenium and why it is gaining popularity, we first need to understand automation testing.<\/p>\n\n\n\n<p class=\"blog-detail-list\"><strong>Key Findings<\/strong><br>\u2022 In the past decade, the growth of IT industry has brought along complex IT products and even more complicated applications. Effective testing is even more important as there is no scope for human errors or manual blunders.<br>\u2022 Automated testing is taking over manual processes as it faster and more efficient. It is not prone to errors, provides test coverage in short time, and comes at a low cost.<br>\u2022 The demand for automation testing is increasing at an unprecedented speed and scale. According to Transparency Market Research (TMR), the global test automation market will likely expand at a robust CAGR of 15.4% from 2017 to 2025 to become worth US$ 109.69 billion by 2025 from US$ 30.45 billion in 2016.<br>\u2022 Success here depends on identifying the right tool for the project. With so many automation tools to choose from, this process can be tricky.<\/p>\n\n\n\n<p><strong>Selenium, the All-time Favorite<\/strong><\/p>\n\n\n\n<p>Selenium, the open-source automation testing tool for web-based applications, is becoming increasingly popular. The extensively used automation tool has certain unique benefits that give it an edge over the competition. Let\u2019s see why it is the most preferred choice of organizations and automation testers.<\/p>\n\n\n\n<p class=\"blog-detail-list\">\u2022 The main reason for the success of Selenium is that the tests can be coded in any number of programming languages, they can be run directly in web browsers, and work across operating systems.<br>\u2022 The second reason for the success of Selenium as the most powerful automation tool are its features that are simple to use \u2013 its capable user interfaces help meet 90% needs of web application testers. and more of these make it a preferred choice for many testers.<\/p>\n\n\n\n<p><strong>Best Practices \u2013 Selenium Test Automation<\/strong><\/p>\n\n\n\n<p>Based on experience of leveraging Selenium for test automation, I recommend the following practices:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Use PageObjects Pattern&nbsp;<\/strong><\/li>\n<\/ol>\n\n\n\n<p>Page Object model is an object design pattern in Selenium, where web pages are represented as classes, and the various elements on the page are defined as variables on the class. All possible user interactions can then be implemented as methods on the class:<\/p>\n\n\n\n<p>clickLoginButton();<\/p>\n\n\n\n<p>setCredentials (user_name, user_password);<\/p>\n\n\n\n<p>Since well-named methods in classes are easy to read, this works as an elegant way to implement test routines that are both readable and easier to maintain or update in the future.<\/p>\n\n\n\n<p>Advantages of using Page Object Pattern:<\/p>\n\n\n\n<p class=\"blog-detail-list\">\u2022 Easy to Maintain<br>\u2022 Easy Readability of scripts<br>\u2022 Reduce or Eliminate duplicity<br>\u2022 Re-usability of code<br>\u2022 Reliability<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li><strong>Preferred selector order:<\/strong><\/li>\n<\/ol>\n\n\n\n<p>Preferred selector order: id &gt; name &gt;links text&gt; css &gt; xpath<\/p>\n\n\n\n<p>CSS and XPath are location-based selectors, they are slower than other selectors.<\/p>\n\n\n\n<p class=\"blog-detail-list\">\u2022 Id and name are often the easiest and sure way.<br>\u2022 CSS = Id + name.<br>\u2022 Last solution should be xpath.<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li><strong>Avoid Thread.sleep prefer Wait<\/strong><\/li>\n<\/ol>\n\n\n\n<p>Instead of sleep, use explicit wait\/implicit wait is the best practice, let\u2019s see what actually the explicit wait, Thread.sleep(), Implicit wait\u2019s working logic<\/p>\n\n\n\n<p><strong><em>Explicit wait:<\/em><\/strong>An explicit wait is a kind of wait for a certain condition to occur before proceeding further in the code.<\/p>\n\n\n\n<p><strong><em>Implicit wait:<\/em><\/strong>An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0<\/p>\n\n\n\n<p><strong><em>Thread.sleep()<\/em><\/strong>In sleep code will always wait for mentioned seconds inside the parentheses even in case working page is ready after 1 sec. So, this can slow the tests.<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li><strong>Don\u2019t Use a Specific Driver<\/strong><br>\u2022 Using Parameter notes you can easily handle different browser types and prepare your test for cross-browser and parallel execution.<br>\u2022 Using JUnit, you have @RunWith(Parameterized.class) with @Parameters (browser).<br>\u2022 Using TestNG you have @Parameters(\u201cbrowser\u201d) with XML configuration.<\/li>\n\n\n\n<li><strong>Taking Screen Shots and Logs from HTML Sources<\/strong><br>\u2022 It will easily help the investigation in case something goes wrong. Basically, you have to create a kind of Watcher\/ Listener for your tests.<br>\u2022 In JUnit you can use @Rule.<br>\u2022 In TestNG you can use extends TestListenerAdapter and use a XML configuration &lt;listener&gt; and org.testng.Reporter.log<\/li>\n\n\n\n<li><strong>IE Not Working<\/strong><br>\u2022 The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.<br>\u2022 You must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings, choose \u201cInternet Options\u2026\u201d from the Tools menu, and click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled \u201cEnable Protected Mode\u201d.<\/li>\n\n\n\n<li><strong>Data Driven Testing<\/strong><br>\u2022 To use the same test with different inputs due to test a considerable variety of scenarios without code changing.<\/li>\n<\/ol>\n\n\n\n<p>Selenium is a powerful tool, which can be leveraged effectively by developers and testers. With its useful features, Selenium serves as a key tool for browser compatibility testing as well as system functional testing. Using Selenium helps clients leverage benefits of custom Selenium Test Automation frameworks.<\/p>\n\n\n\n<p>By leveraging proprietary test accelerators, clients can jump start test automation and reduce automation cycle-time. Selenium Test Automation Framework is a proven and tested framework having 90+ function libraries to directly jump start your test automation projects or complement your existing test automation suite. It is indeed strong when compared to other available tools for automation testing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Selenium automation is becoming the most sought after automated testing tool. I reviewed different websites that dedicate their entire content to Selenium. As I observed endless theoretical backgrounds, examples, explanations, installations, and code segments, the one thing that I wanted to dig deeper into was why more and more organizations are migrating to Selenium? In&hellip; <a class=\"more-link\" href=\"https:\/\/viewmyprojects.com\/winwirewp\/blog\/best-practices-implementing-selenium-automation\/\">Continue reading <span class=\"screen-reader-text\">Best Practices of Implementing Selenium Test Automation<\/span><\/a><\/p>\n","protected":false},"author":71,"featured_media":16699,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_eb_attr":"","_uag_custom_page_level_css":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-12101","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","entry"],"acf":[],"featured_image_src":"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Best-Practices-of-Implementing-Selenium-Test-Automation-graphic.webp","author_info":{"display_name":"Venkat","author_link":"https:\/\/viewmyprojects.com\/winwirewp\/author\/venkat\/"},"views":3674,"uagb_featured_image_src":{"full":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Best-Practices-of-Implementing-Selenium-Test-Automation-graphic.webp",800,440,false],"thumbnail":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Best-Practices-of-Implementing-Selenium-Test-Automation-graphic-150x150.webp",150,150,true],"medium":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Best-Practices-of-Implementing-Selenium-Test-Automation-graphic-300x165.webp",300,165,true],"medium_large":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Best-Practices-of-Implementing-Selenium-Test-Automation-graphic-768x422.webp",750,412,true],"large":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Best-Practices-of-Implementing-Selenium-Test-Automation-graphic.webp",750,413,false],"1536x1536":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Best-Practices-of-Implementing-Selenium-Test-Automation-graphic.webp",800,440,false],"2048x2048":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Best-Practices-of-Implementing-Selenium-Test-Automation-graphic.webp",800,440,false],"post-thumbnail":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Best-Practices-of-Implementing-Selenium-Test-Automation-graphic.webp",800,440,false]},"uagb_author_info":{"display_name":"Venkat","author_link":"https:\/\/viewmyprojects.com\/winwirewp\/author\/venkat\/"},"uagb_comment_info":0,"uagb_excerpt":"Selenium automation is becoming the most sought after automated testing tool. I reviewed different websites that dedicate their entire content to Selenium. As I observed endless theoretical backgrounds, examples, explanations, installations, and code segments, the one thing that I wanted to dig deeper into was why more and more organizations are migrating to Selenium? In&hellip;&hellip;","_links":{"self":[{"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/posts\/12101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/users\/71"}],"replies":[{"embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/comments?post=12101"}],"version-history":[{"count":2,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/posts\/12101\/revisions"}],"predecessor-version":[{"id":20109,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/posts\/12101\/revisions\/20109"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/media\/16699"}],"wp:attachment":[{"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/media?parent=12101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/categories?post=12101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/tags?post=12101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}