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



我是所有这些编码经验的新手。 我已经做了几年的手动QA,现在我开始接触硒

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

现在我正在使用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中运行此代码时,窗口显示"成功"并进行了注册。

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

有什么帮助吗?

我已经这样做了 -

"我想做一个条件,如果,上面的测试用例在testrail中返回"成功"帖子是好的测试用例,如果测试用例在测试轨道中返回"失败"帖子,测试用例失败.我知道如何发布结果,但不知道如何从测试运行中获得"成功"或"失败">

通过创建一个实现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();
}

最新更新