With arquillian incontainer mode ,Why Test method is getting exeduted square of the times of values returned by data provider in testng? - testing

I'm using TestNG as Unit Test Framework and Jboss AS7.1.1 Final as server
The data provider and Test methods works well in Client Mode
The same dataprovider will return 10 rows and my Test method is getting executed nearly 100times in In container mode
Test method
#Test(groups="bean-tests",dataProvider="Presenter-Data-Provider")
public void findByIdPositiveTest(long presenterId,String expectedPresenterName)
{
}
Dataprovider method:
#DataProvider(name = "Presenter-Data-Provider")
public Object[][] presenterTestDataProvider()
{
EntityManagerFactory emf=null;
EntityManager em=null;
Object testcaseData[][]=null;
Session session=null;
try
{
emf=Persistence.createEntityManagerFactory("TestCaseDataSource");
em=emf.createEntityManager();
session=em.unwrap(Session.class);
Criteria query=session.createCriteria(TestPresenter.class).setFirstResult(0).setMaxResults(10);
List<TestPresenter> rowList=query.list();
testcaseData=new Object[rowList.size()][2];
for(int loopCount=0;loopCount<rowList.size();loopCount++)
{
TestPresenter row=rowList.get(loopCount);
testcaseData[loopCount][0]=row.getPresenterId();
testcaseData[loopCount][1]=row.getExpectedPresenterName();
}
}
catch(Exception exception)
{
mLog.error(exception.getMessage());
}
return testcaseData;
}
I'm running as Test Suite using folowing Suite configuration
<test name="Bean testing">
<groups>
<run>
<!-- This has to be added by default while using arquillian Test Runner -->
<include name="arquillian" />
<include name="bean-tests" />
</run>
</groups>
<classes>
<class name="blah.blah.blah.PresenterManagerBeanTest" />
</classes>
</test>
Pls let me know What I did was wrong
Or direct me how to get values from DB to Data provider and tests using In container mode
Thanks in advance
sathiya seelan

It looks like it's related to https://issues.jboss.org/browse/ARQ-1282. Issue is still open.

Related

How to run a single test case (method) instead of whole test suite (class) using Selenium/TestNG/Maven

