I have also added another solution which you wanted to implement ie) passing the values from the servlet post method to your selenium test
Download selenium java client driver here
Extract the downloaded jar and add the selenium-java-2.46.0.jar and all the other jars in libs folder into /WEB-INF/lib folder of the deployed web app
I will add a basic script which i tested and was working fine as an example
Servlet post method
protected void doPost(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException
{
resp.setContentType("text/html");
String url=req.getParameter("url");
//add the parameters to be passed to the main method of the selenium test into a string array
String[] urls=new String[1];
urls[0]=url;
//pass the string array as an argument to the main method
Seleniumclass.main(urls);
}
}
SeleniumTest
public class Seleniumclass {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get(args[0]);
}
}
Note : You cannot call the testng test directly from the servlet post method like main method bcause testng is a testing framework but you can write the post values from a servlet to a file and then trigger the testng.xml file from your servlet program.In your selenium script read the values from file
Trigger testng xml file
TestListenerAdapter adapter = new TestListenerAdapter();
TestNG testng = new TestNG();
List<String> suites = Lists.newArrayList();
//path to xml
suites.add("/home/vicky/testng.xml");
testng.setTestSuites(suites);
testng.run();
Hope this helps you...if you still face any issues kindly get back