Using Appium, How to run Chrome browser in an emulator? - android-emulator

Appium Version : 1.0.0
DesiredCapabilities cap=new DesiredCapabilities();
cap.setCapability(CapabilityType.PLATFORM, MobilePlatform.ANDROID);
cap.setCapability(MobileCapabilityType.DEVICE_NAME,"emulator-5554");
cap.setCapability(MobileCapabilityType.BROWSER_NAME,"Chrome");
cap.setCapability("apppackage","com.anroid.chrome");
cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT,"100");
AndroidDriver<AndroidElement> driver=new AndroidDriver<AndroidElement>(new URL("http://0.0.0.0:4723/wd/hub"),cap);
driver.get("https://www.google.co.in");

This configuration works for me: Appium server 1.7.1, java-client 5.0.4
DesiredCapabilities cap=new DesiredCapabilities();
cap.setCapability(CapabilityType.PLATFORM, MobilePlatform.ANDROID);
cap.setCapability(MobileCapabilityType.DEVICE_NAME,"emulator-5554");
cap.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.BROWSER);
AndroidDriver<MobileElement> driver = new AndroidDriver<>(
new URL("http://127.0.0.1:4723/wd/hub"), caps);
driver.get("https://www.google.co.in");
In this case, default browser will be used. If you want chrome, make sure it is pre-installed on emulator
If it is, you may use MobileBrowserType.CHROME

Related

Issue in setting up the Android emulator with React native

I am fairly new to React native and trying to set up Android environment with Visual studio. All the installation has been fairly successful, however, when I try to run the sample app on the android emulator executing the npx react-native run-android command it shows below error -
'C:\Users\Home' is not recognized as an internal or external command,
operable program or batch file.
error Failed to launch emulator. Reason: Could not start emulator within 30 seconds..
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
at org.codehaus.groovy.vmplugin.VMPluginFactory.<clinit>(VMPluginFactory.java:43)
at org.codehaus.groovy.reflection.GroovyClassValueFactory.<clinit>(GroovyClassValueFactory.java:35)
at org.codehaus.groovy.reflection.ClassInfo.<clinit>(ClassInfo.java:109)
However, when i execute adb devices on visual studio, it shows the list of emulator connected -
List of devices attached
emulator-5554 device
What could be the possible reason? Is this because my users name is Home PC? (Is this because there is a space in between) and it is not able to get the correct path?
This is because your java version is updated to the latest version and gradle is not supported with the installed version. what you can do is update the gradle as well
So go to gradle/wrapper folder inside the android folder
Edit gradle-wrapper.properties file and replace distributionUrl
with following value
https\://services.gradle.org/distributions/gradle-6.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
I too faced the same issue.The problem is with the JDK. From JDK 14 i downgraded to JDK 11(LTS) version. And it worked.
Hope it helps.
Install Java 8 version, which is available Java 8 download
Gradle is not keeping up with the Java Latest versions, so roll back
to previous versions

directConnect option is not working after upgrading to webdriver-manager 12.1.4

