【问题标题】:Can I use Selenium Grid to test multiple machines and website but same browser我可以使用 Selenium Grid 测试多台机器和网站但使用相同的浏览器吗
【发布时间】:2015-09-04 03:42:00
【问题描述】:

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

【问题讨论】:

  • 这是真实的用户行为吗?

标签: selenium-grid


【解决方案1】:

是的,您可以使用 Grid 来完成。我会给你一个简单的例子。创建两个testng类并在testng.xml中设置类

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

公共类测试{

      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();
         }

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

如果您想并行运行它们,只需将 parallel="tests" 放入您的 testng.xml 中

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

希望对你有帮助:)

【讨论】:

  • 发生了什么。这不适合你吗?你可以告诉我,如果有的话我可以纠正自己
  • 哎呀对不起点击错误我只想复制“公共类测试{...”\
猜你喜欢
  • 1970-01-01
  • 2011-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-19
  • 2015-10-26
  • 1970-01-01
  • 2018-03-06
相关资源
最近更新 更多