Not able to create first program in Eclipse with Selenium using Appium - eclipse

I am not able to do automation testing with Appium server by using Eclipse with Selenium. I have shared below Eclipse error and Appium server logs also. I have shared Eclipse error also as below:
Error: You need the android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS permission to use the PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS flag
Please check below code in Eclipse:
package tests;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
public class StartChrome {
public static void main(String[] args) {
// Set the Desired Capabilities
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "My Phone");
caps.setCapability("udid", "7970dc54"); // Give Device ID of your mobile phone
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "9 PKQ1.180904.001");
caps.setCapability("appPackage", "com.android.vending");
caps.setCapability("appActivity", "com.google.android.finsky.activities.MainActivity");
caps.setCapability("noReset", "true");
// Instantiate Appium Driver
try {
AppiumDriver<MobileElement> Driver = new AndroidDriver<MobileElement>(
new URL("http://0.0.0.0:4723/wd/hub"), caps);
} catch (MalformedURLException e) {
System.out.println(e.getMessage());
}
}
}

It looks like you haven't actually started your Appium server yet. You can't instantiate a new AndroidDriver without starting the Appium server.
Above the line // Set the Desired Capabilities, add this:
// start appium service
AppiumServiceBuilder builder = new AppiumServiceBuilder();
AppiumLocalService _appiumLocalService = builder.UsingAnyFreePort().Build();
_appiumLocalService.Start();
You'll also need to update the line
AppiumDriver<MobileElement> Driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);
to
AppiumDriver<MobileElement> Driver = new AndroidDriver<MobileElement>(_appiumLocalService.ServiceUrl, caps);
That way, you are using the correct service URL that you Appium service was started on.
Additionally, you should also make sure the following settings on your Android device are also enabled:
Developer mode ON -- tap build number 7 times
USB Debugging ENABLED
Select USB configuration -- change from Charging to Picture Transfer Protocol or MIDI
Make sure your device is appearing when you run adb devices command. I only needed to enable the first two options -- developer mode & USB debugging -- to get mine working.

Related

Has the Webdriver support to set proxy in the driver instance removed? Unable to set proxy in driver using desired capability

I have the following code:
public class LoadBrowserAndSurf {
#Test
public void loadAndSurf() {
System.setProperty("webdriver.chrome.driver", "D:\\Desktop\\Automation Requirements\\chromedriver\\chromedriver.exe");
String proxyString= "13.228.117.219";
Proxy proxy = new Proxy();
proxy.setHttpProxy(proxyString);
DesiredCapabilities browserProxy =new DesiredCapabilities();
browserProxy.setCapability(CapabilityType.PROXY,proxy);
WebDriver wd = new ChromeDriver(browserProxy);
wd.get("http://www.globe.com.ph/");
}
}
In eclipse oxygen this code is able to initiate the driver version, however it is not accessing the proxy.
When try I the same code in the IntelliJ editor, it strikes out the ChromeDriver in the driver object initiation line i.e:
WebDriver wd = new ChromeDriver(browserProxy);
And states message as:
ChromeDriver(org.openqa.selenium.Capabilities) is depricated
Is there a way I can add this proxy in the driver instance when it launches in runtime?

Running IE using selenium webdriver

I would appreciate if someone could help with the code below
package IEProjects;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class startIE {
public static void main(String[] args) {
System.setProperty("webdriver.ie.driver", "C:\\IEDriverServer_Win32_3.3.0\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.google.com");
}
}
And am getting the below results
Started InternetExplorerDriver server (32-bit)
3.3.0.0
Listening on port 29209
Only local connections are allowed
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unexpected error launching Internet Explorer. Browser zoom level was set to 150%. It should be set to 100% (WARNING: The server did not provide any stacktrace information)
It launches IE and didnt perform the action. Below is what is printed on the IE page
This is the initial start page for the WebDriver server. http://localhost:41380/
The error message is descriptive enough, there is a set of pre-requisites to the IEDriver:
https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration
Notice:
The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.

I am getting this error "Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure."

While executing this code, it generates an error for chrome which timed out waiting for driver server to start.
package pkg;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class ClassLogin {
private WebDriver driver;
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
driver = new ChromeDriver();
driver.get("www.xyz.com");
driver.manage().window().maximize();
}
}
webdriver.chrome.driver needs to be set to a path to chromedriver.exe and not chrome.exe.
You may need to download ChromeDriver - WebDriver for Chrome and then set there system property appropriately.

How to configure the Genymotion emulator to the appium?

