From speed, quality to cost, Grid distributed parallel testing shows its advantages in web automation testing.

Table of contents

 Foreword:

1. Introduction to Grid distributed parallel testing

2. Advantages of Grid distributed parallel testing

3. Grid distributed parallel test architecture

4. Grid distributed parallel test package

V. Conclusion


Foreword:

WEB automated testing has become an integral part of the software development process. Testers write scripts to simulate various operations of users on the webpage to verify whether the functions of the webpage meet expectations. During the testing process, the following problems are often encountered: slow speed, synchronization problems, poor scalability, etc. The Grid distributed parallel test was born to solve these problems.

1. Introduction to Grid distributed parallel testing

Grid is an extensible tool that can distribute tests to multiple machines for execution, greatly improving the efficiency of web automation testing. The core concept of Grid is: centralized management, decentralized execution. It consists of a Hub and multiple Nodes. Testers only need to submit test requests to the Hub, and the Hub will distribute the tests to the connected Nodes for execution, and the Nodes will return the execution results to the Hub, and then the testers will count the results for processing.

2. Advantages of Grid distributed parallel testing

1. Improve test efficiency: perform parallel tests on multiple machines at the same time, making the test process faster and more effective, and effectively shortening the test time.
2. Improve test quality: find bugs faster and improve test coverage.
3. Save test cost: save test time, and also save time and cost of testers.

3. Grid distributed parallel test architecture

Grid adopts the Hub-Node structure, and testers need to implement two roles in the Grid framework: Hub and Node.
1.Hub: Grid's central control center, manages the distribution of test requests, results collection and other operations. Testers run Hub on localhost.
2.Node: Run on a remote machine, receive and execute assigned test requests. Testers need to run Node on each remote machine.

4. Grid distributed parallel test package

Encapsulating Grid distributed parallel testing requires technologies such as Selenium WebDriver, TestNG, and Java. Let's package it step by step.

1. Create a Java Maven project and add the following dependencies:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.6.0</version>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-server</artifactId>
    <version>3.6.0</version>
</dependency>
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.11</version>
    <scope>test</scope>
</dependency>

2. Create a Grid wrapper class:

public class GridManager {
    private static final String HUB_URL = "http://localhost:4444/wd/hub";
    private static WebDriver driver;

    public static WebDriver getDriver() {
        if (driver == null) {
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            try {
                driver = new RemoteWebDriver(new URL(HUB_URL), capabilities)
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        }
        return driver;
    }

    public static void stopDriver() {
        if (driver != null) {
            driver.quit();
            driver = null;
        }
    }
}

3. Create a Grid test base class:

public class GridBaseTest {
    protected WebDriver driver;

    @BeforeClass
    public void beforeTest() {
        driver = GridManager.getDriver();
    }

    @AfterClass
    public void afterTest() {
        GridManager.stopDriver();
    }
}

4. Create a TestNG test case and inherit GridBaseTest:

public class Test extends GridBaseTest {
    @Test
    public void test() {
        driver.get("https://www.baidu.com/");
        String title = driver.getTitle();
        Assert.assertEquals(title, "百度一下,你就知道");
    }
}

V. Conclusion

Such a simple Grid distributed parallel testing framework is successfully encapsulated. In fact, in actual development, it is not necessary to start Grid according to this example. We can choose more flexible ways, such as using Docker container technology, or integrating Grid into Jenkins for automated testing. But no matter which method is used, using Grid can greatly improve the efficiency, quality and cost saving of web automation testing, and is more suitable for the testing needs of large-scale and complex web applications.

In short, Grid distributed parallel testing is a disruptive technology for web automation testing. Through its management and execution operations, web applications can be quickly tested, which can be very helpful for our application in a tight time Extensive testing is done to ensure that they end up with great functionality and high quality.

The full source code can be viewed in my GitHub repository: https://github.com/yourgithubname.

The application of Grid automated testing is far more than that. Here we only introduce the basic content of the Grid distributed parallel testing framework. If you are interested, you can continue to learn more about it, so as to further improve your automated testing capabilities.

 As someone who has been here, I also hope that you will avoid some detours. Here I will share with you some necessities on the way forward for automated testing. If you can use it, you can take it directly. I hope it can help you. (WEB automated testing, app automated testing, interface automated testing, continuous integration, automated test development, big factory interview questions, resume templates, etc.), I believe it can make you better progress!

How to get it: Leave a message [Automated Test]
[Automated Test Communication]: 574737577 (remark ccc) icon-default.png?t=N4P3http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=KGneGfxysgywFs526vp9KY9AkOCU8EFn&authKey=c1oehqFQuTnz4BW02Ys0HG%2BOkFu% 2BuKDUpSux9C01Dnrn5kF44vI %2FzZ3UsLbndHjg&noverify=0&group_code=574737577

 

Guess you like

Origin blog.csdn.net/Free355/article/details/130929679