Automating capture network traffic through browser mob proxy in Appium - appium

I am having trouble getting Browsermob proxy to capture network traffic.
I am using Appium to write tests in android app. I want to use Browser mob proxy to capture and verify network calls. Browser mob proxy is being started at port 19536. I am using a shell script to turn Mac proxy on at port 19536.
Below is the code I am using but I can't see any network requests in the HAR file. Its pretty much empty.
Can someone help? TIA.
Code
//Start Proxy Server
server = new BrowserMobProxyServer();
server.start(19536);
//Turn Mac http Proxy on
Global.runShellCmdWithArg("/usr/local/bin/webproxy.sh", "on");
// get the Selenium proxy object
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(server);
File appDir = new File("/build/outputs/apk/");
File app = new File(appDir, "Demo-debug.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","Android Emulator");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "5.1");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.test");
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
server.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.REQUEST_BINARY_CONTENT);
server.newHar("newHar");
testApp = new DemoAppPage(driver);
wait = new WebDriverWait(driver, 30);
testApp.clickGetStarted();
testApp.clickButton();
// Get the HAR data
Har har = server.getHar();
File harFile = new File("test.har");
har.writeTo(harFile);

Related

Getting an error on Sauce labs when trying to iOS native app : Error: Infrastructure Error -- The Sauce VMs failed to start the browser or device

Here is my DesiredCapability. Trying to run native app.
Uploading the build from Saucelabs -> Live UI
tried a curl command as well
MutableCapabilities sauceOpts = new MutableCapabilities();
// sauceOpts.setCapability("name", methodName);
sauceOpts.setCapability("build", "zzzz");
sauceOpts.setCapability("appiumVersion", "1.19.2");
sauceOpts.setCapability("username", "zzzz");
sauceOpts.setCapability("accessKey", "abcd");
DesiredCapabilities caps = DesiredCapabilities.iphone();
caps.setCapability("sauce:options", sauceOpts);
caps.setCapability("automationName", automationName);
caps.setCapability("deviceName","iPhone 7 Plus Simulator");
caps.setCapability("deviceOrientation", "portrait");
caps.setCapability("platformVersion","13.0");
caps.setCapability("platformName", "iOS");
caps.setCapability("browserName", "");
caps.setCapability("app","storage:filename=zzzz.zip");
// caps.setCapability("appium:autoAcceptAlerts", true);
driver = DriverConfig.getInstance().setDriver(new IOSDriver(new URL("https://zzzz:zzzz#ondemand.eu-central-1.saucelabs.com:443/wd/hub"), caps));

A new session could not be created exception occurs

i will try to open chrome browser & automate the facebook (try to open any site so that i can check my appium configuration is ok or not)
After execution of following code got exception as,
#Test
public void test1() throws MalformedURLException
{
DesiredCapabilities capabilities=DesiredCapabilities.android();
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, BrowserType.CHROME);
capabilities.setCapability(MobileCapabilityType.PLATFORM, Platform.ANDROID);
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "my phone");
capabilities.setCapability(MobileCapabilityType.VERSION, "6.0.1");
URL url=new URL("http://127.0.0.1:4727/wd/hub");
//java.net.URL url=new URL("http://127.0.0.1:4727/wd/hub");
//URL url=new URL("http://127.0.0.1:4727/wd/hub");
WebDriver driver=new AndroidDriver(url, capabilities);
//WebDriver driver = new RemoteWebDriver(new URL( http://****:4723/wd/hub), capabilities);
// WebDriver driver = new RemoteWebDriver(new URL("http://****:4723/wd/hub", capabilities);
//driver.get("http://www.yahoo.com");
driver.get("https://www.facebook.com/");
System.out.println(driver.getTitle());
exception as,
#BeforeTest setUp org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: An unknown server-side error occurred while processing the command. (Original error: unknown error: Device 4e89be7c is not online (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=Windows NT 10.0 x86_64))) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 9.05 seconds Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
please help
I see in the stacktrace that "Device 4e89be7c is not online"
I'm pretty sure that you avd is open and running so please time in terminal "adb devices"
if your avd is shown and its status is "offline" then type:
"adb kill-server"
IMPORTANT: Close any instances of adb in the Task Manager
now type in terminal "adb start-server" and "adb devices" -> if the status of the adb has changed, you are good to go.