Through eclipse I have configured the Genymotion path & also I have downloaded the virtual devices in the Genymotion.
In Appium, those downloaded virtual devices are visible in the"Launch Device" dropdown menu. Then I set the apk path & try to start the Appium 1.3.4.1.
By that time I am getting an error message like
Starting Node Server
usage: main.js [-h] [-v] [--shell]
main.js: error: Unrecognized arguments: Nexus 5 - 4.4.4 - API 19 - 1080x1920.
[--localizable-strings-dir LOCALIZABLESTRINGSDIR] [--app APP]
[--ipa IPA] [-U UDID] [-a ADDRESS] [-p PORT]
[-ca CALLBACKADDRESS] [-cp CALLBACKPORT] [-bp BOOTSTRAPPORT]
[-k] [-r BACKENDRETRIES] [--session-override] [--full-reset]
[--no-reset] [-l] [-lt LAUNCHTIMEOUT] [-g LOG]
[--log-level {info,info:debug,info:info,info:warn,info:error,warn,warn:debug,warn:info,warn:warn,warn:error,error,error:debug,error:info,error:warn,error:error,debug,debug:debug,debug:info,debug:warn,debug:error}]
[--log-timestamp] [--local-timezone] [--log-no-colors]
[-G WEBHOOK] [--native-instruments-lib]
[--app-pkg ANDROIDPACKAGE] [--app-activity ANDROIDACTIVITY]
[--app-wait-package ANDROIDWAITPACKAGE]
[--app-wait-activity ANDROIDWAITACTIVITY]
[--android-coverage ANDROIDCOVERAGE] [--avd AVD]
[--avd-args AVDARGS]
[--device-ready-timeout ANDROIDDEVICEREADYTIMEOUT] [--safari]
[--device-name DEVICENAME] [--platform-name PLATFORMNAME]
[--platform-version PLATFORMVERSION]
[--automation-name AUTOMATIONNAME] [--browser-name BROWSERNAME]
[--default-device] [--force-iphone] [--force-ipad]
[--language LANGUAGE] [--locale LOCALE]
[--calendar-format CALENDARFORMAT] [--orientation ORIENTATION]
[--tracetemplate AUTOMATIONTRACETEMPLATEPATH] [--show-sim-log]
[--show-ios-log] [--nodeconfig NODECONFIG] [-ra ROBOTADDRESS]
[-rp ROBOTPORT] [--selendroid-port SELENDROIDPORT]
[--chromedriver-port CHROMEDRIVERPORT]
[--chromedriver-executable CHROMEDRIVEREXECUTABLE]
[--use-keystore] [--keystore-path KEYSTOREPATH]
[--keystore-password KEYSTOREPASSWORD] [--key-alias KEYALIAS]
[--key-password KEYPASSWORD] [--show-config] [--no-perms-check]
[--command-timeout DEFAULTCOMMANDTIMEOUT] [--keep-keychains]
[--strict-caps] [--isolate-sim-device] [--tmp TMPDIR]
[--trace-dir TRACEDIR] [--intent-action INTENTACTION]
[--intent-category INTENTCATEGORY] [--intent-flags INTENTFLAGS]
[--intent-args OPTIONALINTENTARGUMENTS]
Node Server Process Ended
When I try to run with normal emulator in Android SDK it works well.
But I want to run it with Genymotion emulator. How to do? I'm stuck up here.
My questions are:
Whether the additional emulator will work in appium windows or not?
What I need to give in the "Argument" field under appium?
The following code works for the above question.
static String deviceName = "Google Nexus 5 - 4.4.4 - API 19 - 1080x1920";
public static void main(String[] args) throws InterruptedException, ExecuteException, IOException {
DesiredCapabilities capabilities = new DesiredCapabilities();
DefaultExecutor executor = new DefaultExecutor();
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
CommandLine launchEmul = new CommandLine("C:/Program Files/Genymobile/Genymotion/player");
launchEmul.addArgument("--vm-name");
launchEmul.addArgument("\""+deviceName+"\"");
executor.setExitValue(1);
executor.execute(launchEmul, resultHandler);
Thread.sleep(40);
capabilities.setCapability("deviceName","Google Nexus 5 - 4.4.4 API 19 - 1080x1920");
capabilities.setCapability("platformVersion", "4.3");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app","D:/SOFTWARES/Apks/GOA.apk");
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
System.out.println("SetUp is successful and Appium Driver is launched successfully");
}
Recently i i've used genymotion and appium and worked fine
1-i've installed appium(i've tried windows and console version succesfully)
2-i've installed genymotion and created a virtual device in it
3-launched virtual device from genymotion
4-in my test, when i defined driver capabilities, i didnt identified a specific virtual device, so, appium try to identify any active device(virtual or not)
try that and let me know if worked to help in anything i could

Netbeans Run->Stop Build does not stop the running java processes

I'm using Netbeans 7.1.2 on Mac OS X Lion 10.7.3.
I have a simple java server (using netty) project and after I build and run the project then try to stop the running by Run->Stop Build it does not terminate the java server process.
For example, my server app uses port 8080 and even after I stop running from the netbeans the port 8080 is in use and the app keeps running. I have to manually kill the java process from activity monitor.
What's the correct procedure to end the running app started by Netbeans?
Greatly appreciate your help. Thanks in advanced.
Have a look at the documentation: http://netty.io/docs/stable/guide/html/. Scroll down to section 9. Shutting Down Your Application.
Your main app ahs to look something like:
package org.jboss.netty.example.time;
public class TimeServer {
static final ChannelGroup allChannels = new DefaultChannelGroup("time-server"(35));
public static void main(String[] args) throws Exception {
...
ChannelFactory factory = ...;
ServerBootstrap bootstrap = ...;
...
Channel channel = bootstrap.bind(...);
allChannels.add(channel);
...
// Shutdown code
ChannelGroupFuture future = allChannels.close();
future.awaitUninterruptibly();
factory.releaseExternalResources();
}
}
You handler needs:
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) {
TimeServer.allChannels.add(e.getChannel());
}
You have to:
1. Store all your channels in a ChannelGroup
2. When shutting down, close all channel and release resources.
Hope this helps.