Unlike the previous waterfall development model, software testers now have the advantage of using automated tools to execute test case suites, which testers were accustomed to doing through test script execution.

But the goal of automated testing is not to get rid of manual testing altogether, but to minimize the number of manually run tests. Automated testing enables you to quickly test multilingual sites and can also speed up test execution.

The process for automating tests is simple, see The Automated Test Life Cycle.

The Selenium automation

Open source tools and applications are becoming increasingly important because of their cost-effectiveness, efficiency, repeatability, accuracy and ease of use. Selenium is one of the open source tools that provides all the benefits of open source tools for application testing.

Selenium is a set of Selenium tools for testing. It contains Selenium IDE, Selenium RC, Selenium Webdriver and Selenium Grid. It is used to automate Web interaction and regression testing and has record and playback capabilities. You can also export recorded scripts to other languages, including Java, C#, Python, Ruby, Javascript, and PHP.

Selenium in cross-browser testing

As the name suggests, cross-browser testing is a way to test a Web application on different Web browsers and devices to ensure that it works seamlessly on each device and browser.

Selenium helps automate test cases in Safari, Google Chrome, Mozilla Firefox, and Internet Explorer. Selenium can also execute test cases simultaneously on the same computer on different browsers. It also supports multiple languages and operating systems. Reference article: How can I be more efficient in Cross-browser testing

Let’s take a look at Selenium best practices to take advantage of during automated testing.

Use the right locator

At the bottom of the Selenium framework is interaction with a browser that allows you to examine, enter, and browse multiple objects using the document object Model (DOM). This happens through a set of operations and uses multiple locators, including CSS selectors, name, Xpath, ID, tag names, link text, and className.

For example, use Class and ID locators when you don’t want to change code without developers and testers knowing. On the other hand, link text can be used to handle situations dynamically when other teams are testing. Finally, XPath can be used for positioning.

Data-driven testing

If you want to use the same tests and the same code for different inputs, you can rely on Selenium. It will allow developers and quality control teams to make modifications, which means you can use it for system functional testing as well as browser compatibility testing.

Selenium also allows customers to benefit from its framework. Customers can leverage proprietary test accelerators and initiate test automation. This will reduce automation cycle time. There are many libraries that allow clients to initiate automated processes.

Do not rely on specific drivers

Never rely on a specific driver implementation. Understand that drivers are not instantaneous across browsers. That is, there won’t necessarily be IE drivers, FireFox drivers, etc.

For example, when you perform integration tests during a continuous Linux build, you receive RemoteDriver. You can quickly create small frameworks in Selenium using LabelledParameterized (JUnit has @runwith and TestNG @Parameters).

And ScreenShotWatchMan (junit@rule, TestNG TestListenerAdapter). In other words, it’s a good idea to use parameter annotations to handle multiple browser types and be ready to execute them simultaneously.

Selector order

The order in which you select selectors is important because selectors (such as XPath and CSS) are location-based. They are slow compared to ID, name, and link text. Name and ID are particularly direct and straightforward mode selectors. CSS is usually a combination of ID and Name. XPath, by contrast, should be the solution of last resort.

A robust solution is as follows: XPath

usePageObjectsDesign patterns

PageObject has gained popularity as the best design pattern in test automation. It improves the maintainability of tests and reduces code duplication. In addition, it is an object-oriented class that acts as an interface to the page of the application under test. For simplicity, PageObject is an object-oriented design pattern and defines web pages as classes. Different elements on the page will become variables. User interactions are implemented in concrete ways.

  • Page = category

  • Various elements on the page = variables

  • User interaction = method

  • The advantages of the PageObject

  • With minor UI tweaks, it helps build a robust framework. The test code is separate from the page code.

  • They are reliable and easy to maintain.

  • The script is readable. This code is reusable.

  • Almost complete elimination of duplication.

advocatewaitavoidsleep

Use ‘wait’ instead of sleep. Learn about explicit and implicit waits, and thread.sleep () logic. Then, why wait instead of sleep?

  • wait

Explicit – Waiting for something to happen without having to continue writing code.

Implicit – instructs WebDriver to poll the DOM until the element is searched. By default, the time is set to 0.

  • sleep

Thread.sleep() waits for the number of seconds specified in parentheses, regardless of whether the working page is ready.

Close the Firebug start page

Firebug may be included when you start the Firefox driver. Sometimes this can cause it to not work properly. If it bothers you to have a new Firebug TAB open when you start your browser, follow one of the tips provided below to close the Firebug start page.

  • inshowFirstRunPageMarks will beFalseSettings, as follows.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("extensions.firebug.showFirstRunPage".false);
Copy the code

Reference article:

  • Selenium 4.0 Alpha update log
  • Selenium 4.0 Alpha update practices
  • JUnit 5 and Selenium Basics
  • JUnit 5 and Selenium Basics (ii)
  • JUnit 5 and Selenium Basics (3)
  • Selenium Python Use Tips (1)
  • Selenium Python Use Tips (2)
  • Selenium Python Use tips (3)
  • Selenium Parallel Testing basics
  • Selenium parallel testing best practices

  • The public,FunTesterFirst, welcome attention, prohibit the third party to reprint without authorization. For cooperation, please contact[email protected].