appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.2k stars 755 forks source link

Appium with Java: Selenium 4.11.0 Appium 8.6.0 , Could not start a new session. Response code 400. Message: Missing command parameter: appId #2202

Open johanrosabal opened 1 month ago

johanrosabal commented 1 month ago

Description

I'm trying to run a simple test with java maven project, I already have installed winAppDriver, but I'm getting the following Error on WinAppDriver

`HTTP/1.1 400 Bad Request Content-Length: 96 Content-Type: application/json

{"status":100,"value":{"error":"invalid argument","message":"Missing command parameter: appId"}}

========================================== POST /session HTTP/1.1 Accept: / Content-Length: 352 Content-Type: application/json; charset=utf-8 Host: 127.0.0.1:4723 User-Agent: appium/8.6.0 (selenium/4.13.0 (java windows)) X-Idempotency-Key: 4a972c32-fbeb-45f0-9cc2-5163d237b6af

HTTP/1.1 400 Bad Request Content-Length: 96 Content-Type: application/json`

Environment

Details

I use this link https://github.com/appium/java-client?tab=readme-ov-file#compatibility-matrix for the compatibility Issues, I don't understand the "appId" parameters,

Code To Reproduce Issue [ Good To Have ]

`import io.appium.java_client.windows.WindowsDriver; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test;

import java.net.MalformedURLException; import java.net.URL; import java.time.Duration; // https://github.com/appium/java-client?tab=readme-ov-file#compatibility-matrix public class CalculatorTest { private WindowsDriver driver; @BeforeClass public void setup() throws MalformedURLException {

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("app", "C:\\Windows\\System32\\notepad.exe");
    capabilities.setCapability("platformName", "Windows");
    capabilities.setCapability("deviceName", "WindowsPC");
    capabilities.setCapability("automationName", "Windows");
    driver = new WindowsDriver(new URL("http://127.0.0.1:4723/"), capabilities);
    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(2));
}

@Test
public void writeTest() {
    // Find the text area element and write "This is a test"
    WebElement editField = driver.findElement(By.id("Edit"));
    editField.sendKeys("This is a test");

    // Save the file
    driver.findElement(By.id("File")).click();
    driver.findElement(By.id("Save As...")).click();

    // Enter the file name
    WebElement fileNameField = driver.findElement(By.id("Edit"));
    fileNameField.sendKeys("testfile.txt");

    // Click the Save button
    driver.findElement(By.id("Save")).click();
}

@AfterClass
public void tearDown() {
    if (driver != null) {
        driver.quit();
    }
}

} `

Exception Stacktraces

this is the Log Error: org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 400. Message: Missing command parameter: appId Host info: host: 'DESKTOP-4NSBAV2', ip: '192.168.56.1' Build info: version: '4.13.0', revision: 'ba948ece5b*' System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.15' Driver info: io.appium.java_client.windows.WindowsDriver Command: [null, newSession {capabilities=[{appium:app=C:\Windows\System32\notepad.exe, appium:automationName=Windows, appium:deviceName=WindowsPC, platformName=windows}], desiredCapabilities=Capabilities {app: C:\Windows\System32\notepad..., automationName: Windows, deviceName: WindowsPC, platformName: windows}}] Capabilities {app: C:\Windows\System32\notepad..., automationName: Windows, deviceName: WindowsPC, platformName: windows}

itkhanz commented 1 month ago

This seems to be similar to following:-

Try initializing driver as below and see whether it resolved the issue:-

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("app", "C:\\Windows\\System32\\notepad.exe");
    capabilities.setCapability("platformName", "Windows");
    capabilities.setCapability("deviceName", "WindowsPC");
    capabilities.setCapability("automationName", "Windows");

    //driver = new WindowsDriver(new URL("http://127.0.0.1:4723/"), capabilities);

    HttpCommandExecutor exec = new HttpCommandExecutor(new URL("http://127.0.0.1:4723/"));
    driver  = new WindowsDriver(exec, capabilities);

I am not sure what is the underlying root cause, but I am guessing this happens because Appium changes "app" to "appium:app" and WinAppDriver is expecting "app" as WinAppDriver is not W3C Complaint.

lucasandre22 commented 1 month ago

Hey @johanrosabal, complementing the @itkhanz response, this error may occur when you try to run WinAppDriver with Appium java and Selenium 4. Make sure to use the appium-windows-driver in order to make WinAppDriver compatible with Selenium 4 and consequently, W3C standards.

johanrosabal commented 1 month ago

GitHub - appium/java-client: Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol https://github.com/appium/java-client?tab=readme-ov-file#compatibility-matrix

I use this link and try several versions as this information specify,

So, I don't what else to do, for example for Selenium 4.22 what version of the appium library did recommend ?

also i try with selenium 4.11 with 8.5.0.

So, i wonder if is possible that problem is the WinAppDriver version that I am using

[image: image.png]

El lun, 22 jul 2024 a la(s) 3:37 p.m., Lucas Almeida ( @.***) escribió:

Hey @johanrosabal https://github.com/johanrosabal, complementing the @itkhanz https://github.com/itkhanz response, this error may occur when you try to run WinAppDriver with Appium java and Selenium 4. Make sure to use the appium-windows-driver https://github.com/appium/appium-windows-driver in order to make WinAppDriver compatible with Selenium 4 and consequently, W3C standards.

— Reply to this email directly, view it on GitHub https://github.com/appium/java-client/issues/2202#issuecomment-2243857623, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABL77NVUIC67TRZABIAVFPLZNV3R7AVCNFSM6AAAAABLFUATVOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBTHA2TONRSGM . You are receiving this because you were mentioned.Message ID: @.***>

lucasandre22 commented 1 month ago

Take a look at the compatibility matrix of Appium Java Client and Selenium Client in Java. For example, you can use Appium 9.2.3 and Selenium 4.21.0. The problem is, if you are using Selenium 4 and Appium, you would need to use appium-windows-driver which is a proxy over WinAppDriver in order to support Selenium 4 commands.

johanrosabal commented 1 month ago

Hi Lucas,

The solution works for Java ? in the link that you provided I see an example for python. Did you have some example with JAVA ?

El lun, 22 jul 2024 a la(s) 3:51 p.m., Lucas Almeida ( @.***) escribió:

Take a look at the compatibility matrix of Appium Java Client and Selenium Client in Java https://github.com/appium/java-client?tab=readme-ov-file#compatibility-matrix . For example, you can use Appium 9.2.3 and Selenium 4.21.0. The problem is, if you are using Selenium 4 and Appium, you would need to use appium-windows-driver https://github.com/appium/appium-windows-driver which is a proxy over WinAppDriver in order to support Selenium 4 commands.

— Reply to this email directly, view it on GitHub https://github.com/appium/java-client/issues/2202#issuecomment-2243874365, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABL77NUSPUTOUFJZ6VXFUK3ZNV5E5AVCNFSM6AAAAABLFUATVOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBTHA3TIMZWGU . You are receiving this because you were mentioned.Message ID: @.***>