简体   繁体   中英

Invoking Selenium Webdriver Script from JSP Page

I am working on an experimental project, where I am trying to invoke Selenium Webdriver script from a JSP Page. So basically client will open a Web application on browser and click on 'Run' link provided (this linked to run.jsp). This will invoke selenium script on Server (On server I have proper steup to execute selenium script). In run.jsp, I am trying to create object of Webdriver and open google.com. Here is my run.jsp

<%@ page import="org.openqa.selenium.WebDriver"%>
    <%@ page import="org.openqa.selenium.chrome.ChromeDriver"%>

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
     pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Selenium Test</title>
    </head>
    <body>
    <%
        System.out.println("Test Selenium Here");
        System.setProperty("webdriver.chrome.driver","/Users/Prateek/Downloads/chromedriver");
        WebDriver driver = new ChromeDriver(); 
        driver.get("http://www.google.com");

    driver.quit(); %> <h1> Test Successfull. </h1> </body> </html>

But when I deploy this application on Tomcat 7 and try to open run.jsp. It throws this error.

HTTP Status 500 - javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver

type Exception report

message javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver

description The server encountered an internal error that prevented it from fulfilling this request.

I am not sure whether its possible to achieve what I am aiming for. Looking for guidance.

Error clearly shows that the interface "org.openqa.selenium.WebDriver" is not in the classpath. Have you included selenium jars in the lib directory of the tomcat or in the classpath?

My question is : What you are experimenting? If a user clicks your link and this request comes to the server and browser instance will be started in the server and not on the client side? Do you really need this feature? for what? Please clarify the purpose.

For my understanding they will try to run the selenium Scripts from the web page,

example, we have 100 scripts like classes(testcases) which is done by selenium webdriver, then i try to invoke the test cases from webpage instead of eclipse.

i have already done this using java swing(Desktop application), i have a common library and functions, then my swing UI will invoke the library functions...

can you try this...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM