如何使用 tomcat 单击 Html 按钮调用 Selenium 类
我在不同的 java 文件中有三个测试用例,想要通过单击 html 按钮使用 tomcat 服务器调用它。这是我的 html
<form action="case1" method="post">
<input type="submit" id="sele" name="button" value="TestCase1">
<input type="submit" id="sele1" value="TestCase2">
<input type="submit" id="sele2" value="TestCase3">
</form>
单击按钮后,它将检查在 servlet 中单击了哪个按钮并调用相应的类,一个按钮示例
String button = req.getParameter("button");
PrintWriter out = res.getWriter();
if ("TestCase1".equals(button)) {
try {
out.println("Started");
Sele s=new Sele();
s.sele();
out.println("Ended");
} catch (InterruptedException e) {
e.printStackTrace();
}
输出屏幕显示开始和结束,但它没有调用 Selenium 类。我的 selenium 类代码没有显示任何错误或异常,
public class Sele{
public void sele() throws InterruptedException, IOException{
System.setProperty("webdriver.chrome.driver","C:/java/jar/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://localhost:8080/first/index2.html");
driver.manage().window().maximize();
但是如果我通过命令提示符执行此 java 代码,它会调用 Selenium 类
public Remote{
void remote(){
Sele s=new Sele();
s.sele();
}
}
代码正常工作并自动打开 chrome,但不在服务器中,任何人都可以在这里帮助我。 ....
I have three test case in different java file and want to invoke it using tomcat server by clicking html button. This is my html
<form action="case1" method="post">
<input type="submit" id="sele" name="button" value="TestCase1">
<input type="submit" id="sele1" value="TestCase2">
<input type="submit" id="sele2" value="TestCase3">
</form>
After clicking button it will check which button is clicked in servlet and invoke respective class , one button example
String button = req.getParameter("button");
PrintWriter out = res.getWriter();
if ("TestCase1".equals(button)) {
try {
out.println("Started");
Sele s=new Sele();
s.sele();
out.println("Ended");
} catch (InterruptedException e) {
e.printStackTrace();
}
The output screen show Started and Ended but it didnt invoke Selenium class. And Not Showing any error or Exception, My selenium class code
public class Sele{
public void sele() throws InterruptedException, IOException{
System.setProperty("webdriver.chrome.driver","C:/java/jar/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://localhost:8080/first/index2.html");
driver.manage().window().maximize();
But if i Execute this java code in through command prompt it invoke Selenium class
public Remote{
void remote(){
Sele s=new Sele();
s.sele();
}
}
Code work correctly and open chrome as automated for above code but not in server can any one help me out here.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 sele 类中,我添加了调试器地址并打开特定端口以查看出了什么问题,您可以从已打开的浏览器触发新浏览器到 ren selenium 脚本
In sele class I added debugger Address and open in particular port to see what went wrong and you can able trigger new browser from already opened browser to ren selenium script