I am trying to automate a hybrid app with Appium 1.7.1 and Java, iOS simulator.Xcode 8.3
So far I was able to launch the app and remove the notifications pop up but when trying to get the contexts an error is thrown in Appium:
[MJSONWP] Encountered internal error running command: Error: Could not connect to a valid app after 20 tries. at Object.wrappedLogger.errorAndThrow (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-support/lib/logging.js:63:13) at RemoteDebugger.selectApp$ (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-remote-debugger/lib/remote-debugger.js:259:6) at tryCatch (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40) at GeneratorFunctionPrototype.invoke [as _invoke] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22) at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21) at GeneratorFunctionPrototype.invoke (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37) [HTTP] <-- GET /wd/hub/session/c59dd263-05e2-439a-9f1e-c37389e38ada/contexts 500 136 ms - 219
And on the IDE:
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Could not connect to a valid app after 20 tries. (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds
Code:
package XYZ;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import jdk.internal.instrumentation.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.URL;
import java.util.Set;
/**
* Created by on 28/11/2017.
*/
public class AppSimulatorLaunch {
public AppiumDriver<MobileElement> driver;
@Before
public void setup() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPad Air 2");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.3");
capabilities.setCapability("nativeWebTap", true);
capabilities.setCapability("automationName", "XCUITest");
capabilities.setCapability("xcodeOrgId", "xyz");
capabilities.setCapability("xcodeSigningId", "iPhone Developer");
capabilities.setCapability("newCommandTimeout", "120");
capabilities.setCapability(MobileCapabilityType.APP, "/Users/user/Documents/xyz.app");
driver = new IOSDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.switchTo().alert().accept();
}
@After
public void tearDown() {
// driver.quit();
}
@Test
public void testCheckWebsite() throws InterruptedException {
Thread.sleep(5000);
Set<String> contextNames = driver.getContextHandles();
System.out.println("about to print the context list");
System.out.println(contextNames);
driver.context((String) contextNames.toArray()[1]);
driver.findElement(By.xpath("//*[@id=\"USER\"]")).sendKeys("t334658");
driver.findElement(By.xpath("//*[@id=\"PASSWORD\"]")).sendKeys("geenidee01");
driver.findElement(By.xpath("//*[@id=\"bouton1\"]")).click();
}
}
Any idea how to solve this? I've tried adding a thread.sleep as mentioned in https://github.com/appium/appium/issues/6825 but it does not seem to work either.
AutoTig
Set<String> contextNames = driver.getContextHandles();
? – Adelin