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

核能气质少年 提交于 2019-12-12 05:39:15

问题


I have to test multiple machine and each machine have to test different website with same browser. In this case can I use Selenium Grid? If I can't, are there any way to do that?


回答1:


Yes you can do it using Grid. I am going to give you a simple example. Create two class of testng and and set the class in testng.xml

Now use code in both classes as below:-

public class Testing {

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

Now configure different site in both classes, set there ips and provide there port as you had set in your other salve machines.

If you want to run them parallel then simply put parallel="tests" in your testng.xml

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

I Hope it will help you :)



来源:https://stackoverflow.com/questions/32389706/can-i-use-selenium-grid-to-test-multiple-machines-and-website-but-same-browser

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!