博学而笃定,切问而近思

selenium grid2实例化测试

上一篇 / 下一篇  2015-08-11 16:25:06 / 个人分类:Selenium

@Test
    public void test01() throws MalformedURLException, InterruptedException{
        String hubURL = "http://192.168.1.112:4444/wd/hub";
        
        DesiredCapabilities aDesiredCap = new DesiredCapabilities();
        aDesiredCap.setBrowserName("firefox");
        aDesiredCap.setVersion("");
        aDesiredCap.setPlatform(Platform.WINDOWS);
       
        //wd = new FirefoxDriver();
        wd = new RemoteWebDriver(new URL(hubURL),aDesiredCap);
       
   
        //wd = new RemoteWebDriver(aDesiredCap);
        wd.get("http://www.baidu.com");

        Thread.sleep(1000);
        System.out.println(wd.getCurrentUrl());
        wd.quit();
       
        System.out.println("test01");
       
    }
   
   
   
    @Test
    public void test02() throws MalformedURLException, InterruptedException{
        System.out.println("Test Case: "+ Thread.currentThread().getStackTrace()[1].getMethodName()+" *************");
        File file = new File("C:/Program Files (x86)/Internet Explorer/IEDriverServer.exe");
        System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
        String hubURL = "http://192.168.1.112:4444/wd/hub";
        DesiredCapabilities aDesiredCap = new DesiredCapabilities();
       
        aDesiredCap.setBrowserName("internet explorer");
        aDesiredCap.setVersion("");
        aDesiredCap.setPlatform(Platform.WINDOWS);
        aDesiredCap.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
        //wd = new InternetExplorerDriver();
       
        wd = new RemoteWebDriver(new URL(hubURL),aDesiredCap);
   
   
        wd.get("http://www.qq.com");

        Thread.sleep(3000);
        System.out.println(wd.getCurrentUrl());
        wd.quit();
       
    }
   
    @Test
    public void test03() throws InterruptedException, IOException{
        System.out.println("Test Case: "+ Thread.currentThread().getStackTrace()[1].getMethodName()+" *************");
        File file = new File("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromeDriver.exe");
        System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());

       
        String hubURL = "http://192.168.1.112:4444/wd/hub";
        DesiredCapabilities aDesiredCap = new DesiredCapabilities();
       
        aDesiredCap.setBrowserName("chrome");
        aDesiredCap.setVersion("");
        aDesiredCap.setPlatform(Platform.WINDOWS);
         
         ChromeDriverService service = new ChromeDriverService.Builder().usingDriverExecutable(new File("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromeDriver.exe")).usingAnyFreePort().build();
         service.start();
         
         //wd = new ChromeDriver();
         wd = new RemoteWebDriver(new URL(hubURL),aDesiredCap);
         wd.get("http://mail.163.com");

         Thread.sleep(3000);
         System.out.println(wd.getCurrentUrl());
         wd.quit();
        // 关闭 ChromeDriver 接口
        service.stop();

    }
    
在启动假设hub和 2个 node,
运行test02,是将test02随机分配到任意符合条件的node中,只运行一次。同理test01也是

至于test03, 目前总有the path to webdriver.chrome.driver错误,
已经将chromedriver.exe放入环境变量中
也尝试rem java -Dwebdriver.chrome.driver="C:\Program Files (x86)\Google\Chrome\Application\chromeDriver.exe" -jar E:\maven\repo\org\seleniumhq\selenium\selenium-server-standalone-2.42.2.jar  -timeout 20000 -browser "browserName=chrome,version=31,maxInstances=2,platform=WINDOWS,chrome.binary=C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",还是不行。需要后续解决


TAG:

 

评分:0

我来说两句

Open Toolbar