2017-08-02 97 views
1

我正在嘗試使用testng.xml ...並且看起來像設備農場忽略了整個文件。Testng XML未被AWS設備農場接受

我的例子很簡單。我有一個工廠類,實例化測試類,這是我的xml文件看起來像

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> 
<suite name="Default Suite"> 
    <test name="test"> 
     <classes> 
      <class name="Factory"/> 
     </classes> 
    </test> 
</suite> 

我甚至試圖排除方法手動

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> 
<suite name="Default Suite"> 
    <test name="test"> 
     <classes> 
      <class name="Factory"/> 
      <class name="TestSingleUrl"> 
        <methods> 
         <exclude name="testCorrectSiteKey"/> 
         <exclude name="testIsTagImplemented"/> 
         <exclude name="testHttpsScheme"/> 
         <exclude name="testCorrectTagName"/> 
         <exclude name="testCorrectBootstrapPath"/> 
        </methods> 
      </class> 
     </classes> 
    </test> 
</suite> 

但我發現了一個「無法調用方法:使其成爲靜態或創建非參數構造函數「。這意味着設備場正在嘗試運行TestSingleUrl類中的方法..但是呼叫這些測試的人應該是工廠

有誰知道我們如何讓設備場接受我們的xml文件?

這是我的工廠類:

public class Factory{ 

    private String targetSiteKey; 

    //Data Provider that consumes the first line, which contains the target sitekey of the tag 
    @DataProvider(name = "urlProvider") 
    public Iterator<Object[]> createData() throws IOException { 
     List<String> lines = IOUtils.readLines(new InputStreamReader(this.getClass().getResourceAsStream("Urls.csv"))); 
     List<Object[]> objectArrays = lines.stream().map(x -> new Object[]{x}).collect(Collectors.toList()); 

     Iterator<Object[]> itr = objectArrays.iterator(); 
     targetSiteKey = itr.next()[0].toString(); 

     return itr; 
    } 

    @Factory(dataProvider="urlProvider") 
    public Object[] creatingTests(String url){ 
     System.out.println(System.currentTimeMillis()); 
     String siteKey=null; 
     String path = null; 
     String tagName = null; 
     WebElement browsi; 
     try{ 
      RemoteWebDriver driver = DriverWrapper.getDriver(); 
      driver.get(url); 
      browsi = driver.findElement(By.id("browsi-tag")); 

      tagName = browsi.getTagName(); 
      siteKey = browsi.getAttribute("data-sitekey"); 
      path = browsi.getAttribute("src"); 

     }catch(Exception ignored){} 
     finally{ 
      return new Object[] {new TestSingleUrl(targetSiteKey,siteKey,path,tagName,url)}; 
     } 
    } 
} 

這是我TestSingleUrl類:

public class TestSingleUrl { 
    private String targetSiteKey,siteKey,path,tagName,url; 

    public TestSingleUrl(String targetSiteKey,String siteKey, String path, String tagName,String url){ 
     this.targetSiteKey = targetSiteKey; 
     this.siteKey=siteKey; 
     this.path=path; 
     this.tagName=tagName; 
     this.url=url; 
    } 

    @Test 
    public void testCorrectSiteKey(){ 
     System.out.println(url); 
     Assert.assertEquals(siteKey, targetSiteKey); 
    } 

    @Test 
    public void testIsTagImplemented(){ 
     System.out.println(url); 
     Assert.assertFalse(siteKey.isEmpty()); 
     Assert.assertFalse(tagName.isEmpty()); 
     Assert.assertFalse(path.isEmpty()); 
    } 

    @Test 
    public void testHttpsScheme(){ 
     System.out.println(url); 
     Assert.assertTrue(path.contains("https")); 
    } 

    @Test 
    public void testCorrectTagName(){ 
     System.out.println(url); 
     Assert.assertEquals(tagName,"script"); 
    } 

