kazurayam / selenium-webdriver-java

Examples of the O'Reilly book "Hands-On Selenium WebDriver with Java"
https://oreil.ly/1E7CX
Apache License 2.0
0 stars 0 forks source link

compileTestJava task failed; package org.openqa.selenium.devtools.v114.network does not exist #4

Closed kazurayam closed 9 months ago

kazurayam commented 10 months ago

Once I resolved the issue #3 (JDK17, Gradle 8.4), I got several compilation error message:

$ ./gradlew build
Starting a Gradle Daemon, 2 stopped Daemons could not be reused, use --status for details

FAILURE: Build failed with an exception.

* What went wrong:
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.4.
     Required by:
         project :selenium-webdriver-junit4 > org.springframework.boot:org.springframework.boot.gradle.plugin:3.1.4
      > No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.1.4 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.4 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.4 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.4 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.4 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.4 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.4 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')

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 10s
kazurayam commented 10 months ago

The following message tells me that I miss a jar for "Selenium DevTools v114"

> Task :selenium-webdriver-junit4:compileTestJava
/Users/kazuakiurayama/github/selenium-webdriver-java/selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch05/cdp/DeviceEmulationJUnit4Test.java:34: error: package org.openqa.selenium.devtools.v114.network does not exist
import org.openqa.selenium.devtools.v114.network.Network;
                                                ^

I found the jar is avaliable at

kazurayam commented 10 months ago

I should add declaring dependency to the jar.

for the Maven pom.xml files

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-devtools-v114 -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-devtools-v114</artifactId>
    <version>4.12.1</version>
</dependency>

for the Gradle build.gradle files:

// https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-devtools-v114
testImplementation 'org.seleniumhq.selenium:selenium-devtools-v114:4.12.1'
kazurayam commented 10 months ago

I modified 4 build.gradle files in the project, and tried compiling the source with Gradle

:~/github/selenium-webdriver-java (kazurayam4)
$ ./gradlew build

> Task :selenium-webdriver-junit4:compileTestJava
/Users/kazuakiurayama/github/selenium-webdriver-java/selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch10/mobile/AppiumJUnit4Test.java:33: error: cannot find symbol
import io.appium.java_client.remote.MobileCapabilityType;
                                   ^
  symbol:   class MobileCapabilityType
  location: package io.appium.java_client.remote
/Users/kazuakiurayama/github/selenium-webdriver-java/selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch10/mobile/AppiumJUnit4Test.java:45: error: cannot find symbol
        options.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
                              ^
  symbol:   variable MobileCapabilityType
  location: class AppiumJUnit4Test
