As IS:
Step 1: I am creating instance of testng in servelt.doPost method.
public void dummyDoPost(){
TestListenerAdapter adapter = new TestListenerAdapter();
testNG = new TestNG();
List<Class> listnerClasses = new ArrayList<Class>();
List<String> suiteNameList = new ArrayList<String>();
Class[] classList = new Class[]{
csvOperation.class
};
listnerClasses.add(straight2bank.csvOperation.class);
testNG.setDefaultSuiteName("suite");
testNG.setListenerClasses(listnerClasses);
testNG.setTestClasses(classList);
testNG.run();
Step 2: I have class created which will read the user choice of platform returned by servelet (Say ios, Android or Chrome).
Pro gram as below. That an another operation
Class B{
public void platformController (Map<String,String> testDataValues){
System.out.println("Platform Controller started.");
String platformToBeExecuted = testDataValues.get("JourneyId");
System.out.println("Journey ID returned to platformController " +platformToBeExecuted);
if(platformToBeExecuted.contains("chrome")){
System.out.println("Platform to be executed: Chrome");
System.setProperty("webdriver.chrome.driver",pathToChromeDriver);
/****
To remove message "You are using an unsupported command-line flag: --ignore-certificate-errors.
Stability and security will suffer."
Add an argument 'test-type'
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
*****/
driver = new ChromeDriver();
driver.get(urlOfApplication);
System.out.println("3");
}else if(platformToBeExecuted.contains("ie")){
System.setProperty("webdriver.ie.driver", pathToIEDriver);
driver = new InternetExplorerDriver();
driver.get(urlOfApplication);
System.out.println("2");
}else if(platformToBeExecuted.contains("iOS")){
System.out.println("Platform to be executed: iOS");
System.out.println("Platform to be executed: iOS");
suites.add(".//iostestng.xml");<-----------------
dummyServletClass.testNG.setTestSuites(suites);
dummyServletClass.testNG.run();
}
SO here I have execute the iosTestng.xml using testng.
To do this :-
1) Do I have to declare testng
as static in servelt
class and use the same here ?
2) Do I need to create an another instance for testng
in class B
?
3) Is there any way to pass an argument constructor in setTestClasses
?
I'm confused, as we may be working on to run the program in parallel on a long run.