2017-09-26 6 views
0

私は魅力レポートを使用しています。私のレポートは正しく生成されますが、私はスクリーンショットとコンソール出力はレポートに添付されません。ここでコンソール出力に、report-selenium webdriver、testng、mavenに添付されたスクリーンショットを取得します。

は私のpom.xmlです:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.testproject</groupId> 
    <artifactId>tests</artifactId> 
    <version>0.1-SNAPSHOT</version> 
    <properties> 
     <aspectj.version>1.8.10</aspectj.version> 
    </properties> 
    <dependencies> 
     <dependency> 
      <groupId>io.qameta.allure</groupId> 
      <artifactId>allure-testng</artifactId> 
      <version>2.0-BETA14</version> 
      <scope>test</scope> 
     </dependency> 

     <dependency> 
      <groupId>org.testng</groupId> 
      <artifactId>testng</artifactId> 
      <version>6.11</version> 
      <scope>test</scope> 
     </dependency> 

     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-java</artifactId> 
      <version>3.4.0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-server</artifactId> 
      <version>3.4.0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.poi</groupId> 
      <artifactId>poi</artifactId> 
      <version>3.16</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.poi</groupId> 
      <artifactId>poi-ooxml</artifactId> 
      <version>3.16</version> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.5.1</version> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.20</version> 
       <configuration> 
        <argLine> 
         -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar" 
        </argLine> 
        <suiteXmlFiles> 
         <suiteXmlFile>testng.xml</suiteXmlFile> 
        </suiteXmlFiles> 
       </configuration> 
       <dependencies> 
        <dependency> 
         <groupId>org.aspectj</groupId> 
         <artifactId>aspectjweaver</artifactId> 
         <version>${aspectj.version}</version> 
        </dependency> 
       </dependencies> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

それが壊れてテストを実行するのにかかる時間/ステータス合格/不合格を示しallure report の添付のスクリーンショットをご覧ください。しかし、コンソールの出力はそれに接続されていません。失敗したテストケースのスクリーンショットも、フォルダsurefire-reports/screenshotsに保存されています。私はそれらを添付してレポートを魅力的にする必要があります。誰かがこの出力を得るために追加する必要があることを知ってもらえますか?

ありがとうございます!

+0

あなたが行ったことについて質問に十分な詳細を追加しない場合(経験している問題をシミュレートするためにおそらく他人によって実行される可能性があるコードスニペットを共有する必要があります)、あなたが期待していることは、あなたの質問が閉鎖される可能性が非常に高いことです。文脈の詳細であなたの質問を充実させてください。 –

答えて

0

TestNGリスナーを使用して失敗したスクリーンショットを取得しており、testNGリスナーにアクセスできることを前提としています。それ以外の場合は、TestListenerAdapterをオーバーライドしてTestNGリスナー(http://testng.org/doc/documentation-main.html#listeners-testng-xml)を作成する方法を参照してください。

  1. あなたが、テストの失敗でスクリーンショットを撮るために使用されるあなたのTestNGのリスナーに、このメソッドを呼び出すことができますスクリーンショット

    @Attachment(value = "Page screenshot", type = "image/png") 
    public byte[] saveScreenshot() { 
        // Use selenium screenshot code to take screenshot and convert into  byte[] 
        return byte[]; 
    } 
    

    を保存するために、次のようなメソッドを作成することができそうです。コンソール出力を報告して取得するための

    @Override 
    public void onTestFailure(ITestResult testResult) { 
        saveScreenshot(); 
        super.onTestFailure(testResult); 
    } 
    
  2. 、次のメソッドを作成

    @Attachment 
    public String logOutput(List<String> outputList) { 
        String output = ""; 
        for (String o : outputList) 
         output += o + "<br/>"; 
        return output 
    } 
    

    TestNGの方法onTest(成功、失敗、スキップ)とonConfiguration(成功、失敗、スキップ)を呼び出しリスナー

    @Override 
    public void onTestSuccess(ITestResult testResult) { 
        // Reporter.getOutput(testResult)will give the output logged in testng reporter 
        logOutput(Reporter.getOutput(testResult)); 
        super.onTestSuccess(testResult); 
    } 
    

https://github.com/allure-framework/allure1/wiki/Attachments

関連する問題