我可以使用 Selenium Grid 测试多台机器和网站但使用相同的浏览器吗

Can I use Selenium Grid to test multiple machines and website but same browser

我必须测试多台机器,每台机器都必须使用相同的浏览器测试不同的网站。在这种情况下我可以使用 Selenium Grid 吗? 如果我做不到,有什么办法吗?

是的,您可以使用网格来完成。我将给你一个简单的例子。创建两个 class 的 testng and 并在 testng.xml

中设置 class

现在在两个 classes 中使用代码如下:-

public class 测试 {

      public static try1 {
         try{

          String baseUrl="https://www.google.com/";        // url on which we have to test
          String nodeurl="http://192.168.10.30:5555/wd/hub";  // ip and port of node remote machine 2 we are using as node for testing. 
        System.setProperty("webdriver.chrome.driver","C:/robot/chromedriver.exe");


            // the below line have chrome capability then explorer works dont change it to explorer it doesn't work
        WebDriver driver = new RemoteWebDriver(new URL(nodeurl), DesiredCapabilities.chrome()); 
        driver.get(baseUrl);


        WebElement element = driver.findElement(By.name("q"));
        element.sendKeys("BrowserStack");
        element.submit();

        System.out.println(driver.getTitle());
        driver.quit();
         }

现在在两个 classes 中配置不同的站点,在那里设置 ips 并提供端口,就像您在其他 salve 机器上设置的那样。

如果你想 运行 它们并联,那么只需将 parallel="tests" 放入你的 testng.xml

<suite name="Test-class Suite" parallel="tests" thread-count="2">  

希望对您有所帮助:)