Skip to content

justunsix/selenium-java-tests

Repository files navigation

Selenium Java Tests

Gitpod ready-to-code

About The Project

Template project to run tests with Selenium and Java.

Built with

Getting Started

Get a local copy up and running by following these steps.

Prerequisites

Choose an option below. You can develop in your browser or locally.

Option 1. Development Environment in Browser

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.

Option 2. Install Locally

  1. Clone this repository to your local computer using git clone https://github.com/justunsix/selenium-java-tests.git.
  2. Install Java Development Kit - Set your JAVA_HOME environment variable to point to Java folder and add the JDK's bin folder to your path environment variable.
  3. Install Maven - add Maven's bin folder to your path environment variable.
  4. Install Chrome in the default location and the Chrome driver, making sure the versions match and add the Chrome driver binary to your 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.
    1. Add the chrome driver folder to your 'path' environment variable.
    2. Open your Chrome browser to check it works. If Chrome opens up as a black screen disable hardware acceleration using this workaround.

Installation and Run

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 ===

Usage

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:

  • Use this space to show useful examples of how a project can be used. Additional screenshots, code examples and demos work well in this space. You may also link to more resources.
  • For more examples, please refer to the Documentation

Roadmap

Contributing

Contributions are what make the open source community a good place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Justin Tung - @justin_tung

Project Link: https://github.com/justunsix/selenium-java-tests

Acknowledgements

Appendix: How this repository was set up

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.

Appendix: Example Windows Setup to Meet Installation Requirements

Appendix: Other Stuff

Download Dependency sources and/or Javadoc

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.

Settings.json

    "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"
        }

Other commands

# 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

About

Template project to run tests with Selenium and Java

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages