【问题标题】:Get JUNIT result from a test to post its result in testrail从测试中获取 JUNIT 结果以将其结果发布到 testrail
【发布时间】:2019-02-09 13:17:04
【问题描述】:

我对所有这些编码经验都很陌生。我已经做了几年的手动 QA,现在我开始接触 selenium

我已经制定了一个非常简单的测试用例来提交注册表,我想获得该测试用例的结果并将其发布到我的测试工具“Test Rail”上。我在测试端点时一直在用soapui做,所以我知道怎么做,但不知道如何关联测试用例的结果来触发后置条件。

现在我将 selenium 与 eclipse 和 Junit 一起使用,这是我的简单代码:

package com.example.tests;

import java.util.concurrent.TimeUnit;
import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class createLead {
private WebDriver driver;
private Select dropdown;

  @Before
  public void setUp() throws Exception { 
    System.setProperty("webdriver.chrome.driver", "C:\\Users\\Agustin Barcia\\driver\\chromedriver.exe");
    driver = new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  }

  @Test
  public void testUntitledTestCase() throws Exception {
    driver.get("www.randomform.com");    
    driver.findElement(By.id("firstname-input")).sendKeys("agustin");
    driver.findElement(By.id("lastname-input")).sendKeys("placement");
    driver.findElement(By.id("emailaddress-input")).clear();
    driver.findElement(By.id("emailaddress-input")).sendKeys("random@email.com");
    driver.findElement(By.id("country-select"));
    dropdown = new Select(driver.findElement(By.id("country-select")));
    dropdown.selectByValue("ar");
    driver.findElement(By.id("state-select"));
    dropdown = new Select(driver.findElement(By.id("state-select")));
    dropdown.selectByValue("178");
    driver.findElement(By.id("city-select"));
    dropdown = new Select(driver.findElement(By.id("city-select")));
    dropdown.selectByValue("245");
    driver.findElement(By.id("submit-button")).click();    
    } 
}

当我在 Junit 中运行此代码时,窗口显示“Success”并进行注册。

现在我有了在 testrail 中发布结果的代码,我想做一个条件,如果上面的测试用例在 testrail 中返回“成功”帖子,则测试用例 ok,如果测试用例返回“失败”帖子在测试轨道中,测试用例失败。我知道如何发布结果,但不知道如何从测试运行中获得“成功”或“失败”

有什么帮助吗?

【问题讨论】:

  • 你应该看看 JUnit 的TestWatchman/TestWatcher Rules
  • @JakubCh。谢谢!我已经检查了 testwachman,但是由于我不是开发人员,所以我不会考虑是否必须为规则创建一个新类,或者只是将部分代码添加到我上面的测试类中
  • 如果必须为规则创建一个新类,或者只是将部分代码添加到我上面的测试类中,我不会考虑 - 这取决于你。如果您想为许多测试类/套件重用该规则,那么您应该为该规则提供一个新类(以避免代码重复)。否则它可以留在createLead 类中(例如,如果你这样做只是为了学习东西,或者只是将结果发布到测试轨)

标签: java selenium junit testrail


【解决方案1】:

我已经做到了-

“我想设置一个条件,如果上面的测试用例在测试轨中返回“成功”后测试用例正常,如果测试用例在测试轨中返回“失败”后测试用例失败。我知道如何发布结果,但不是如何从测试运行中获得“成功”或“失败”

通过创建一个实现 ITTestListner 并捕获测试用例结果的报告类,如下所示:-

 public void onTestSuccess(ITestResult tr) {

System.out.println("onTestSuccess");

String screenshotPath = ".//" + screenshotName + ".png";
File screenshotTRPath = new File(System.getProperty("user.dir") + "/Reports/" + 
     screenshotName + ".png");

System.out.println("screenshotPath-->" + screenshotPath);
System.out.println("screenshotTRPath-->" + screenshotTRPath.toString());
///TestRail API
try {
    addResultForTestCase(currentTestCaseId, TEST_CASE_PASSED_STATUS, 
 screenshotTRPath.toString());
} catch (IOException | APIException | ParseException e) {  e.printStackTrace();

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多