簡體   English   中英

"如何使用 Selenium Hub、Node 和 Remote Webdriver 捕獲圖像並將它們附加到 Cucumber Reports (Jenkins)?"

[英]How to capture images and attach them to Cucumber Reports (Jenkins) using Selenium Hub, Node and Remote Webdriver?

目前我正在使用 Ubuntu 實例在雲中觸發我的自動化測試。

Ubuntu 實例有一個 Jenkins 實例正在運行,還有 Selenium Hub 和 Node。 似乎截圖圖像沒有保存在 ubuntu 系統上的 builds\\3\\cucumber-html-reports\\embeddings 中,但是在 Windows 系統上這個問題不存在。

我目前添加了以下邏輯來捕獲圖像並將其附加到 Jenkins Cucumber 報告中,但是目前圖像沒有附加到報告中:

@After
public void after(Scenario scenario) {
    if (scenario.isFailed()) {
        try {
            WebDriver augmentedDriver = new Augmenter().augment(getDriver());
            byte[] s = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.BYTES);
            scenario.embed(s, "image/png");

示例報告(在 Jenkins 中生成),請注意,在本地運行測試時,圖像會被保存並附加到報告中。 在此處輸入圖像描述

如果這不起作用,那么你可以考慮以下方式附加屏幕截圖來報告詹金斯。

鈎子看起來如下 -

@After
    public void afterScenario(Scenario scenario){
        try{
            if(scenario.isFailed()){
                ExtentTestManager.addScreenShotsOnFailure();
    // More code goes here....       

捕獲圖像的方法 - 請根據您的需要自定義路徑。

public static void addScreenShotsOnFailure() {
    i = i + 1;
    File scrFile = ((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(OutputType.FILE);

    Date d = new Date();
    SimpleDateFormat formatter = new SimpleDateFormat("E dd MMM HH:mm:ss z yyyy");  
    String strDate = formatter.format(d);
    screenshotName = strDate.replace(":", "_").replace(" ", "_") + "_"+i+".jpg";

    try {
        FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir") + "/target/extent-report/" + screenshotName));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

我對ubuntu問題沒有直接的答案。 但是,嘗試將捕獲圖像的路徑添加到黃瓜報告中作為html鏈接。

@After
public void after(Scenario scenario){
   if (scenario.isFailed()) {
        try {
            WebDriver augmentedDriver = new Augmenter().augment(getDriver());
            File path = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);
            FileUtils.copyFile(path,new File(localRepoPath));
            String html = "<html><body><a href=\">" + localRepoPath + "\"> screenshot </a></body></html>";
            scenario.embed(html.getBytes(), "text/html");
       }catch(Exception e){
          // Do Something
       }
  }        
}

當我在本地看到報告時,我可以看到圖像,但是當我在團隊中共享時,報告沒有圖像。 我們如何添加圖像來報告跨團隊可以訪問它的位置。

"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM