0
@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();
}

The above is one of my test case. Here I am struck for two items.

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.

Is there any way that i can get the test case Id which I used in @ Test

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. 

But again the I am finding difficult for naming convention for video as i am looking current method name/testcase id as Video name..

Can any one help me on this?

Thanks

ChanGan
  • 4,254
  • 11
  • 74
  • 135

1 Answers1

0

You can use ITestContext interface. It allows you to store objects and then retrieve it anywhere you want. It will remain relevant for one whole test run.

How to use:

1) First set your attribute to whatever value you want, in this case the TestCaseId -

@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

2) Then retrieve it in your required function -

@AfterTest
public void TearDown(ITestContext testContext) {
    String testCaseId = testContext.getAttribute("TestCaseID");
    endTestcase();
    endResult();
    driver.close();
}

Note how I have passed ITestContext testContext as a parameter in both the functions.

Shivam Mishra
  • 1,731
  • 2
  • 11
  • 29
  • This is working fine. Can you look the second part as well? – ChanGan Jun 29 '18 at 09:56
  • In the second part, you said that you need the TestCaseId in @AfterTest. I believe that problem is solved by my asnwer. Can you please edit the question and be more clear what you are asking. – Shivam Mishra Jun 29 '18 at 11:19