我正在使用selenium开发用于UI(浏览器)测试的自动化测试框架。
我们正在使用Test Link来存储测试用例和管理执行状态。
我们正在使用Test Link api在执行后更新测试链接中的执行状态,但状态会在测试用例级别更新。
我还需要在测试步骤级别更新执行状态。
需要深入了解这一点。 以下是我使用的代码。
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import testlink.api.java.client.TestLinkAPIClient;
import testlink.api.java.client.TestLinkAPIException;
import testlink.api.java.client.TestLinkAPIResults;
public class AutomatedUpdateExample {
public static String DEVKEY = "2f404203b306bd8dd811a7f824c194d0";
public static String URL = "http://localhost/testlink/lib/api/xmlrpc/v1/xmlrpc.php";
public static void reportResult(String TestProject, String TestPlan, String Testcase, String Build, String Notes, String Result) throws TestLinkAPIException {
TestLinkAPIClient api = new TestLinkAPIClient(DEVKEY, URL);
api.reportTestCaseResult(TestProject, TestPlan, Testcase, Build, Notes, Result);
}
@Test
public void Test1() throws Exception {
AutomatedUpdateExample a = new AutomatedUpdateExample();
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 600);
String testProject = "Gmail";
String testPlan = "SampleTestPlan";
String testCase = "GmailLogin1";
String build = "SampleBuild";
String notes = null;
String result = null;
try {
driver.manage().window().maximize();
driver.get("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1");
driver.findElement(By.id("Email")).sendKeys("testlink.msoftgp");
driver.findElement(By.id("Passwd")).sendKeys("*******");
driver.findElement(By.id("signIn")).click();
driver.switchTo().defaultContent();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("+Testlink")));
result = TestLinkAPIResults.TEST_PASSED;
notes = "Executed successfully";
}
catch (Exception e) {
result = TestLinkAPIResults.TEST_FAILED;
notes = "Execution failed";
} finally {
a.reportResult(testProject, testPlan, testCase, build, notes, result);
driver.quit();
}
}
}