appium icon indicating copy to clipboard operation
appium copied to clipboard

What are the necessary changes to be done for iOS source code to see the "Webview" enabled in Hybrid App.

Open chethanshetty09 opened this issue 9 years ago • 13 comments

The problem

Detecting the WEBVIEW context in iOS hybrid app. IOSDRIVER class provides only NATIVE context and not WEBVIEW context

Environment

  • Appium version (or git revision) that exhibits the issue: 1.6.4
  • Desktop OS/version used to run Appium: MAC Captian 10.11.6
  • Mobile platform/version under test: iPhone 9.2.3
  • Real device or emulator/simulator: Real device
  • Appium CLI or Appium.app|exe: 1.0.0

Details

When i try to print the getcontext from IOSDriver class, the Webview context is not been returned by this class. Only "NATIVEVIEW" is printed. If same is followed in Android build i see WebVIEW and NATIVE been returned by respective driver class.

Do i need to make any changes to iOS source code before i generate an IPA file? Please help.

The code i am using to get or switch context is:

// Switching to iOS webview
IOSDriver<MobileElement> iosDriver = (IOSDriver<MobileElement>) appiumDriver;
Set<String> contextNames = iosDriver.getContextHandles();
for (String contextName : contextNames) {
    System.out.println(contextName); //prints out something like [NATIVE_APP, WEBVIEW_<APP_PKG_NAME>]
    if(contextName.contains("WEBVIEW")){
        iosDriver.context(contextName);
        System.out.println("Switched to: "+contextName);
        break;
    }
}
return iosDriver;

chethanshetty09 avatar Sep 03 '17 15:09 chethanshetty09

Please attach full server log

mykola-mokhnach avatar Sep 03 '17 15:09 mykola-mokhnach

Hi @chethanshetty09, Could you please check if you have ios_webkit_debug_proxy installed and if so what it returns when you run it from the Mac you have the device connected to? More information here: https://github.com/google/ios-webkit-debug-proxy

ochubey avatar Sep 04 '17 10:09 ochubey

Hi @ochubey, Webkit is already installed on mac. here is the log when i run the above command:

Listing devices on :9221
Connected :9222 to iphone 6s (<udid of the device>)

I feel there is some settings need to be done to make the ipa/app file enable webview context. But unfortunately i am able to detect the webview from Safari developer tool.

chethanshetty09 avatar Sep 07 '17 09:09 chethanshetty09

If you're able to rebuild an AUT - make sure to use -configuration Debug flag for xcodebuild, use development certificate/provisioning profile and during exporting use development method in plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>teamID</key>
        <string>{your team id that match correct provisioning profile,etc}</string>
        <key>method</key>
        <string>development</string>
        <key>uploadSymbols</key>
        <true/>
</dict>
</plist>

I use following command to build manualy: xcodebuild clean build -workspace ***.xcworkspace -scheme *** -configuration Debug -sdk iphoneos archive -archivePath ~/Desktop/ios_archives/***.xcarchive PROVISIONING_PROFILE_SPECIFIER="*** Debug Development" CODE_SIGN_IDENTITY="iPhone Developer: *** (***)" export: xcrun xcodebuild -exportArchive -exportOptionsPlist ~/Desktop/exportPlist.plist -archivePath ~/Desktop/ios_archives/***.xcarchive -exportPath ~/Desktop/ios_archives/***

In addition, sorry for being so obvious, please check if Safari on a device has Web Inspector enabled (according to your latest comment - it is enabled) and Enable UI Automation is enabled too.

ochubey avatar Sep 07 '17 11:09 ochubey

Yes, Web inspector on device Safari is ON and Enabled UI Automation. Even in Xcode the Edit scheme section i have enabled "Debug".

these all settings are done for the Build.

chethanshetty09 avatar Sep 07 '17 11:09 chethanshetty09

I added one Capability and then it worked. capabilities.setCapability("instrumentApp", "true"); 👍

Thanks.

chethanshetty09 avatar Sep 07 '17 12:09 chethanshetty09

@chethanshetty09 are you using Appium directly or using Experitest tools (such as Appium Studio)?

ochubey avatar Sep 07 '17 13:09 ochubey

using Appium Directly.

chethanshetty09 avatar Sep 07 '17 13:09 chethanshetty09

I don't think instrumentApp is a capability that Appium knows anything about, so I'm not sure why that would have helped. Where did you learn about this capability?

jlipps avatar Sep 07 '17 23:09 jlipps

@jlipps , I found this solution from Appium studio forum. Here is the link: http://appium.experitest.com/t/what-are-the-necessary-changes-to-be-done-for-ios-source-code-to-see-the-webview-enabled-in-hybrid-app/422

chethanshetty09 avatar Sep 08 '17 04:09 chethanshetty09

@chethanshetty09 I see. that must be an Experitest thing. It's not something that Appium itself knows anything about or does anything with. Anyway, glad to hear it's working!

jlipps avatar Sep 08 '17 23:09 jlipps

@jlipps , Yes it is for Experitest but i am not using Experitest and i am using the normal Appium server. This solution worked for me.

chethanshetty09 avatar Sep 11 '17 04:09 chethanshetty09

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Apr 25 '19 17:04 lock[bot]