Getting this error : Can inject only one of <ITestContext, XmlTest> into a AfterTest annotated click.

3,516 views
Skip to first unread message

garvitag...@gmail.com

unread,
Jun 22, 2017, 1:38:42 AM6/22/17
to testng-users
Hi,

I am using testNG framework. I am having Base class and other classes CreateClient, CreateProject, CreateUser, AccessToProjects extends base. 
 Steps to reproduce :
1. Create client class creates new client that us random name and saved in iTestContext object passed in @Test method.
2. Create project class creates new project for client(select from dropdown) that is created in created client class by using getProperty method of iTestContext object.
3 Create user creates new user for client created using getProperty method of iTestContext object.
Everything working fine here.

4. AccessToProject class give access to user for particular project. For this i need to select user that is created in CreatedUser class. I am doing same way by iTestContext object. 
On user page, there are many users that are in <li>/<a> tag inside <ul> tag. 

So i am equating if option in list equals to user name created then click it. 

 @Test
    public void project_access(ITestContext itc) {
        usercreated = (String) itc.getAttribute(CreateUser.user_name);    /* pull user name from CreateUser class */
        System.out.println("new user created : " +usercreated); 
   

/* pull all elements in list >
      List<WebElement> li = 
     driver.findElements(By.xpath(".//*[@id='users-list']/ul/li/div/div/div[1]/span/a")); 
      
     for(WebElement userlist : li) { 
         if (userlist.getText().equals(usercreated)) {
                             userlist.click();
                                return;
                  }
                  }


Now there are 2 scenarios :
1. I run my suite commenting @After Test method that closes browser that is defined in Base class. It gives me error Can inject only one of <ITestContext, XmlTest> into a AfterTest annotated click.
I dont have any clue regarding this.

2 I run mu suite without commenting @AfterSuite method, it doe snot give any error. But it does not go inside for loop. I put SOP statement after List<> line, its getting printed. But its not going inside loop.

Thanks,
Garvita Girotra

⇜Krishnan Mahadevan⇝

unread,
Jun 22, 2017, 3:06:12 AM6/22/17
to testng...@googlegroups.com
Can you please help share a simple standalone example which we can execute to reproduce the problem ? That way its easy for us to visualise/see what is the problem as well.


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

garvitag...@gmail.com

unread,
Jun 28, 2017, 2:57:11 AM6/28/17
to testng-users
Hi Krishan,

I am running my suite on headless browser on local server. There is no global link for application that i can provide for sample run.

Thanks, 
Garvita Girotra
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.

⇜Krishnan Mahadevan⇝

unread,
Jun 28, 2017, 5:34:41 AM6/28/17
to testng...@googlegroups.com
Why not create a simple standalone test which doesnt use any of the UI stuff and share that with us, so that we can use that to reproduce your problem ?

Without a reproducible test, its hard to take a jab at your issue and tell you what might be wrong.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages