Senior old bird summary, Selenium automated testing practical tips, don't take detours...


foreword

Selenium4 automated testing: https://www.bilibili.com/video/BV1MS4y1W79K/

The web automation testing framework architecture commonly used by enterprises now:
Python+selenium4+pytest+POM+allure+Jenkins;

Unlike the previous waterfall development model, software testers now have the advantage of using automation tools to execute test case suites, while previously, testers were used to completing tests through test script execution.

But the purpose of automated testing is not to get rid of manual testing completely, but to minimize the number of tests that are run manually. Automated testing enables rapid testing of multilingual sites and also increases test execution speed.

Selenium Automation
Open source tools and applications are becoming increasingly important due to their cost-effectiveness, efficiency, repeatability, accuracy and ease of use. Selenium is one of the open source tools which offers all the advantages of open source tools in terms of application testing.

Selenium in Cross Browser Testing
As the name suggests, cross browser testing is a method used to test a web application on different web browsers and devices to ensure that it runs seamlessly on each device and browser.

Selenium automated testing tips

1. Utilize the right locator
The bottom of the Selenium framework is to interact with the browser, allowing multiple objects to be inspected, entered and browsed using the Document Object Model (DOM). This happens through a set of operations and uses several locators including CSS selectors, name, XPath, ID, tagname, link text and classname.

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

2. Data-driven testing
If you want to use the same test and the same code for different inputs, you can rely on Selenium. It will allow developers and QA teams to make modifications, which means it can be used for system functional testing as well as browser compatibility testing.

Selenium also allows clients to benefit from its framework. Customers can leverage a proprietary test accelerator and initiate test automation. This will reduce the automation cycle time. There are a number of libraries that allow clients to initiate automated processes.

3. Don't depend on a specific driver
Never depend on a specific driver implementation. Understand that drivers are not instantaneous across browsers. That is, there may not necessarily be an IE driver, a FireFox driver, etc.

For example, a RemoteDriver is received when performing integration tests during a continuous Linux build. Small frameworks can be quickly created in Selenium using LabeledParameterized (JUnit has @RunWith and TestNG has @Parameters).

and ScreenShotWatchMan(JUnit @Rule, TestNG TestListenerAdapter). In other words, it's good to use parameter annotations to handle multiple browser types and be ready to execute concurrently.

4. Selector order
The order in which selectors are selected is important because selectors (such as XPath and CSS) are position-based. They are slower compared to ID, name and link text. name and ID are particularly straightforward and direct way selectors. CSS is usually a combination of ID and Name. In contrast, XPath should be the solution of last resort.

A robust solution looks like this: XPath <CSS <Links Text <Name <ID. That means starting with the ID and making the XPath the last selector. Of the 3 tables with no data, XPath recognizes the second table the slowest, and may not return the correct table. So in the end XPaths were chosen, they are fragile. CSS is always combined with names and IDs.

5. Use the PageObjects design pattern
PageObject has gained popularity as the best design pattern in test automation. It improves test maintainability and reduces code duplication. Also, it is an object-oriented class that acts as an interface to the application page under test. For simplicity, PageObject is an object-oriented design pattern and defines a web page as a class. Different elements on the page will become variables. User interaction is implemented using concrete methods.

Web page = category;
various elements on the page = variables;
user interaction = method;

Advantages of PageObject
It helps to have a robust framework with minor UI tweaks. Test code and page code are separate. They are reliable and easy to maintain. The script is readable. The code is reusable. Duplication is almost completely eliminated.

6. Advocate wait to avoid sleep
and use wait instead of sleep. Learn about explicit and implicit waits, and Thread.sleep() logic. Then, why wait and not sleep.

wait
explicit – wait for something to happen without continuing to write code.
Implicit – instructs WebDriver to poll the DOM until it finishes searching for an element. By default, time is set to 0.

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

7. Close the Firebug start page.
When starting the firefox driver, firebug may already be included. Sometimes this can cause things to not work properly. If it bothers you to start your browser with a new firebug tab open at the same time, follow one of the tips provided below to close the firebug start page.

Set False in the showFirstRunPage flag, as follows:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("extensions.firebug.showFirstRunPage", false);

The following is the most complete software test engineer learning knowledge architecture system diagram in 2023 that I compiled

1. From entry to mastery of Python programming

Please add a picture description

2. Interface automation project actual combat

Please add a picture description

3. Actual Combat of Web Automation Project

Please add a picture description

4. Actual Combat of App Automation Project

Please add a picture description

5. Resume of first-tier manufacturers

Please add a picture description

6. Test and develop DevOps system

Please add a picture description

7. Commonly used automated testing tools

Please add a picture description

Eight, JMeter performance test

Please add a picture description

9. Summary (little surprise at the end)

As long as you have a dream in your heart, don't stop pursuing it; as long as you work hard, there will be no difficulties you can't overcome; as long as you keep a firm belief, you will be able to create your own brilliant life.

Only by going forward bravely can we usher in a better tomorrow on the road of life. Every step is an opportunity to hone yourself, don't be afraid of failure, because success is the next step you keep trying. Let passion drive your dreams, keep working hard, and look forward to the brilliant future!

Every day is an opportunity, don't waste it. Remain persistent and courageous even when you encounter difficulties. Believe in your own potential and never give up your desire to pursue a better life. Only by working hard can we realize our dreams!

Guess you like

Origin blog.csdn.net/m0_70102063/article/details/130769377