从测试中获取JUNIT结果,并将其结果发布到testrail中

时间:2018-09-04 13:24:55

标签: java selenium junit testrail

我是所有这些编码经验的新手。我已经做过手工质量检查了好几年了,现在我开始接触硒了。

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

现在我将硒与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中运行此代码时,窗口显示“成功”并进行了注册。

现在我有将代码发布到testrail的代码,如果上面的测试用例在testrail中返回“成功”后,我想做一个条件,如果测试用例返回“ failure”后,我想做一个条件在测试导轨中,测试用例失败。我知道如何发布结果,但不知道如何从测试运行中获取“成功”或“失败”

有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

我已经做到了-

“我想作为条件,如果上面的测试用例在testrail中返回“成功”帖子,表示测试用例正常,并且如果测试用例在测试用导轨中返回“ failure”帖子,则表示该测试用例失败。我知道如何发布结果,但不能从测试运行中获取“成功”或“失败”

通过创建一个报告类来实现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();

}