So basically I am wondering how could I run a specific test case (a method) instead of running a whole class.
I am running tests using a combination of Selenium/Maven/TestNG. My current testing setup looks something like this:
simplified command to run tests:
mvn test -DtestSuiteName="test"
contents of test.xml used in the command above:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Selenium Testng Template">
<test name="TestSuiteTest">
<classes>
<class name="listeners.Test_Listener"/>
<class name="tests.example_test_suite_name"/>
</classes>
</test>
</suite>
What the Listener does is basically set up the enviroment for the tests, it starts a pre-configured WebDriver instance and closes it after all the tests are run. It looks something like this:
#Listeners(Listener_Helper)
class Test_Listener implements IExecutionListener {
#BeforeSuite
void openBrowser(){
prepareEnviroment()
}
#AfterSuite
void closeBrowser(){
cleanUp()
}
Now to the contents of a example test file. It consists of a class that is somewhat of a test suite, and it that contains several methods, which are somewhat of a test case.
class example_test_suite_name {
#Test(priority=1)
void test_name_one() {
//test instructions
}
#Test(priority=2)
void test_name_two() {
//test instructions
}
To summarize, It's not a problem to launch a test suite - a class, but how do I launch a single test case - one method of a class?
Let's say I only wanted to start "test_name_one" but not other methods that class contains. Unfortunately I couldn't find anything related to that on the web.
Any hint regarding this matter would be highly appreciated
You can specify test method more in xml file
<groups>
<run>
<include name="setName"></include>
</run>
</groups>
<classes>
<class name="com.journaldev.xml.TestNGXMLTest">
</class>
</classes>
Above test suite will only execute methods in setName group, so only test_setName method will be executed.

org.testng.TestNGException: Parameter 'browser' is required by #Configuration on method MethodSetup

ENV: Seleniuim web driver, testng, eclipse, java 1.8
I have a test. I can run it just fine from testng suite (right click suite > run as > testng suite). If I run the test directly (right click the test > run as > testng test), i get an error:
org.testng.TestNGException: Parameter 'browser' is required by
#Configuration on method MethodSetup but has not been marked #Optional
or defined in
C:\Users\m\AppData\Local\Temp\testng-eclipse--1694993462\testng-customsuite.xml
BaseTest:
public class BaseTest {
protected WebDriver driver;
#Parameters ({"browser"})
#BeforeMethod
protected void MethodSetup(String browser){
System.out.println("method set up");
driver = Browsers.getDriver(browser);
}
//....
}
Test:
public class LoginTest extends BaseTest{
#Parameters({ "browser" , "ch" })
#SuppressWarnings("deprecation")
#Test
public void positiveLoginTest(){
String expectedPageTitle = "Seeker Dashboard - Profile";
String Expectedprofilename = "md";
//...
}
TestNG suite:
<suite name="TestAll">
<test name="ie1">
<parameter name="browser" value="ch"/>
<classes>
<class name="com.dice.LoginTest">
<methods>
<include name="positiveLoginTest"/>
</methods>
</class>
</classes>
</test>
</suite>
You are specifying as a parameter in your suite xml. When you run as suite, that particular xml is used. But when you select a single test and run it, testng creates a custom testng file (with bare minimums - no parameters, no listeners - you can take a look at the file on the path that you mention).
You need to specify your xml as a template xml in eclipse if that is a standard xml that you use. Go to project properties -> testng -> Set the xml as a template xml.

How can I print in log the number of tests running as part of one group in TestNG?

I need to print this before actual execution of tests start. Anyways, we get the count at last of execution.
Say for example if my testng.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1">
<test name="test1">
<groups>
<run>
<include name="functest" />
</run>
</groups>
<classes>
<class name="GroupTestExample" />
</classes>
</test>
</suite>
And there are 10 methods in class GroupTestExample which comes under group functest, it should print 10 in log as soon as it starts running.
Create a custom Listener which extends the org.testng.TestListenerAdapter. After that override the following method:
public class MyCustomListener extends TestListenerAdapter {
#Override
public void onStart(ITestContext testContext) {
super.onStart(testContext);
System.out.println("Number of Test Methods: " + testContext.getAllTestMethods().length);
}
}
You can add your custom listener by using #Listeners annotation on your main class of your test, like
#Listeners({MyCustomListener.class})
public class MyMainTestClass { ... }
You can find more information in TestNG doc:
TestNG Listeners -
http://testng.org/doc/documentation-main.html#testng-listeners

Selenium Web driver script running in alphabetical order of method name on TestNG. What is the way to run it in a specific sequence

I have to run my scripts in specific order let say :-
1)Login
2)Add Profile
3)Edit Profile
4)Delete profile
But when I execute my script it is executing alphabetically not as the desired flow.
What can be done to run testcases in desired sequence
You can prioritize you tests:
#Test(priority=1)
public void LoginTest() {}
#Test(priority=2)
public void AddProfileTest() {}
In this case tests will run according theirs priority (lower priorities will be scheduled first).
Or you can use dependsOnMethods and dependsOnGroups:
#Test(groups = "group1")
public void LoginTest() {}
#Test(groups = "group1")
public void AddProfileTest() {}
#Test(dependsOnGroups = "group1")
public void EditProfile() {}
In this case EditProfile test will only run after LoginTest() and AddProfileTest() have completed successfully.
Or you can specify order of tests run in testng.xml.
See documentation: http://testng.org/doc/documentation-main.html
You can use XML to make your methods run in an order.
For Example
`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="ur suite name">
<test name="test_name" preserve-order="true">
<classes>
<class name="packagename.class name">
<methods>
<include name="method1"/>
<include name="method2"/>
</methods>
</class>
</classes>
</test>
</suite>
`:

will testng initiate as many webdriver instance as test cases?

I am facing a problem of Selenium Grid and TestNG. My test scripts will NOT quite the browser until all the test class are executed.
I've configed 5 Chrome instance running on my Selenium Grid, then below is my xml file
<suite name="BrowserTest">
<test name="Test1" >
<parameter name="browserName" value="chrome"/>
<classes>
<class name= "Pagetest" />
</classes>
</test>
<test name="Test2" >
<parameter name="browserName" value="firefox"/>
<classes>
<class name= "Pagetest" />
</classes>
</test>
<test name="Overview Page Test on ie, English" >
<parameter name="browserName" value="ie"/>
<classes>
<class name= "Pagetest" />
</classes>
</test>
</suite>
Here is my test scripts
public class Pagetest {
private WebDriver browser;
public PateTest( String browser){
// create a browser instance.
}
#AfterClass (or #afterTest)
public void afterTest() throws Exception {
System.out.println("this test is done");
this.browser.quit();
}
#Test
public void test1(){
this.browser.get("www.google.com");
// doing some login stuff
}
}
Now when I am running my test, testNG will create 3 chrome webdirver instance one by one (with running the test). but after the 1st test is done, the browser instance of 1st test is not quited until all 3 tests are done, then all the 3 chrome instance are quited almost at the same time. What I want is after the 1st test is done, it's browser instance is quited, then the 2nd test case is started, did I do something wrong or how should I change my code?
Try using threadlocal it would help when you are even running tests in parallel
public ThreadLocal<WebDriver> driver=null;
#beformethod()
public void setUp
{
driver = new ThreadLocal<WebDriver>();
driver.set(new ChromeDriver());
return driver.get();
}
#AfterMethod
public void closeBrowser() {
{
driver.get().quit();
}