Executing specific tests

31 views
Skip to first unread message

Amit

unread,
Sep 27, 2016, 2:58:27 AM9/27/16
to Selenium Users
Hi there,

I am new to automation and using Java + Eclipse IDE + TestNG + Selenium WebDriver.

@BeforeSuite
initializeWebDriver(){
}

@BeforeTest
getURL(){
}

@Test
loginToWebPage() {
}

@Test
SearchSomething(){
}

@Test
GenerateReport(){
}

I have the above methods. For Example, I wish to only execute GenerateReport() method, then how do i do it. Usual path of execution is 
1. Login
2. Search
3. Generate Report


Suggestions / Advice are very much appreciated.

Thanks,
Amit 

anemuday

unread,
Sep 27, 2016, 5:31:32 AM9/27/16
to Selenium Users
Hi Amit,

You can invoke any specific test method by specifying that method name in your testng file, but remember your before and after methods will execute in addition to your test method.

<suite name="test" verbose="1">
<test name="CallMethod">
<classes>
<class name="yourclass" />
<methods>
<include name="GenerateReport"></include>
</methods>
</classes>
</test>
</suite>

Here it invokes,
initializeWebDriver() - default
getURL() - default
GenerateReport() - Your method


Do let me know if it didnt help.

Thanks,
Uday

Amit

unread,
Sep 27, 2016, 9:00:00 AM9/27/16
to Selenium Users
Thanks for your prompt reply Uday. But the flow is like 
initializeWebDriver() 
getURL() 
login()
GenerateReport() 

Unless the credentials are provided at login screen i cannot go further, hence is there a way where we are on the next screen after login page and i can directly run a generatereport()

anemuday

unread,
Sep 29, 2016, 1:07:46 AM9/29/16
to Selenium Users
Amit,

In your post, you told us that you need to execute only generateReports() method, so i gave above lines of code.

Now you are asking us to execute Login method also. So below is the code:

<suite name="test" verbose="1">
 
<test name="CallMethod">
 
<classes>
 
<class name="yourclass" />
 
<methods>

                               
<include name="loginToWebPage"></include>

 
<include name="GenerateReport"></include>
 
</methods>
 
</classes>
 
</test>
</suite>


If you want to execute generatereport only after login is successful, then you can update your generatereport method to

@Test(dependsOnMethods = { "loginToWebPage" })
GenerateReport(){
}

Reply all
Reply to author
Forward
0 new messages