Goal : trying to capture network traffic from device(iPhone 6) safari browser (MobileWeb Testing). Request, Response, WebTimings from her file.
Environment:
Eclipse,Java 8
Mac - macOS Sierra 10.12.4
device - iPhone 6 (iOS 10.3.1)
BMP maven dependency -
<dependency>
<groupId>net.lightbody.bmp</groupId>
<artifactId>browsermob-core</artifactId>
<version>2.1.2</version>
<scope>test</scope>
</dependency>
<!-- existing LittleProxy dependency -->
<dependency>
<groupId>org.littleshoot</groupId>
<artifactId>littleproxy</artifactId>
<version>1.1.2</version>
</dependency>
Appium - <dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>4.1.2</version>
</dependency>
MITM - <dependency>
<groupId>net.lightbody.bmp</groupId>
<artifactId>mitm</artifactId>
<version>2.1.4</version>
</dependency>
WebDriverAgent - Build the WebDriverAgentApp
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'UDID' test
.Turn on Web Inspector on IOS Device. Go to Settings -> Safari -> Advanced -> Web inspector
. Install homebrew (The missing package manager for OS X)
. How to install homebrew - Type command in Terminal prompt. (You can open terminal by Finder. Open Finder (Finder is available in the Dock.) Select Applications. Then
chose Utilities. Double click on Terminal.) Now type below command:
cmd - “/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
. Install ios_webkit_debug_proxy. For accessing web views on real iOS device Appium uses this. To install the latest tagged version of the ios-webkit-debug-proxy using
Homebrew, run the following commands in the terminal prompt in given sequence:
a. brew update
b. brew install ios-webkit-debug-proxy
. ios_webkit_debug_proxy should be running and listening on port 27753. So after installing you can start the proxy with the following command in terminal:
a. ios_webkit_debug_proxy -c <Connected device UDID>:27753 –d
cmd - ios_webkit_debug_proxy -c UDID:27753 -d
. To be able to run your tests against mobile Safari we use the SafariLauncher App to launch Safari. Once Safari has been launched the Remote Debugger automatically
connects using the ios-webkit-debug-proxy. Here you should have a provisioning profile that can be used to deploy the SafariLauncherApp.
SafariLauncherApp –
Get SafariLauncher.app(.https://github.com/budhash/SafariLauncher1.4k)
Launch the SafariLauncher.app on connected device from Xcode.
Build the app, run tha app, copy the .app file to appium folder.
Success :
I am able to run the appium/java script to connect to iphone, launch webdriveragent followed by safarilauncher app.
Navigating to particular website.
Captured the network traffic BUT
Problem :
Not able to capture the secured calls (https) network calls.
I did install the BMP security certificate on device as well as on my mac. Trusted it.
Certificate from - https://github.com/lightbody/browsermob-proxy/tree/master/browsermob-core/src/main/resources/sslSupport
Any help would be appreciated.
// Create new proxy server
BrowserMobProxyServer server = new BrowserMobProxyServer();
server.setTrustAllServers(true);
server.setMitmDisabled(true);
server.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
server.start(51664);
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(server);
seleniumProxy.setProxyType(ProxyType.MANUAL);
seleniumProxy.setSslProxy("trustAllSSLCertificates");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
capabilities.setCapability("deviceName", "iPhone 6");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("platformVersion", "10.3.1");
capabilities.setCapability("browserName", "safari");
capabilities.setCapability("startIWDP", true);
capabilities.setCapability("udid", "auto");
capabilities.setCapability("automationName", "XCUITest");
capabilities.setCapability("xcodeOrgId", "BundleID");
capabilities.setCapability("xcodeSigningId", "iPhone Developer");
capabilities.setCapability("useNewWDA", true);
// Create Driver
// AppiumDriver driver = new AppiumDriver(new
// URL("http://0.0.0.0:4723/wd/hub"),desiredCapabilities);
try {
driver = new IOSDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(180, TimeUnit.SECONDS);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Create HAR File
server.newHar("test");
// Open website
driver.get("http://www.yahoo.com");
Thread.sleep(10000);
// get and save HAR
Har har = server.getHar();
HarLog log = har.getLog();
List<HarEntry> entries = new CopyOnWriteArrayList<HarEntry>(log.getEntries());
System.out.println(entries);
for (HarEntry entry : entries) {
System.out.println(entry.getRequest().getUrl());
}
readHar(har);
if (driver != null)
driver.quit();
server.stop();