    @Test 
    public void testCorrectBootstrapPath(){ 
     System.out.println(url); 
     Assert.assertTrue(path.contains("middycdn-a.akamaihd.net/bootstrap/bootstrap.js")); 
    } 
} 

我覺得我得到的錯誤信息是由於設備農場試圖運行每個方法都有一個它發現的@Test註釋。如果它正在讀我的xml文件,它不會發生。

RocketRaccoon

+0

你能分享生產和TestSingleUrl?看起來你錯誤地實現了Factory模式。 – RocketRaccoon

+0

嘿@RocketRaccoon,我只是把類。我不認爲是在我的類錯誤..因爲我可以在本地設備運行它..問題是當我把它發送到設備農場。 –

+0

你在那裏執行它? – RocketRaccoon

回答

0

我不知道確切,但我相信你應該能夠放置的testng.xml在資源目錄,並從pom.xml中引用它。

貌似這篇文章介紹如何從pom.xml中引用的testng.xml: How to call testng.xml file from pom.xml in Maven

當您生成項目,然後它會被包含在瓶子裏。

的awslabs項目通過使用該MVN命令構建它

MVN清潔套裝-DskipTests =真

https://github.com/awslabs/aws-device-farm-appium-tests-for-sample-app

[更新] 我從awslabs下載的示例項目並將其導入蝕。 我加入這個插件到pom.xml文件:

<plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.12.4</version> 
      <configuration> 
       <suiteXmlFiles> 
       <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile> 
       </suiteXmlFiles> 
      </configuration> 
     </plugin>  

我然後創建的testng.xml在./src/test/resources/

我複製並粘貼XML此處提供:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> 
<suite name="Default Suite"> 
    <test name="test"> 
     <classes> 
      <class name="Factory"/> 
     </classes> 
    </test> 
</suite> 

我然後建立該項目使用

mvn clean package -DskipTests=true 

這產生目標目錄中的zip-with-dependencies.zip文件。

我通過創建一個新項目並選擇Appium Java Testng作爲我想運行的測試類型,將此測試包上傳到設備場。

我遇到這個語法錯誤:

Failed to generate the test suites[TestNG] [ERROR] Cannot find class in classpath: Factory 

,因爲我沒有在我的類路徑類,這是預期,然而,這證明了設備農場沒有閱讀的testng.xml。

[更新]

我能夠重現問題時,我用排除標籤中的testng.xml。 I.E當我使用這個XML時:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> 
<suite name="Default Suite"> 
    <test name="test"> 
     <classes> 
      <class name="factory.TestSingleUrl"> 
       <methods> 
        <exclude name="testCorrectSiteKey" /> 
        <exclude name="testIsTagImplemented" /> 
        <exclude name="testHttpsScheme" /> 
        <exclude name="testCorrectTagName" /> 
        <exclude name="testCorrectBootstrapPath" /> 
       </methods> 
      </class> 
     </classes> 
    </test> 
</suite> 

要進一步調查方法標籤。

[更新]

看起來這是在設備農場的已知問題: AWS Device farm seems to be ignoring TestNG annotations

想我們只需要等待他們更新的環境和解析器。

您可能可以在私有設備上運行測試。你將需要聯繫AWS獲得一個在此電子郵件:

[email protected]

[更新]

看起來他們已經更新了webDriverAgent。看看它現在是否有效。

希望有所幫助。

問候

詹姆斯

+0

我使它在本地設備上工作。問題是,當我將它發送到AWS Device Farm時,他們不尊重testng.xml文件。 –

+0

設備場是否爲您提供可以共享的任何分析結果或錯誤消息? – jmp

+0

他們給我的錯誤信息是「無法調用方法:使其成爲靜態或創建非參數構造函數」。那是因爲他們試圖從TestSingleUrl類運行Test方法,但是他們的構造函數有參數,因爲是實例化它們的工廠。所以這就是爲什麼我暗示他們忽略了xml文件 –

相關問題