Code Monkey home page Code Monkey logo

selenium-webdriver-java's Introduction

Build Status badge-jdk License badge Support badge Twitter Follow

Hands-On Selenium WebDriver with Java

This repository contains a comprehensive collection of examples about Selenium 4 using Java as language binding. These examples are explained in the O'Reilly book Hands-On Selenium WebDriver with Java.

This repo has been implemented as a multi-module project (using Maven and Gradle as build tools) composed of tests based on different frameworks: JUnit 4, JUnit 5 (alone or extended with Selenium-Jupiter), and TestNG.

Practice site

This repo also contains a Practice site, i.e., a representative set of sample web pages used as the system under test (SUT) in the Selenium WebDriver test examples. This site is hosted using GitHub Pages.

Tags

This repo uses Git tags to track the evolution of the codebase in time. These tags are the following:

  • 1.0.0: The examples of the first version of the book (released in April 2022) are based on this tag.
  • 1.1.0: Bump to Java 11, due to the incompatibility of TestNG 7.6.0 (released on May 18, 2022) with Java 8.
  • 1.2.0: Remove GitHub token from the workflow setup, not required anymore since WebDriverManager 5.3.0 (released on August 21, 2022).
  • 1.3.0: Bump to Java 17, due to the incompatibility of Spring Boot 3.0.0 (released on Nov 24, 2022) with Java 11.

About

selenium-webdriver-java (Copyright © 2021-2024) is an open-source project created and maintained by Boni Garcia, licensed under the terms of Apache 2.0 License.

selenium-webdriver-java's People

Contributors

bonigarcia avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

selenium-webdriver-java's Issues

Problem with opening project as a gradle project

Problem with opening project (558f801) as a gradle project.

I opened project as a gradle project in IntelliJ IDEA 2023.2.2 (Community Edition).
But during configuring project ':selenium-webdriver-junit4' a problem occured:

`A problem occurred configuring project ':selenium-webdriver-junit4'.

Could not resolve all files for configuration ':selenium-webdriver-junit4:classpath'.
Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.1.5.
Required by:
project :selenium-webdriver-junit4 > org.springframework.boot:org.springframework.boot.gradle.plugin:3.1.5
> No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.1.5 was found. The consumer was configured to find a library for use during runtime, compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.4' but:
- Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.5 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.4')
- Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.5 declares a component for use during runtime, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 11)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '8.4')
- Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.1.5 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.4')
- Variant 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.1.5 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.4')
- Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.5 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.4')
- Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.5 declares a component for use during runtime, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 11)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '8.4')
...`

I am using jbr-17 (JetBrains Runitime version 17.0.08) and 18 language level.

BR,
knazw

The output files from test classes are written in the parent project directory, instead of the sub-project directory, which is odd

Problem to solve

I cloned the v1.3.0, I executed

$ cd ~/tmp/selenium-webdriver-java
$ tree -L 1 .
.
├── LICENSE
├── README.md
├── alternatives
├── build
├── docs
├── gradle
├── gradlew
├── gradlew.bat
├── pom.xml
├── selenium-ide
├── selenium-webdriver-junit4
├── selenium-webdriver-junit5
├── selenium-webdriver-junit5-seljup
├── selenium-webdriver-testng
└── settings.gradle
10 directories, 6 files

$ ./gradlew :selenium-webdriver-junit4:test 
... (minutes passed)

$ tree -L 1 .
.
├── 2023.11.26_18.36.26.959-6a52be7cc3674308ba99b3523fc8dc12.png
├── 2023.11.26_18.36.28.591-6a52be7cc3674308ba99b3523fc8dc12.png
├── LICENSE
├── README.md
├── alternatives
├── build
├── docs
├── extentReport.html
├── fullpage-screenshot-chrome.png
├── fullpage-screenshot-firefox.png
├── gradle
├── gradlew
├── gradlew.bat
├── my-pdf.pdf
├── pom.xml
├── screenshot.png
├── selenium-ide
├── selenium-webdriver-junit4
├── selenium-webdriver-junit5
├── selenium-webdriver-junit5-seljup
├── selenium-webdriver-testng
├── settings.gradle
├── webdrivermanager.pdf
├── webdrivermanager.png
└── webelement-screenshot.png

10 directories, 16 files

In the parent project directory, 10 files were newly created.

Why these files were written into the parent project selenium-webdriver-java directory? Why not these files were written into the sub-project selenium-webdriver-junit4 directory?

My research

I looked at io.github.bonigarcia.webdriver.jupiter.ch04.screenshots.ScreeshotPngJunit4Test, it has the following statement:

        Path destination = Paths.get("screenshot.png");

The file screenshot.png will be created in the current working directory. Therefore, I can presume, when the test case ran, a call to System.getProperty("user.dir") returned the Path value of the parent project selenium-webdriver-java directory, not the sub-project directory selenium-webdriver-junit4.

Now I can restate my question. Why the current working directory for the test cases were set to be the parent project selenium-webdriver-java directory, not the sub-project directory selenium-webdriver-junit4? which seems very strange for me.

What I found

In the https://github.com/bonigarcia/selenium-webdriver-java/blob/1.3.0/selenium-webdriver-junit5/build.gradle, I found a line:

test {
    ...
    systemProperty System.properties
}

This single line is the cause of the issue that surprised me.

I executed the following command in the Terminal

$ pwd
~/tmp/selenium-webdriver-java
$ ./gradlew :selenium-webdriver-junit4:test

At this instant, the System.properties included the user.dir property which had the value of ~/tmp/selenium-webdriver-java. This value was passed to the test target of the selenium-webdriver-junit4/build.gradle. Therefore all JUnit4 tests found a call to System.getProperty("user.dir") was returning ~/tmp/selenium-webdriver-java, not ~/tmp/selenium-webdriver-java/selenium-webdriver-junit4.

My proposal

The JUnit4/5/TestNG-based test classes should not call java.nio.file.Paths.get(String fileName) to locate output files because Paths.get(String relativePath) depends on the value of current working directory which is not necessarily reliable. The current working directory is dependent on the runtime environment (Gradle, Maven, IntelliJ IDEA, etc).

I would recommend to resolve the project directory by the classpath. I have proposed my solution for this as follows

Unsupported Java. Your build is currently configured to use Java 17.0.8 and Gradle 7.1.

I cloned the master branch of https://github.com/bonigarcia/selenium-webdriver-java.
I installed JDK17.0.8 into my macOS 12.7.
I opened the project in IntelliJ IDEA, I got the following error messages in the Build tab:

Unsupported Java. 
Your build is currently configured to use Java 17.0.8 and Gradle 7.1.

Possible solution:
 - Use Java 16 as Gradle JVM: Open Gradle settings 
 - Upgrade Gradle wrapper to 7.2 version and re-import the project

IntellJ IDEA found Gradle 7.1 to be used, but the Project's JVM is v17.0.8.
It seems that Gradle7.1 is too old to work on JVM 17.

I checked the gradle/wrapper/gradle-wrapper.properties of the master branch:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

The gradle-wrapper.properties files specified gradle v7.1 ---- but it must be too old to work on JDK17.

Opera browser version

Hi, came across the book, congrats !
Trying to run the tests on Opera, but it shows "Browser opera is not available in the system"
Maybe would be better to run on older version of Opera browser?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.