1
votes

I was trying to automate the hybrid app build using ionic2/Angular2 and typescript.

I am using C# for code writing. test are in BDD - specflow Versions: iOS:9.3.1 Xcode: 7.3 Appium: 1.4.13

I am not able to identify elements after swtiching Context to WEBVIEW.

Calling IOSDriver using below code

private IOSDriver<IOSElement> driver = null;

public IOSDriver<IOSElement> GetDriver(string platformVersion, string deviceName, string udid ,string appPath, string serverUri)
{
    Capabilities iosCapabilities = new Capabilities();
    DesiredCapabilities capabilities = iosCapabilities.Get(platformVersion, deviceName, udid, appPath);
    driver = new IOSDriver<IOSElement>(new Uri(serverUri), capabilities, TimeSpan.FromSeconds(Constants.DriverWaitTime));
    driver.Manage ().Timeouts ().ImplicitlyWait (TimeSpan.FromSeconds(Constants.ImplicitWaitTime));

    var contextNames = driver.Contexts;
    driver.Context = contextNames[1];

    driver.FindElement(By.Xpath(locator)).Click();

}

Setting Capabilities as

private DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.SetCapability ("appium-version", Constants.AppiumVersion);
capabilities.SetCapability ("platformName", Constants.PlatformName);
capabilities.SetCapability("autoWebView", "true");
capabilities.SetCapability("browserName", "iOS");
capabilities.SetCapability ("platformVersion", Constants.PlatformVersion);
capabilities.SetCapability("deviceName", deviceName);
capabilities.SetCapability("app", appPath);
capabilities.SetCapability("udid", udid);

Am I setting the capabilities in correct way?

  1. Solution tried:
    1. I checked using browserName capbility as blank/safari but didn't worked
    2. Also, I installed ios-webkit-debug-proxy and started proxy using terminal in background on my mac
  2. Problem is i am not able to identify elements in WEBVIEW.

What I am doing

After launching the app, in appium inspector I am able to see all the elements and I am trying to click on textbox to enter some value

Xpath of textbox(as i can view in appium inspector window): "//UIAApplication1/UIAWindow1/UIAScrollView2/UIAWebView1/UIATextField1"

var contextNames = driver.Contexts

is giving me list to views(In my case 2 views: NATIVE_APP, WEBVIEW_1) WebView context is dynamically updating from 1,2,3 and so on..

As soon as I call

diver.Context=contextNames[1]; //setting context to WEBVIEW

and refresh the appium inspector I am not able to see/identify single element.Everything goes away.

Why I am not able to see/identify elements after switching to webview. (Note: As soon as I Switch back to driver.Context="NATIVE_APP" every element becomes visible in appium inspector but still I am not able to click)

It shows error as "An element could not be located using given search parameter"

Manually also when I try to tap or sendkeys using appium inspector it is not letting me do so(after lauching tha app manually using inspector button). What is the issue here. Help would be highly appreciated

Screenshot of Appium inspector:

enter image description here

Error message as displayed in appium window:

enter image description here

Here are the full logs of Appium(ERROR)

Link of Appium logs when not able to identify elements in WEBVIEW

3
please split this into sub parts, seems too long to be answered at once OR format properly to get to know your queriesNaman
Basically I am trying to identify the elements present in webview(my app is hybrid) after swtiching from default context to "WEBVIEW" but not able to do soSuraj Gupta

3 Answers

1
votes
  1. Continues of from here : How to enable and use WebView for iOS Automation in Appium

Try and use the following code to switch contexts :

var contextNames = driver.GetContexts(); //correction to your code 
driver.SetContext(contextNames[1]);
  1. You don't necessarily need the following capability while using appium :

    capabilities.SetCapability("browserName", "iOS"); //can be removed from code as well
    
  2. I am guessing you might be trying to use Appium Inspector along with running/debugging your tests. In which case you might not be able to use both the instances. Please look into the appium server logs for details on this.

0
votes

I think you have to Set up UICatalog in Appium

  1. Copy this link in xcode : https://github.com/appium/ios-uicatalog

  2. Search the repository where we have the UICatalog.app installed Users/Library/Developer/Xcode/DerivedData/UICatalog-bhmtevqhmgarbcgnqybxttbkqfvn/Build/Products/Debug-iphonesimulator/UICatalog.app

  3. Copy it into app path in Appium ios settings
0
votes

1) While access ios webview -- using getcontextHandles we can achieve

Set contextNames = idriver.getContextHandles();

System.out.println(contextNames);

for (String contextName : contextNames) {
  if (contextName.contains("NATIVE_APP")) {
    Reporter.log("Reaching to Native App", true);
    idriver.context(contextName);
    sleepfor(1000);
    idriver.findElementByName("Open").click();
    Reporter.log("Clicking Open to naviagte to Native APP", true);
  }
  else{
    Reporter.log("Not found", true);
  }
}

2) If above context doesn't work -- try to run iproxy run this in terminal -- ios_webkit_debug_proxy -c deviceID:27753 -d deviceID -- to get device id (instruments -s devices)