Package and Deploy Selenium WebDriver Project
We use eclipse or any other IDE for creating Selenium WebDriver scripts, but it’s not always feasible to execute the scripts from the IDE. Here we see how to package the selenium project into a jar file and deploy it to servers.
If we package our test script, it could be deployed on any servers and triggered periodically or using any other test management tools.
Please note that this can be used for any type of projects.
Package WebDriver Project
For packaging the application into a jar file, we need a starting class. This is the entry point to your application and would differ based on your framework. If you run your tests using TestNG xml file, you can see this post to run the xml file programmatically.
I’m taking the webdriver project from this post as a base. The project structure is a shown below and the starting point is the Main.java class.
- Right-Click on the project and select Export to bring up the Export dialog.
- Select Runnable JAR file under Java section.
- Under Launch Configuration, select the starting/entry point class for the project.
- Select a suitable location for Export Destination providing the name of the jar. I usually give the project name itself.
- Select Copy required libraries into a sub-folder next to generated JAR
- Select Save as ANT script and provide the filename as build.xml if required (Optional)
- Press Finish.
- In the exported location, you can see the jar file along with a folder containing the dependent jar files.
- Now, you need to copy the resources to the output location. This can include the chromedriver.exe file, testng.xml file, log4j.properties etc.
- After all the required resources are copied to the output location, open up a command prompt on the folder location and run
java -jar <JAR FILE>
// for eg
// java -jar webdriver-testng.jar
- You can create a bat file (any file with .bat as extension) with java -jar <JAR FILE> as its contents so that you don’t have to type every time.
Deploy to server
Once you have generated the jar file and tested it, its time to deploy it in your execution server.
- Zip the above folder to move it to a server and extract it in the suitable location.
- There you can either set up a task scheduler to run the triggerExecution.bat, or have some controller manage the execution.
Hope you found this helpful. Follow us or subscribe to get more such posts.