Closed kazurayam closed 9 months ago
selenium-webdriver-junit4/build.gradle has the following code:
appiumVersion = "9.0.0"
I changed this interrimly to
appiumVersion = "8.6.0"
and tried to run the test:
$ ./gradlew test
> Task :selenium-webdriver-junit4:compileTestJava
Note: /Users/kazuakiurayama/github/selenium-webdriver-java/selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch10/mobile/AppiumJUnit4Test.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
> Task :selenium-webdriver-junit4:test
io.github.bonigarcia.webdriver.junit4.ch02.helloworld.HelloWorldChromeJUnit4Test STANDARD_OUT
2023-10-20 21:03:25 [Test worker] DEBUG i.g.bonigarcia.wdm.WebDriverManager.<init>(225) - Using WebDriverManager 5.5.3
2023-10-20 21:03:26 [Test worker] DEBUG i.g.b.wdm.cache.ResolutionCache.checkValidity(156) - Removing resolution chrome=97 from cache (expired on Thu Jan 13 00:05:00 JST 2022)
2023-10-20 21:03:26 [Test worker] DEBUG i.g.b.wdm.versions.VersionDetector.getBrowserVersionFromTheShell(259) - Detecting chrome version using online commands.properties
2023-10-20 21:03:26 [Test worker] DEBUG i.g.bonigarcia.wdm.versions.Shell.runAndWaitArray(65) - Running command on the shell: [/Applications/Google Chrome.app/Contents/MacOS/Google Chrome, --version]
2023-10-20 21:03:27 [Test worker] DEBUG i.g.bonigarcia.wdm.versions.Shell.runAndWaitArray(69) - Result: Google Chrome 118.0.5993.96
2023-10-20 21:03:28 [Test worker] INFO i.g.bonigarcia.wdm.WebDriverManager.resolveDriverVersion(1217) - Using chromedriver 118.0.5993.70 (resolved driver for Chrome 118)
2023-10-20 21:03:28 [Test worker] DEBUG i.g.b.wdm.cache.ResolutionCache.putValueInResolutionCacheIfEmpty(119) - Storing resolution chrome=118 in cache (valid until 22:03:28 20/10/2023 JST)
2023-10-20 21:03:28 [Test worker] DEBUG i.g.b.wdm.cache.ResolutionCache.putValueInResolutionCacheIfEmpty(119) - Storing resolution chrome118=118.0.5993.70 in cache (valid until 21:03:28 21/10/2023 JST)
2023-10-20 21:03:28 [Test worker] DEBUG i.g.bonigarcia.wdm.WebDriverManager.createUrlHandler(1453) - Driver to be downloaded chromedriver 118.0.5993.70
2023-10-20 21:03:28 [Test worker] INFO i.g.bonigarcia.wdm.online.Downloader.downloadAndExtract(132) - Downloading https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/118.0.5993.70/mac-x64/chromedriver-mac-x64.zip
2023-10-20 21:03:36 [Test worker] INFO i.g.bonigarcia.wdm.online.Downloader.extract(193) - Extracting driver from compressed file chromedriver-mac-x64.zip
2023-10-20 21:03:37 [Test worker] INFO i.g.bonigarcia.wdm.WebDriverManager.exportDriver(1270) - Exporting webdriver.chrome.driver as /Users/kazuakiurayama/.cache/selenium/chromedriver/mac64/118.0.5993.70/chromedriver
io.github.bonigarcia.webdriver.junit4.ch02.helloworld.HelloWorldChromeJUnit4Test > test FAILED
java.lang.NoClassDefFoundError at HelloWorldChromeJUnit4Test.java:46
Caused by: java.lang.ClassNotFoundException at HelloWorldChromeJUnit4Test.java:46
java.lang.NullPointerException at HelloWorldChromeJUnit4Test.java:51
io.github.bonigarcia.webdriver.junit4.ch02.helloworld.HelloWorldEdgeJUnit4Test STANDARD_OUT
2023-10-20 21:03:37 [Test worker] DEBUG i.g.bonigarcia.wdm.WebDriverManager.<init>(225) - Using WebDriverManager 5.5.3
2023-10-20 21:03:37 [Test worker] DEBUG i.g.b.wdm.versions.VersionDetector.getBrowserVersionFromTheShell(259) - Detecting edge version using online commands.properties
2023-10-20 21:03:37 [Test worker] DEBUG i.g.bonigarcia.wdm.versions.Shell.runAndWaitArray(65) - Running command on the shell: [/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge, -version]
2023-10-20 21:03:37 [Test worker] DEBUG i.g.bonigarcia.wdm.versions.Shell.runAndWaitNoLog(83) - There was a problem executing command </Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge -version> on the shell: Cannot run program "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge" (in directory "."): error=2, No such file or directory
2023-10-20 21:03:37 [Test worker] DEBUG i.g.bonigarcia.wdm.versions.Shell.runAndWaitArray(69) - Result:
2023-10-20 21:03:37 [Test worker] DEBUG i.g.b.wdm.versions.VersionDetector.getBrowserVersionFromTheShell(267) - Browser version for edge not detected using online properties (using local commands.properties)
2023-10-20 21:03:37 [Test worker] DEBUG i.g.bonigarcia.wdm.versions.Shell.runAndWaitArray(65) - Running command on the shell: [/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge, -version]
2023-10-20 21:03:37 [Test worker] DEBUG i.g.bonigarcia.wdm.versions.Shell.runAndWaitNoLog(83) - There was a problem executing command </Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge -version> on the shell: Cannot run program "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge" (in directory "."): error=2, No such file or directory
2023-10-20 21:03:37 [Test worker] DEBUG i.g.bonigarcia.wdm.versions.Shell.runAndWaitArray(69) - Result:
2023-10-20 21:03:37 [Test worker] DEBUG i.g.bonigarcia.wdm.WebDriverManager.resolveDriverVersion(1242) - The driver version for EDGE is unknown ... trying with latest
2023-10-20 21:03:38 [Test worker] DEBUG i.g.b.wdm.versions.VersionDetector.getDriverVersionFromRepository(180) - Latest version of msedgedriver according to https://msedgedriver.azureedge.net/LATEST_STABLE is 118.0.2088.57
2023-10-20 21:03:38 [Test worker] INFO i.g.bonigarcia.wdm.WebDriverManager.logSeekRepo(1568) - Reading https://msedgedriver.azureedge.net/?restype=container&comp=list to seek msedgedriver
2023-10-20 21:03:41 [Test worker] DEBUG i.g.bonigarcia.wdm.WebDriverManager.createUrlHandler(1453) - Driver to be downloaded edgedriver 118.0.2088.57
2023-10-20 21:03:41 [Test worker] INFO i.g.bonigarcia.wdm.online.Downloader.downloadAndExtract(132) - Downloading https://msedgedriver.azureedge.net/118.0.2088.57/edgedriver_mac64.zip
2023-10-20 21:03:49 [Test worker] INFO i.g.bonigarcia.wdm.online.Downloader.extract(193) - Extracting driver from compressed file edgedriver_mac64.zip
2023-10-20 21:03:49 [Test worker] INFO i.g.bonigarcia.wdm.WebDriverManager.exportDriver(1270) - Exporting webdriver.edge.driver as /Users/kazuakiurayama/.cache/selenium/msedgedriver/mac64/118.0.2088.57/msedgedriver
io.github.bonigarcia.webdriver.junit4.ch02.helloworld.HelloWorldEdgeJUnit4Test > test FAILED
java.lang.NoClassDefFoundError at HelloWorldEdgeJUnit4Test.java:46
Caused by: java.lang.ExceptionInInitializerError at ClassLoader.java:-2
java.lang.NullPointerException at HelloWorldEdgeJUnit4Test.java:51
........... (a lot more of test execution logs followed)
Now the compilation errors were worked-around by changing theappiumVersion
from 9.0.0
to 8.6.0
.
If we downgradle Appium from 9.0.0 to 8.6.0, we can pass "compileTestJava" task and therefore I can look at whole sequence of tests are running.
If we stick to the Appium 9.0.0, we can NOT pass "compileTestJava" task. This is very bad.
We need to find out how to amend the test source in java which are now failing with Appium 9.0.0 so that they pass the compilation.
I guess, the MobileCapabilityType class is no longer there in the Appium 9.0.0.
In the 8.6.0 Appium java-client javadoc, I found that io.appium.java_client.remote.MobileCapabilityType
class was marked @Deprecated
io.appium.java_client.remote
Interface MobileCapabilityType
All Superinterfaces:
org.openqa.selenium.remote.CapabilityType
Deprecated.
This interface will be removed. Use Options instead.
@Deprecated
public interface MobileCapabilityType
extends org.openqa.selenium.remote.CapabilityType
The list of common capabilities.
Read:
https://appium.io/docs/en/latest/guides/caps/#appium-capabilities
How to resolve this? --- The javadoc just says "Use Options instead".
In the Migration Guide v8 to v9 told
MobileCapabilityType interface. Use driver options instead.
I noticed also the compiler warned that we are using Deprecated API in the Appium java-client 8.6.0:
> Task :selenium-webdriver-junit4:compileTestJava
Note: /Users/kazuakiurayama/github/selenium-webdriver-java/selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch10/mobile/AppiumJUnit4Test.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
....
So how should I modify the source of AppiumJUnitXTest.java
?
According to the source of v8.6.0, MobileCapabilityType
MobileCapabilityType.PLATFORM_NAME
is not declaredMobileCapabilityType.DEVICE_NAME
is a String "deviceName"
MobileCapabilityType.AUTOMATION_NAME
is not declaredI feel I am at a loss.
I happend to find an article https://www.lambdatest.com/blog/desired-capabilities-in-selenium-testing/
{
“platformName”: “Android”,
“platformVersion”: “10.0”,
“deviceName”: “Samsung Galaxy s10”,
“automationName”: “Appium”,
“app”: “path for the app under test”
}
So I guess I could rewrite the AppiumJUnitXTest.java
as follows
MobileCapabilityType.PLATFORM_NAME
-> platformName
MobileCapabilityType.DEVICE_NAME
-> deviceName
MobileCapabilityType.AUTOMATION_NAME
-> automationName
The Appium java-client v9.0 README shows the following sample code:
BaseOptions options = new BaseOptions()
.setPlatformName("myplatform")
.setAutomationName("mydriver")
.amend("mycapability1", "capvalue1")
.amend("mycapability2", "capvalue2");
AppiumDriver driver = new AppiumDriver(
// The default URL in Appium 1 is http://127.0.0.1:4723/wd/hub
new URL("http://127.0.0.1:4723"), options
);
try {
WebElement el = driver.findElement(AppiumBy.className, "myClass");
el.click();
driver.getPageSource();
} finally {
driver.quit();
}
How to set the DEVICE_NAME?
One more sample code that shows how to build Options
import io.appium.java_client.chromium.options.ChromiumOptions;
...
@Test
public void canBuildChromiumOptions() {
// Given
// When
ChromiumOptions options = new ChromiumOptions();
options.setNewCommandTimeout(Duration.ofSeconds(10))
.setPlatformName(Platform.MAC.name())
.withBrowserName("Chrome")
.setAutodownloadEnabled(true)
.setBuildCheckDisabled(true)
.setChromeDriverPort(5485)
.setExecutable("/absolute/executable/path")
.setLogPath("/wonderful/log/path")
.setVerbose(true);
// Then
assertEquals(AutomationName.CHROMIUM, options.getAutomationName().orElse(null));
assertEquals("Chrome", options.getBrowserName());
assertTrue(options.isAutodownloadEnabled().orElse(null));
assertTrue(options.isBuildCheckDisabled().orElse(null));
assertEquals(5485, options.getChromeDriverPort().orElse(null));
assertFalse(options.getExecutableDir().isPresent());
assertEquals("/absolute/executable/path", options.getExecutable().orElse(null));
assertEquals("/wonderful/log/path", options.getLogPath().orElse(null));
assertFalse(options.isUseSystemExecutable().isPresent());
assertTrue(options.isVerbose().orElse(null));
}
This sample does not deal with DEVICE_NAME which our AppiumJUnitXTest
class wants to specify explicitly.
I found that the above sample code uses
import io.appium.java_client.chromium.options.ChromiumOptions;
On the other hand, https://github.com/kazurayam/selenium-webdriver-java/blob/master/selenium-webdriver-junit4/src/test/java/io/github/bonigarcia/webdriver/junit4/ch10/mobile/AppiumJUnit4Test.java uses
import org.openqa.selenium.chrome.ChromeOptions;
This difference may have a deep background story. I should be careful.
...
Does the Appium java-client v8.6.0 has the io.appium.java_client.chromium.options.ChromiumOptions
? Let me check. ...
Yes, there is. https://github.com/appium/java-client/blob/v8.6.0/src/main/java/io/appium/java_client/chromium/options/ChromiumOptions.java
Is @bonigarcia aware of io.appium.java_client.chromium.options.ChromiumOptions
? Why he did not use it?
Well, I know nothing about what he thought.
What should I (@kazurayam) do? --- I (@kazurayam) want to modify the AppiumJUnit4Test.java
to pass compilation. To achieve it, I will refer to the sample code that uses io.appium.java_client.chromium.options.ChromiumOptions
. And I will propose a Pull Request to @bonigarcia. If he likes it or not, let him judge.
I found an useful stuff in the article Desired Capabilities in Selenium Testing, Lambdatest
automationName: Using this capability we can instruct driver about which automation engine it should use. By default, it is set as Appium. Other available engines like Appium, Espresso (both are for android), XCUITest (for iOS)
platformName: We can use this to instruct about the mobile operating system platform like iOS, Android, etc.
platformVersion: We can use this for mentioning the mobile operating system version on which test expect to execute.
deviceName: We can use this to specify the particular mobile device over which we wish to perform automated browser testing. Like we have used Samsung Galaxy s10 in the above example.
app: This capability is used to provide the path of our application which needs to be tested with script. Here we provide an absolute local path or remote path with HTTP URL.
browserName: This can be used when we want to execute a test on mobile web browser. We can provide the name of the browser like Safari for iOS, Chrome for Android, etc. It can be left empty when we want to automate app and not using browser.
language: This can be used to set the language of Android or iOS. newCommandTimeout: This capability helps to instruct driver for the time it has to wait for a new command from client before ending the idle session.
There are few more general capabilities like noReset, fullReset,eventTimings, etc.
Sample code about "deviceName"
The Appium java-client v9.0.0 was just recently released at 13 Oct 2023
https://github.com/appium/java-client/releases/tag/v9.0.0
This icludes a breaking change:
The previously deprecated MobileCapabilityType interface has been removed. Use driver options instead
The upgrade of Appium java-client v8.6.0 to v9.0.0 has broken the https://github.com/bonigarcia/selenium-webdriver-java, tag 1.3.0
I have modified
at https://github.com/kazurayam/selenium-webdriver-java/commit/a2220880e88f5d56d51e9524c20c111c0f49242e
Now the compileTestJava
task passes completely:
:~/github/selenium-webdriver-java (kazurayam5work *)
$ gradle clean compileTestJava
...
BUILD SUCCESSFUL in 12s
16 actionable tasks: 16 executed
I have to confirm the modified Appium***Test
classes run appropriately. I will do that tomorro. It's late at night ...
After the issue #4 fixed, still I got the following comilation errors: