I have a Cordova app that I want to automate tests on with Appium, in the iOS Simulator. My C# code looks like this (some stuff omitted):
public IOSDriver<IWebElement> driver;
string webviewContext = null;
[SetUp]
public void Class1()
{
//Setting Capabilities
AppiumOptions capabilities = new AppiumOptions();
capabilities.AddAdditionalCapability("platformName", "iOS");
capabilities.AddAdditionalCapability("platformVersion", "14.5");
//capabilities.AddAdditionalCapability("deviceName", "iPhone 12 Pro Max");
capabilities.AddAdditionalCapability("deviceName", "iPad (8th generation)");
capabilities.AddAdditionalCapability("automationName", "XCUITest");
capabilities.AddAdditionalCapability("platform", "iOS");
// capabilities.AddAdditionalCapability("autoWebview", true);
capabilities.AddAdditionalCapability("instrumentApp", true);
capabilities.AddAdditionalCapability("webviewConnectTimeout", 1000);
capabilities.AddAdditionalCapability("app", "/Users/matt/Documents/platform-prototype/FreshGradeClient/built/cordova/debug/obj/platforms/ios/build/emulator/FreshGrade-Stage.app");
//Connecting to Appium Server
driver = new IOSDriver<IWebElement>(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities, TimeSpan.FromSeconds(180));
var contexts = ((IContextAware)driver).Contexts;
for (int i = 0; i < contexts.Count; i++) {
if (contexts[i].Contains("WEBVIEW"))
{
webviewContext = contexts[i];
break;
}
}
Assert.IsNotNull(webviewContext);
}
In my test, a couple of button click actions happen successfully. Then in my test where I want to switch to the WEBVIEW context I have:
driver.Context = webviewContext;
When this line is executed, the following error occurs:
NUnit Adapter 4.0.0.0: Test execution complete
----- Test Execution Summary -----
MobileTest.Test.VerifySignUp:
Outcome: Failed
Error Message:
System.NotImplementedException : The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
Stack Trace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Appium.AppiumDriver`1.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Appium.AppiumDriver`1.set_Context(String value)
at MobileTest.Test.VerifySignUp() in /Users/matt/Documents/Appium (the original)/unittest2.cs:line 88
Line 88 is the line where I’m trying to set the driver’s context. Any help would be appreciated, I’ve googled the hell out of this and nothing.
UPDATE: Looking at the Appium server logs, I see:
[WD Proxy] Proxying [POST /wd/hub/session/0c8cedbb-d922-450a-ae3a-e1b63089c618/element/15000000-0000-0000-AF3D-010000000000/click] to [POST http://127.0.0.1:8100/session/C2A2761E-1500-47E3-B283-6B11758A738B/element/15000000-0000-0000-AF3D-010000000000/click] with body: {}
[WD Proxy] Got response with status 200: {"value":null,"sessionId":"C2A2761E-1500-47E3-B283-6B11758A738B"}
[WD Proxy] Replacing sessionId C2A2761E-1500-47E3-B283-6B11758A738B with 0c8cedbb-d922-450a-ae3a-e1b63089c618
[HTTP] <-- POST /wd/hub/session/0c8cedbb-d922-450a-ae3a-e1b63089c618/element/15000000-0000-0000-AF3D-010000000000/click 200 226 ms - 65
[HTTP]
[HTTP] --> POST /wd/hub/session/0c8cedbb-d922-450a-ae3a-e1b63089c618/contexts
[HTTP] {"name":"WEBVIEW_81320.2"}
[HTTP] No route found for /wd/hub/session/0c8cedbb-d922-450a-ae3a-e1b63089c618/contexts
[HTTP] <-- POST /wd/hub/session/0c8cedbb-d922-450a-ae3a-e1b63089c618/contexts 404 5 ms - 262
[HTTP]
UPDATE: When I try to set driver.Context, the driver is attempting to POST to /wd/hub/session/<sessionId>/contexts
, but that URL is incorrect: it should be /wd/hub/session/<sessionId>/context
(without the “s”). I had to perform a manual HTTP request to the server using the correct URL.