desired capabilities not recognized by appium

My desired capabilities from code are like below:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.VERSION, "4.4.2");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,
"Android");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,
"Android emulator");
capabilities
.setCapability(MobileCapabilityType.BROWSER_NAME, "Browser");
try {
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),
capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
driver.navigate().to("http://google.com");
My appium server debug info is showing below lines:
> info: --> POST /wd/hub/session {"desiredCapabilities":{"browserName":"Browser","platformName":"Android","version":"5.1.1","deviceName":"Android emulator"}}
> info: Client User-Agent string: Apache-HttpClient/4.3.3 (java 1.5)
> info: [debug] The following desired capabilities were provided, but not recognized by appium. They will be passed on to any other services running on this server. : version
Note: I have the AVD started with the same desired capabilities. Still it is showing the same message. And browser is opened in one of the already started AVD randomly.
Thanks in advance.
Please change capabilities.setCapability(MobileCapabilityType.VERSION, "4.4.2");
to capabilities.setCapability(MobileCapabilityType.VERSION, "1.1.0");
Please verify that your simulator name is "Android emulator" and not something else.
Also I don't see APP_PACKAGE and APP_ACTIVITY capabilities.

Appium Server not connected and throwing org.openqa.selenium.remote.UnreachableBrowserException

I have recently started mobile devices automation on appium with the java language.
I am trying to run the initial setup code through program it is returning this failure message.
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused: connect
When Manual run Appium server it doesn't have any errors and server started; the android apk file is installed.
Below is my code; Eclipse doesn't show any errors. I use Android Emulator for this Initial test. Appium and Java Project code in same host machine.
public void setup() throws MalformedURLException {
WebDriver AppWebDriver = null;
AppiumDriver ApUMDriver = null;
AndroidDriver AppiumURLDriver;
URL Serverurl;
// TODO Auto-generated method stub
DesiredCapabilities Appiumcapabiliy = new DesiredCapabilities();
File appDir = new File("c:\ApkbuildsDir");
File app = new File(appDir, "xxx.apk");
Appiumcapabiliy.setCapability("devicename","Device11");
Appiumcapabiliy.setCapability("platformname","Android");
Appiumcapabiliy.setCapability("platformVersion","4.2.2");
Appiumcapabiliy.setCapability("app-package","packagename");
Appiumcapabiliy.setCapability("app-activity","activityscreen");
Appiumcapabiliy.setCapability("app", app.getAbsolutePath());
Serverurl = new URL("http://127.0.0.1:4723/wd/hub");
AppWebDriver = new AndroidDriver(Serverurl,Appiumcapabiliy);
AppWebDriver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
ApUMDriver.findElement(By.name("My Card"));
}
Could you please guide me how to eliminate this server connect error through program.
Regards, Kiran
Looks like "Appium server" instance is NOT running in your machine. That is, http://127.0.0.1:4723/wd/hub
Please start the Appium server on 4723 port and try execute your code.

Not able to open HTTPS URL in IOS Simulator with appium and Selenium WebDriver

I am using Appium with Selenium WebDriver for automating my web application(having SSL certificate with https in the application url). i am using below code for IPad Simulator.
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS");
capabilities.setCapability(CapabilityType.VERSION, "6.1");
capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
capabilities.setCapability("device", "iPad");
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, true);
//Create an instance of RemoteWebDriver and connect to the Appium server.
driver = new RemoteWebDriver(new URL("http://localhost:4723/wd/hub"), capabilities);
But still when i execute my automation script it is not able to open the application url in the IPad simulator.
Can anyone please help me in how to solve this issue.
Thanks in Advance!!
If you are using Appium 1.0+, a number of changes needs to be done with your DesiredCapabilities :
Please match your cap sets with below:
Few Important Points:
Double check the IP & PORT on which Appium server started and mention the same while passing to RemoteWebDriver.
public void setUp() throws Exception
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "iPhone Simulator");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("platformVersion", "7.1");
capabilities.setCapability("browserName", "safari");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),
capabilities);
}
A few corrections to your DesiredCapabilities:
Browser Name should be Safari
Platform Name should be iOS
And shouldn't the URL of your RemoteWebDriver be http://0.0.0.0:4723/wd/hub?
Please review the desired capabilities spec
And after you make those corrections, if you try going to http://www.google.com, does it work?

Resources