I used to run my protractor tests using directConnect: true option set.
The chromedriver I had at that time was chromedriver2.46
Now with the latest webdriver-manaegr12.1.4, the chromedriver was upgraded to ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729#{#29})
If I still continue to use directConnect: true and run my tests, I get the following error
session not created: This version of ChromeDriver only supports Chrome version 75
(Driver info: chromedriver=75.0.3770.8 (681f24ea911fe754973dda2fdc6d2a2e159dd300-refs/branch-heads/3770#{#40}),platform=Mac OS X 10.14.4 x86_64)
Here is my very simple example: https://github.com/cnishina/protractor542-chrome74 It does not use a Docker container but it works for Chrome 74 with ChromeDriver 74.
Chrome browser + ChromeDriver versions
The output error message looks like session was not created because you are trying to use ChromeDriver 75. I would refer to http://chromedriver.chromium.org/downloads to match the ChromeDriver version to the Chrome browser version. The latest Chrome browser version is 74 so ChromeDriver downloads 74.0.3729.131. If you are still on Chrome browser 71-73, you could use ChromeDriver 2.46. Moving forward, the browser major version and chromedriver version must match. So for Chrome 73, you could use 73.0.3683.68.
Downloading different versions of ChromeDriver
If you need to download a different version of ChromeDriver, you could run the webdriver-manager command: webdriver-manager update --versions.chrome 73.0.3683.68 or to download 2.46, webdriver-manager update --versions.chrome 2.46.

Skipping Chrome Welcome Pase in Emulated Android using Eclipse and Appium Desktop?

I'm trying to run an Eclipse java script in order to automate a Web Application using Appium Desktop and Android Emulator.
The script's aim is only to open the Chrome browser in the Android Emulator and go to a specific URL:
package Appium.appiumTest;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
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 chrometest {
AppiumDriver<MobileElement> driver;
public void setUp() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "Nexus5");
capabilities.setCapability("browserName", "Chrome");
driver = new AndroidDriver<MobileElement>(new URL("https://0.0.0.0:4723/wd/hub"), capabilities);
driver.get("URL");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
public void searchKeyword() {
}
public static void main(String[] args) throws MalformedURLException {
chrometest obj = new chrometest();
obj.setUp();
}
}
When running the application with the Appium server running, the chrome browser opens at the emulated android, although the welcome page is constantly opening. After three/four attempts, the following error appears:
Exception in thread "main" org.openqa.selenium.WebDriverException: An
unknown server-side error occurred while processing the command. Original
error: Failed to start Chromedriver session: A new session could not be
created. (Original error: session not created exception: Chrome version must
be >= 60.0.3112.0
(Driver info: chromedriver=2.33.506120
(e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.14393
x86_64)) (WARNING: The server did not provide any stacktrace information)
I have tried to upgrade the chrome browser in the emulated android using the Play Store, but it does not let me log in, so that's not an option.
You can skip this step by Allowing USB debugging in your emulator. I was stuck at this welcome screen but this workaround helped.
Detailed steps are available in this question - How to skip Chrome Welcome screen, every time I run Appium, Ruby test

Appcelerator can start Genymotion emulator, but can't install package: "device not found"

On Win10, I have the following installed:
Appcelerator Studio
Appcelerator CLI
Android SDK (ADB enabled)
Genymotion (free / private license)
I'm using regular Windows Command Prompt to interact with Appcelerator, trying to run a project via a Genymotion emulator (it's the Appcelerator RSS Reader demo project). I've gotten it to the point where appc run --platform android will spin up Genymotion and start the appropriate emulator (the only device available according to the Android SDK Virtual Device Manager).
However, as soon as the emulator is ready, Appc tries to install the apk, and fails with this message:
[INFO] Making sure the adb server is running
[INFO] Installing apk: C:\Users\USERNAME\Documents\Appcelerator_Studio_Workspace\Rss Reader\build\android\bin\RSS Reader.apk
[ERROR] Failed to install apk on "192.168.128.101:5555"
[ERROR] Error: device not found
If Appc can find the appropriate emulator to start it up, why does installation fail with "device not found"?
If I immediately open a new console and check the adb connections, I see the specified device as connected:
>C:\Users\USERNAME\AppData\Local\Android\sdk\platform-tools>adb devices<br />
List of devices attached
192.168.128.101:5555 device
I have tried the following to troubleshoot:
Made sure SDK and ADB paths were correct
Made sure Genymotion paths were correct
Made sure the emulator has the correct API (25) and OS version (7.1.0)
Just a note, when I try to run appc run --platform android without the emulator / Genymotion started, it will spin up the emulator perfectly but never recognizes it being "ready", and fails with the following:
[INFO] Waiting for emulator to become ready...
[ERROR] Emulator failed to start in a timely manner
The current timeout is set to 120000 ms
If the emulator is already started, it completes as described in the top, with the "device not found" error.
Appc info (generated by Appc CLI on "run"):
Operating System
Name = Microsoft Windows 10 Enterprise
Version = 10.0.14393
Architecture = 64bit
# CPUs = 4
Memory = 17037770752
Node.js
Node.js Version = 6.11.3
npm Version = 3.10.10
Titanium CLI
CLI Version = 5.0.14
Titanium SDK
SDK Version = 6.2.2.GA
SDK Path = C:\ProgramData\Titanium\mobilesdk\win32\6.2.2.GA
Target Platform = android
Try use this:
appc run -p android -C "(name of genymotion virtual device)"

Cannot get blocshop TCP sockets-for-cordova to work

Need to have an Ionic mobile app connect to a Java Tomcat application server using TCP sockets. Have done the following:
Per the blocshop site (https://github.com/blocshop/sockets-for-cordova) directions installed the plugin with: cordova plugin add cz.blocshop.socketsforcordova
Added script src="socket.js" below script src="cordova.js" in the index.html file.
When run in a debug mode in WebStorm the construct var socket = new Socket(); results in the error: ReferenceError: Socket is not defined
Any assistance on how to get blocshop TCP sockets-for-cordova to work in an Ionic project is welcomed.
Try initializing socket (var socket = new Socket()) after deviceready event is called.
I got the same problem with cz.blocshop.socketsforcordova and the fix was:
Update Phonegap/cordva
Update the android SDK
Remove the platform executing android cordova platform remove android
Install the android's platform using cordova (first time I used phonegap platform add android) cordova platform add android
After following those steps my problem was fixed :)