2016-08-22 36 views
-3

我想通過註冊運行Selenium Grid來自VirtualBox的節點。每當我嘗試執行testng.xml並行運行測試,我得到以下錯誤:失敗的配置:@BeforeTest beforeTest如何解決這個問題。
我確定所有必需的jar文件都被添加了。 Selenium集線器正在運行,節點也被註冊到集線器。@BeforeTest beforeTest(「WIN8」,「firefox」,「http://10.xxx:4467/wd/hub」)java.net.MalformedURLException:無協議:remoteurl

package com.example.selenium; 

    import org.testng.annotations.Test; 

    import java.net.MalformedURLException; 
    import java.net.URL; 
    import java.util.concurrent.TimeUnit; 

    import org.openqa.selenium.By; 
    import org.openqa.selenium.Platform; 
    import org.openqa.selenium.remote.DesiredCapabilities; 
    import org.openqa.selenium.remote.RemoteWebDriver; 
    import org.testng.annotations.BeforeTest; 
    import org.testng.annotations.Parameters; 

    public class ParllelTest { 
//RemoteWebDriverInstance 
     static RemoteWebDriver driver; 
    //Checking the type of browser and platform registered 

     @BeforeTest (alwaysRun=true) 
     @Parameters({"platform","browserName","remoteurl"}) 
     public void beforeTest(String platform,String browserName,String remoteurl) throws MalformedURLException { 

     DesiredCapabilities cap = null; 


      if(browserName.equals("firefox")) { 

       cap=new DesiredCapabilities().firefox(); 
      cap.setPlatform(Platform.VISTA); 
      cap.setBrowserName("firefox"); 
      } 

      else if(browserName.equals("chrome")) 
      { 
       cap=new DesiredCapabilities().chrome(); 
       cap.setBrowserName("chrome"); 
       cap.setPlatform(Platform.LINUX); 
      } 


      driver=new RemoteWebDriver(new URL("remoteurl"),cap); 
     } 
//navigating to particular page 
     @Test 
     public void googlesearch() 
     { 


      driver.get("http://www.gmail.com"); 
      driver.findElement(By.name("username")).sendKeys("xxxxx"); 
      driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); 
      driver.findElement(By.name("password")).sendKeys("xxxxx"); 
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
      driver.findElement(By.id("click")).click(); 
     } 
    } 

Iam粘貼相應的xml文件,從iam試圖並行運行測試。

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> 
<suite name="TestSuite" thread-count="4" parallel="tests" > 
<test verbose="3" name="Vista"> 
<paramaters> 
    <parameter name="platform" value="VISTA"/> 
    <parameter name="browserName" value="firefox"/> 
    <parameter name="remoteurl" value="http://10.x.x.x:5557/wd/hub"/> 
</paramaters> 
<classes> 
    <class name="com.example.selenium.ParllelTest"> 
    <method> 
     <include name="googlesearch"/> 
     </method> 
    </class> 
</classes> 
</test> 
<test verbose="3" name="ubuntu"> 
<paramaters> 
    <parameter name="platform" value="WIN8"/> 
    <parameter name="browserName" value="firefox"/> 
    <parameter name="remoteurl" value="http://10.x.x.x:4467/wd/hub"/> 
</paramaters> 
<classes> 
    <class name="com.example.selenium.ParllelTest"> 
     <method> 
     <include name="googlesearch"/> 
     </method> 
    </class> 
</classes> 
</test> 

</suite> 
+0

你在用@BeforeTest註釋的方法中有什麼? –

+0

Iam粘貼在我的問題代碼 –

+0

請不要downvaote IAM絕對初學者硒。Iam真的卡住在這裏很長一段時間需要幫助。 –

回答

0

java.net.MalformedURLException: no protocol: remoteurl

driver=new RemoteWebDriver(new URL("remoteurl"),cap); 

縱觀例外,這條線,看起來像你的參數remoteurl不獲取解碼,它的價值,即http://10.x.x.x:4467/wd/hub。而是越來越通過作爲「remoteurl」字符串,顯然不能被解析成url。

只是爲了證實這一點,儘量把remoteurl的值在上面的代碼行:

driver=new RemoteWebDriver(new URL("http://10.x.x.x:4467/wd/hub"), cap) 

它肯定會工作的話,那就是爲什麼remoteurl被作爲字符串而不是通過一個問題變量,如果上述線路正常,然後再嘗試通過remoteurl不帶引號如下:

driver=new RemoteWebDriver(new URL(remoteurl), cap) 

雖然我不是100%地肯定了remoteurl或「remoteurl」但讓我們嘗試。對於第一點,我100%確定新的URL正在接收「remoteurl」而不是「http://10.x.x.x:4467/wd/hub」。

+0

謝謝。但使用「http://10.xxx:4467/wd/hub」可以在單機上執行,但我想在兩臺機器上並行執行測試:「http://10.xxx:4467/wd/hub「和」http://10.xxx:5557/wd/hub「 –

相關問題