Hello,
I'm quite new in automation, so I tried to do some simple example with starting notepad in combination with appium and winappdriver.
this is the code wich is used in java(Eclipse IDE)
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.MalformedURLException;
import java.net.URL;
import io.appium.java_client.windows.WindowsDriver;
public class WinAppDriverTest {
static WindowsDriver driver;
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub
DesiredCapabilities appCapabilities = new DesiredCapabilities(); //org.openqa.selenium.remote.DesiredCapabilities;
appCapabilities.setCapability("app", "C:\\Windows\\System32\\notepad.exe");
driver = new WindowsDriver(new URL("http://127.0.0.1:4723"), appCapabilities);
}
}
This is the contents of pom.xml file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.simple.automation</groupId>
<artifactId>MavenProjectSimple</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.10.0</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.5.1</version>
</dependency>
</dependencies>
</project>
If I trie to execute the java file I get some Error message in console
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 400. Message: Bad capabilities. Specify either app or appTopLevelWindow to create a session
Host info: host: 'DESKTOP-someName', ip: '170.25.221.122'
Build info: version: '4.10.0', revision: 'c14d967899'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.8'
Driver info: io.appium.java_client.windows.WindowsDriver
Command: [null, newSession {capabilities=[{appium:app=C:\Windows\System32\notepad.exe, appium:automationName=Windows, platformName=windows}], desiredCapabilities=Capabilities {app: C:\Windows\System32\notepad..., appium:automationName: Windows, platformName: windows}}]
Capabilities {app: C:\Windows\System32\notepad..., appium:automationName: Windows, platformName: windows}
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:140)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:133)
at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:102)
at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:182)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:531)
at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:274)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:154)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:89)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:101)
at io.appium.java_client.windows.WindowsDriver.<init>(WindowsDriver.java:50)
at WinAppDriverTest.main(WinAppDriverTest.java:19)
in WinAppDriver I can see this message
Windows Application Driver listening for requests at: http://127.0.0.1:4723/
Press ENTER to exit.
==========================================
POST /session HTTP/1.1
Accept: */*
Content-Length: 229
Content-Type: application/json; charset=utf-8
Host: 127.0.0.1:4723
User-Agent: appium/8.5.1 (selenium/4.10.0 (java windows))
X-Idempotency-Key: 30ebcf38-12e5-45d9-8461-b307b5c6c7d9
{
"capabilities": {
"firstMatch": [
{
}
],
"alwaysMatch": {
"appium:app": "C:\\Windows\\System32\\notepad.exe",
"appium:automationName": "Windows",
"platformName": "windows"
}
}
}
HTTP/1.1 400 Bad Request
Content-Length: 141
Content-Type: application/json
{"status":100,"value":{"error":"invalid argument","message":"Bad capabilities. Specify either app or appTopLevelWindow to create a session"}}
Thank you for advice
I have also replace in java replaced ip adresse with some other ip which I can see in cmd -> ipconfig But it didn't solved my problem
driver = new WindowsDriver(new URL("http://127.0.0.1:4723"), appCapabilities);