Template project to run tests with Selenium and Java.
Get a local copy up and running by following these steps.
Choose an option below. You can develop in your browser or locally.
Gitpod is an online dev environment based on VS Code/Theia and can launch ready-to-code development environments for GitHub projects with a single click. It is free for open source projects like this one and a nice way to sharing code with others. You can open https://gitpod.io/#https://github.com/justunsix/selenium-java-tests or push the Gitpod ready-to-code button at the top of this README.
This option right now is only useful for development. To run the program, a local installation is recommended since it requires a Chrome browser installed.
git clone https://github.com/justunsix/selenium-java-tests.git
.JAVA_HOME
environment variable to point to Java folder and add the JDK's bin folder to your path
environment variable.path
environment variable.path
environment variable. Web Driver Manager is an alternative and efficient way to manage this part; however, this repository does not use it as a dependency.
Confirm installations and pathes are setup in a terminal
# Maven
mvn -v
# Java
java -version
Build and run the project
cd training
mvn package
# Run main method in class AppExample
mvn exec:java -Dexec.mainClass="training.AppExample"
After running it, Chrome will briefly open and visit https://the-internet.herokuapp.com/, a site for test automation, and then close. You will see something like below in the terminal indicating the driver visited and got a link text meaning the run was successful.
[[ChromeDriver: chrome on WINDOWS (d40a87asdas31c6a93304e19e3)] -> partial link text: Testing]
=== Test Driver Complete ===
Inspect the Java model framework for https://the-internet.herokuapp.com/ and https://formy-project.herokuapp.com/ and see and modify test cases for The-Internet site.
When developing, you may want to download the dependency's source with mvn dependency:sources
and/or Javadocs with mvn dependency:resolve -Dclassifier=javadoc
Placeholders:
Contributions are what make the open source community a good place to learn, inspire, and create. Any contributions you make are greatly appreciated.
git checkout -b feature/AmazingFeature
)git commit -m 'Add some AmazingFeature'
)git push origin feature/AmazingFeature
)Distributed under the MIT License. See LICENSE
for more information.
Justin Tung - @justin_tung
Project Link: https://github.com/justunsix/selenium-java-tests
AppExample.java
Initialize project in this repository's folder using a Maven quickstart template
mvn archetype:generate -DgroupId=training -DartifactId=training -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
Add Selenium's dependency to Maven's pom. Added Chrome driver dependency from MVN for testing. Other WebDrivers can be added.
See more options at Maven download sources javadoc
mvn dependency:sources
mvn dependency:sources dependency:resolve -Dclassifier=javadoc
If using VS Code, ctrl+click into a class and then right click to attach the source for the dependency.
"java.configuration.runtimes": [
{
"name": "JavaSE-1.8",
"path": "C:\\usr\\bin\\JDK64",
"sources": "C:\\usr\\bin\\JDK64\\lib\\src.zip",
"javadoc": "https://docs.oracle.com/javase/8/docs/api/",
"default": true
},
{
// Installed with VS Code Java quickstart
"name": "JavaSE-11",
"path": "C:\\Program Files\\AdoptOpenJDK\\jdk-11.0.11.9-hotspot",
"sources": "C:\\Program Files\\AdoptOpenJDK\\jdk-11.0.11.9-hotspot\\lib\\src.zip",
"javadoc": "https://docs.oracle.com/en/java/javase/11/docs/api/",
"default": true
}
// Sonarlint: selenium-java-tests project binding, make sure to configure the connection in your workspace settings or global settings
"sonarlint.connectedMode.project": {
"projectKey": "selenium-java-tests"
}
# Run a single class
java -cp target/base-1.0-SNAPSHOT.jar base.BaseTests
# Execute a single method called testSuccessfulCloseAndSeeModalLink in ModalEntryAdTests class in src/test
mvn -Dtest=HorizontalSliderTests#testSliding test
# Run main testing class, cleanupDaemonThreads is required otherwise
# there is a java.lang.IllegalThreadStateException or use System.exit(0);
# at the end of the program
mvn exec:java -Dexec.mainClass="training.AppExample" -Dexec.cleanupDaemonThreads=false
# Build, test and scan code for upload to sonarcloud.io
# Requires access to the project in Sonar Cloud and
# connect in environment variable / project settings > Analysis method > Manual
mvn verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar