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

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.

Related

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.

Automating capture network traffic through browser mob proxy in 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);

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.

How to start the Appium server from command prompt in MAC machine?

I am automating ios native mobile application using appium. Until now I was launching the server from the Appium GUI by clicking on the Launch button. Now I want to start the server from a command prompt.
I was able to do the same in Windows machine by following the below steps:
Launch Node.js command prompt
Navigate till the Appium bin folder
Use the command node appium
I got blocked on how to start the Node.js command prompt on a Mac. Can you pleases tell me how I can start the Appium server from a command prompt on a Mac.
if you used npm install -g appium then you should be able to directly open one with the command
appium //plus any server args you want ex: appium -p 4474
Or you can still navigate to the folder of your node_modules and into appium and go with
node . //plus any server args you want
if you want to have additional server flags, all are available at their site with documentations.
Open the terminal and type in the following command
appium --address 127.0.0.1 --port 4723
Press enter then it will register itself to 127.0.0.1 and will listen 4723 port. You can extend this command by adding app type etc.
Hope this will help you
cheers
/Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js --address 127.0.0.1 --chromedriver-port 9516 --bootstrap-port 4725 --no-reset --local-timezone --command-timeout 7200 --session-override --debug-log-spacing --platform-version 9.0 --platform-name iOS --app /Users/chennareddy/u/apps/TestApp/build/release-iphonesimulator/Handstand/Handstand.app --show-ios-log --device-name iPhone-6s --native-instruments-lib --orientation Portrait
To start appium in MAC, all you need to do is to type => appium & in the terminal application. In order for the above command to work, you have to install appium in terminal mode. However there are 2 ways of doing it, one is with HomeBrew and the other directly with Node.js . You can find the tutorial of installing HomeBrew online. Follow the steps below to install it directly with node.js -
Go to https://nodejs.org/
Download and install the latest stable version of node.js package in your mac
Now open the terminal application
Run the following command => npm install -g appium
This should install Appium in your system with global privileges. After installation of appium, you can run the command => appium-doctor in the same terminal window to verify if everything is installed properly.
If everything is in green ticks, run => appium & to start the appium server
Hope this helped.
As other answers points out, if you have installed Appium thru terminal then simply type appium & on a terminal window to start appium server. Here all you need to know, how to install appium thru terminal.
1. Install Homebrew.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2. Give Following commands one by one to install appium
brew install node # get node.js
npm install -g appium # get appium
npm install wd # get appium client
appium & # start appium
You can find refer to step by guide for appium download osx here.
String tellCommand = "tell application \"Terminal\" to do script \"/usr/bin/node_modules/appium/bin/appium.js";
String parameters = " -p "+port;
parameters += " "+ (fullReset ? "--full-reset" : "--no-reset")+"\"";
tellCommand += parameters;
String[] command = { "osascript", "-e",
tellCommand };
ProcessBuilder pBuilder = new ProcessBuilder(command);
pBuilder.start();
Try this to launch your appium server programmatically for mac os, it includes automating the webkit debug proxy as well which is needed for debugging.
//customize the below in start server method
//Webkit Proxy command
CommandLine iOSProxyCommand = new CommandLine("ios_webkit_debug_proxy");
iOSProxyCommand.addArgument("-c");
iOSProxyCommand.addArgument(udid+":27753");//provide your udid of the device
iOSProxyCommand.addArgument("-F");//to disable console output in eclipse
DefaultExecuteResultHandler iOSProxyresultHandler = new DefaultExecuteResultHandler();
DefaultExecutor iOSProxyexecutor = new DefaultExecutor();
iOSProxyexecutor.setExitValue(1);
try {
iOSProxyexecutor.execute(iOSProxyCommand, iOSProxyresultHandler);
iOSProxyCommand.toString()));
Thread.sleep(5000);
System.out.println("iOS Proxy started.");
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
CommandLine command = new CommandLine(
"/Applications/Appium.app/Contents/Resources/node/bin/node");
command.addArgument( "/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js",
false);
command.addArgument("--address", false);
command.addArgument("127.0.0.1");
command.addArgument("--port", false);
command.addArgument("4723");
command.addArgument("--full-reset", false);
command.addArgument("--log-level", false);//to disable console output in eclipse
command.addArgument("error");
command.addArgument("--log", false);
Timestamp currentTimestamp = new java.sql.Timestamp(Calendar.getInstance().getTime().getTime());
command.addArgument("/Users/sethupandi/appium"+currentTimestamp+".log");
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
try {
executor.execute(command, resultHandler);
Thread.sleep(5000);
System.out.println("Appium server started.");
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//customize the below in stop appium server-
//kill appium node after end of your execution
String[] command = { "/usr/bin/killall", "-9", "node" };
try {
Runtime.getRuntime().exec(command);
System.out.println("Appium server stopped.");
} catch (IOException e) {
e.printStackTrace();
}
//Kill webkit proxy for iOS
String[] commandProxy = { "/usr/bin/killall", "-9", "ios_webkit_debug_proxy" };
try {
Runtime.getRuntime().exec(commandProxy);
System.out.println("iOS Webkit proxy stopped");
} catch (IOException e) {
e.printStackTrace();
}
For anybody reading this who happens to be using npm (node/js/typescript), I've created a module called appium-controller that starts and stops appium in the background programmatically (mac or windows). It has an option to pass in a specific port either through a node call to the method or through cli.

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