How to use Test Listener feature for selected test suites or test cases only

I want to use the Test Listener feature to add the open/close browser and login/logout.

But there are some test cases that i don’r really need to login because the tests are mainly on the login page and some links on the login page.

Is it possible to customize?

Certainly. I do this with my tests/suites.

If you organize your tests so that those that need login are stored beneath a specific folder and those that don’t need login are beneath a different folder, then you can use the TestCaseID to find out which need to call your login code.

In my TestCase structure, pages that use/need login are stored under “Pages”…

> Test Cases
  > Pages
    > Page Type 1
      Test Login Required Page
      Test Another Login Required Page
    > Page Type 2
      Test This Page with Login
      Test That Page with Login
  > Other Things
    Test No Login Required Page
    Test Another No Login Required Page
1 Like

I have setup like what you’ve mentioned above.

Then how the code under Test Listener class should look like?

just wanna follow up regarding this?

Hello Russ,

Can you please let know how to setup the above mentioned.
I have created the folder structure as u said.

What you (and @porte.marvin) are asking would require me to write the whole thing for you. Sorry, that’s just not practical.

In brief, it would do this:

  1. Use a listener (@beforeTestCase)
  2. Examine the testCaseId
    2.1 If it requires login, call a login method (Keyword Class)
    2.2 Else, don’t
  3. Drink beer.
1 Like

Thanks Russ the above information was enough to implement it.
It is working.

2 Likes