Selenium 在测试调用之后,我可以在中获取@Test的变量名和方法名吗?
上面是我的一个测试用例。在这里,我为两件事感到震惊Selenium 在测试调用之后,我可以在中获取@Test的变量名和方法名吗?,selenium,testng,Selenium,Testng,上面是我的一个测试用例。在这里,我为两件事感到震惊 @BeforeSuite public void reports() { clearreports(); } @Test(priority = 0,enabled = true) public void C2410949_VerifyNameIsCorrectlyDisplayedOnHomePage() throws IOException, InterruptedException, ATU
@BeforeSuite
public void reports() {
clearreports();
}
@Test(priority = 0,enabled = true)
public void C2410949_VerifyNameIsCorrectlyDisplayedOnHomePage() throws IOException, InterruptedException, ATUTestRecorderException, APIException {
String TestCaseId = "8789740";
ATUTestRecorder record = new ATUTestRecorder("./video",
Thread.currentThread().getStackTrace()[1].getMethodName(), true);
record.start();
launchUrl();
startResult();
startTestCase(Thread.currentThread().getStackTrace()[1].getMethodName().toString());
UserNamePage usernamePage = new UserNamePage();
usernamePage.EnterUsername(BaseClass.username.toUpperCase());
PasswordPage passwordPage = new PasswordPage();
passwordPage.passwordValidator(BaseClass.password);
Thread.sleep(30000);
HomePage homePage = new HomePage();
String actualNickName = homePage.WelcomeMessage.getText().toString().replaceAll("hello,", "").trim();
System.out.println("Actual Nick Name:"+actualNickName);
homePage.Click(homePage.SettingsNHelp);
Thread.sleep(15000);
SettingsAndHelp settingandhelp = new SettingsAndHelp();
settingandhelp.Click(settingandhelp.ChangeContactInformation);
Thread.sleep(5000);
SettingsAndHelp.ChangeContactInformation changeContactInformation = settingandhelp.new ChangeContactInformation();
String expecteduserNickName = changeContactInformation.UserNickName.getText().toString()+"!";
System.out.println(expecteduserNickName);
AssertVerify(actualNickName, expecteduserNickName);
homePage.Click(homePage.Logout);
endTestcase();
endResult();
updateResults(TestCaseId, "PASSED");
record.stop();
}
@AfterTest
public void TearDown() {
endTestcase();
endResult();
driver.close();
}
有什么方法可以获得我在@test中使用的测试用例Id吗
One is Test Rail Integration:
1. I have `testcase Id` in `@ Test`. But if test case is passed, then it is all good. But In middle if it fails, I have to fail the test case. I can move that making fail part in @afterTest but test case Id will not be available from @Test.
但我再次发现视频命名约定很困难,因为我将当前的方法名称/testcase id视为视频名称
有人能帮我吗
谢谢您可以使用该界面。它允许您存储对象,然后在任何需要的地方检索对象。它将与整个测试运行保持相关
如何使用:
1) 首先将属性设置为所需的任何值,在本例中为TestCaseId-
2. The recording is also not working if it fails in middle as it is record.stop at the end of the test case. I can initialize and start record in @BeforeTest and Stop in @AfterTest.
2) 然后在所需函数中检索它-
@Test(priority = 0,enabled = true)
public void C2410949_VerifyNameIsCorrectlyDisplayedOnHomePage(ITestContext testContext) throws IOException, InterruptedException, ATUTestRecorderException, APIException {
String TestCaseId = "8789740";
testContext.setAttribute("TestCaseID", TestCaseId);
// rest of the code
请注意,我是如何在这两个函数中将
ITestContext testContext
作为参数传递的 您可以在testNG中使用listener,也可以在Java中使用reflection类。我可以在testNG中使用listener的一些示例吗?它没有我想要的:(请参阅此操作正常。您可以同时查看第二部分吗?在第二部分中,您说您需要@AfterTest中的TestCaseId。我相信该问题已由我的asnwer解决。您可以编辑该问题并更清楚地了解您的问题吗。
@AfterTest
public void TearDown(ITestContext testContext) {
String testCaseId = testContext.getAttribute("TestCaseID");
endTestcase();
endResult();
driver.close();
}