I am new to winAppDriver and was trying what was taught on one of the tutorial. However, I am getting 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 exception.
package openWindowsApps;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.appium.java_client.windows.WindowsDriver;
import io.appium.java_client.windows.options.WindowsOptions;
public class OpenCalculator {
private WindowsDriver windowsDriver;
@BeforeTest
public void openCalculator() throws InterruptedException, MalformedURLException {
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("app", "C:\\Windows\\System32\\calc.exe");
// desiredCapabilities.setCapability("app",
// "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
desiredCapabilities.setCapability("platformname", "Windows");
desiredCapabilities.setCapability("deviceName", "WindowsPc");
windowsDriver = new WindowsDriver(new URL("http://127.0.0.1:4723"), desiredCapabilities);
windowsDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(20));
}
@Test
public void clickOnButtons() {
System.out.println("Clicking on buttons");
}
@AfterTest
public void tearDown() {
windowsDriver.quit();
}
}
P.S: I have downloaded the WinAppDriver.exe and was trying to automate opening the calculator app. I also heard that WinAppDriver does not work with Selenium 4 hence have used selenium 3.
Edit: I am also not getting driver.findElement(By.AccessibilityId) on autosuggestion even though I have installed the following dependency.
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>9.1.0</version>
</dependency>