/Users/kazuakiurayama/github/selenium-webdriver-java/selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch10/mobile/AppiumJUnit4Test.java:46: error: cannot find symbol
        options.setCapability(MobileCapabilityType.DEVICE_NAME,
                              ^
  symbol:   variable MobileCapabilityType
  location: class AppiumJUnit4Test
/Users/kazuakiurayama/github/selenium-webdriver-java/selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch10/mobile/AppiumJUnit4Test.java:48: error: cannot find symbol
        options.setCapability(MobileCapabilityType.AUTOMATION_NAME,
                              ^
  symbol:   variable MobileCapabilityType
  location: class AppiumJUnit4Test
4 errors

> Task :selenium-webdriver-junit4:compileTestJava FAILED

The errors about the DevTools v114 have gone.

The other errors such as "io.appium.java_client.remote.MobileCapabilityType" are another issue => issue #5

kazurayam commented 10 months ago

I also change the Maven pom.xml files.

And I tested compiling the sources with the Maven build tool:

:~/github/selenium-webdriver-java (kazurayam4 *)
$ mvn test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] selenium-webdriver-junit4                                          [jar]
[INFO] selenium-webdriver-junit5                                          [jar]
[INFO] selenium-webdriver-junit5-seljup                                   [jar]
[INFO] selenium-webdriver-testng                                          [jar]
[INFO] selenium-webdriver-java                                            [pom]
[INFO] 
[INFO] -----------< io.github.bonigarcia:selenium-webdriver-junit4 >-----------
[INFO] Building selenium-webdriver-junit4 1.2.0                           [1/5]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ selenium-webdriver-junit4 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ selenium-webdriver-junit4 ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ selenium-webdriver-junit4 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 13 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ selenium-webdriver-junit4 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 217 source files to /Users/kazuakiurayama/github/selenium-webdriver-java/selenium-webdriver-junit4/target/test-classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/kazuakiurayama/github/selenium-webdriver-java/selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch10/mobile/AppiumJUnit4Test.java:[33,36] cannot find symbol
  symbol:   class MobileCapabilityType
  location: package io.appium.java_client.remote
[ERROR] /Users/kazuakiurayama/github/selenium-webdriver-java/selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch10/mobile/AppiumJUnit4Test.java:[45,31] cannot find symbol
  symbol:   variable MobileCapabilityType
  location: class io.github.bonigarcia.webdriver.junit4.ch10.mobile.AppiumJUnit4Test
[ERROR] /Users/kazuakiurayama/github/selenium-webdriver-java/selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch10/mobile/AppiumJUnit4Test.java:[46,31] cannot find symbol
  symbol:   variable MobileCapabilityType
  location: class io.github.bonigarcia.webdriver.junit4.ch10.mobile.AppiumJUnit4Test
[ERROR] /Users/kazuakiurayama/github/selenium-webdriver-java/selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch10/mobile/AppiumJUnit4Test.java:[48,31] cannot find symbol
  symbol:   variable MobileCapabilityType
  location: class io.github.bonigarcia.webdriver.junit4.ch10.mobile.AppiumJUnit4Test
[INFO] 4 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] selenium-webdriver-junit4 1.2.0 .................... FAILURE [  8.420 s]
[INFO] selenium-webdriver-junit5 1.2.0 .................... SKIPPED
[INFO] selenium-webdriver-junit5-seljup 1.2.0 ............. SKIPPED
[INFO] selenium-webdriver-testng 1.2.0 .................... SKIPPED
[INFO] selenium-webdriver-java 1.0.0-SNAPSHOT ............. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  8.574 s
[INFO] Finished at: 2023-10-20T20:38:11+09:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project selenium-webdriver-junit4: Compilation failure: Compilation failure: 
[ERROR] /Users/kazuakiurayama/github/selenium-webdriver-java/selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch10/mobile/AppiumJUnit4Test.java:[33,36] cannot find symbol
[ERROR]   symbol:   class MobileCapabilityType
[ERROR]   location: package io.appium.java_client.remote
[ERROR] /Users/kazuakiurayama/github/selenium-webdriver-java/selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch10/mobile/AppiumJUnit4Test.java:[45,31] cannot find symbol
[ERROR]   symbol:   variable MobileCapabilityType
[ERROR]   location: class io.github.bonigarcia.webdriver.junit4.ch10.mobile.AppiumJUnit4Test
[ERROR] /Users/kazuakiurayama/github/selenium-webdriver-java/selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch10/mobile/AppiumJUnit4Test.java:[46,31] cannot find symbol
[ERROR]   symbol:   variable MobileCapabilityType
[ERROR]   location: class io.github.bonigarcia.webdriver.junit4.ch10.mobile.AppiumJUnit4Test
[ERROR] /Users/kazuakiurayama/github/selenium-webdriver-java/selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch10/mobile/AppiumJUnit4Test.java:[48,31] cannot find symbol
[ERROR]   symbol:   variable MobileCapabilityType
[ERROR]   location: class io.github.bonigarcia.webdriver.junit4.ch10.mobile.AppiumJUnit4Test
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

The Maven build tool run OK. No error about the DevTools v114. This issue#4 is resolved.

There found errors about Appium like [ERROR] symbol: class MobileCapabilityType, I will follow them in another issue #5

kazurayam commented 10 months ago

It is difficult to manage the dependency to the jar of selenium-devtools-vXXX.

As we all know, Chrome browser continues to evolve quite fast. As https://googlechromelabs.github.io/chrome-for-testing/ page shows, as of 21 Oct 2023, the current stable Chrome is v118, the beta v119 is already there, the canary v120 is in process.

The Selenium4 project will continue adding a new Maven repositories as Chrome upgrades in future:

Therefore, as Chrome evolves, the book "Selenium WebDriver in Java" have to be revised, the sample code project have to be updated. --- I am afraid, this makes the life of the book author(@bonigarcia) undurable.

kazurayam commented 10 months ago

In Jun 2023, Chrome for Testing was released.

If the book changes to use Chrome for Testing, rather than the greater Chrome for browsing, the difficulty of dependency management will dissappear.