I keep getting an error on runtime when I'm executing from Eclipse IDE. I added the class paths for the commons-lang3, java-client and selenium webdriver for java jar packages. What am I missing?
My code:
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
public class InstallAppAndroidEmulator {
public static void main(String[] args) {
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, 9.0);
dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
dc.setCapability(MobileCapabilityType.APP, "C:\\Users\\Some_Name\\Desktop\\apk files\\app-test.apk");
URL url = null;
try {
url = new URL("http://localhost:4723/wd/hub");
AndroidDriver<WebElement> driver = new AndroidDriver<WebElement>(url, dc);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Files:
Error message:
Solved by adding missing selenium jars from lib folder (unless using a standalone library)
Solved by adding missing selenium jars from lib folder as well (not needed if using a standalone library)
Related
I started the Selendroid server:
java -jar selendroid-standalone-0.17.0-with-dependencies -app Guru99App.apk
The test App Guru99App.apk is signed.
Then I ran this code in Eclipse:
import io.selendroid.standalone.SelendroidConfiguration;
import io.selendroid.standalone.SelendroidLauncher;
import io.selendroid.common.SelendroidCapabilities;
import io.selendroid.client.SelendroidDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
public class SelendroidTest1 {
private static SelendroidLauncher selendroidServer = null;
private static WebDriver driver = null;
#Test
public void selendroidTest() throws Exception {
System.out.print("Start executing test");
SelendroidConfiguration config = new SelendroidConfiguration();
selendroidServer = new SelendroidLauncher(config);
selendroidServer.launchSelendroid();
DesiredCapabilities caps = SelendroidCapabilities.android();
driver = new SelendroidDriver(caps);
}
#AfterSuite
public void tearDown() {
driver.quit();
}
}
My Smartphone is connected, I checked with 'adb devices' as well, but I keep getting this Exception:
'No devices are found. This can happen if the devices are in use or no device screen matches the required capabilities.'
I also tried starting the server with:
java -jar selendroid-standalone-0.17.0-with-dependencies -aut Guru99App.apk
I assumed that the problem is due to an unsupported version of Android, so I tried this :
SelendroidCapabilities caps = new SelendroidCapabilities("com.guru99app:1.0");
caps.setPlatformVersion(io.selendroid.common.device.DeviceTargetPlatform.ANDROID10);
caps.setEmulator(false);
driver = new SelendroidDriver(caps);
This also did not help.
I am using a Motorola Moto one.
How can I solve this?
Building a basic Appium test in Java for Android.
When I run the code, it gives me an exception error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
driver cannot be resolved
driver cannot be resolved
driver cannot be resolved to a variable
at tests.AppiumTest.main(AppiumTest.java:50)
I have triple checked my jar files, all of them appear to be included and I'm not missing any but when I hover over the driver text, the import Webdriver option does not appear.
Code below:
package tests;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
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 AppiumTest {
public static void main(String[] args) {
//Set the Desired Capabilities
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "My Phone");
caps.setCapability("udid", "Redacted"); //Give Device ID of your mobile phone
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "7.1.1");
caps.setCapability("appPackage", "com.android.vending");
caps.setCapability("appActivity", "com.google.android.finsky.activities.MainActivity");
caps.setCapability("noReset", "true");
// Instagram: com.instagram.android/com.instagram.android.activity.MainTabActivity
// Facebook: com.facebook.katana/com.facebook.katana.LoginActivity
try {
driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);
} catch (MalformedURLException e) {
System.out.println(e.getMessage());
}
//Added 5 seconds wait so that the app loads completely before starting with element identification
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//Find Google Play element using ID property and click on it
driver.findElement(By.id("com.android.vending:id/search_box_idle_text")).click();
//Find 'Google Play Store' element and set the value Google
driver.findElement(By.id("com.android.vending:id/search_box_text_input")).sendKeys("Google");
//Press Enter key from Keyboard using any of the below methods
((AndroidDriver<MobileElement>) driver).pressKeyCode(66);
}
}
Screenshots of imported jar files:
1
2
First of all You didn't show where AndroidDriver is declared.
Second thing is that I don't see in Your dependancies Appium, You just have selenium imported.
appium.io
You should have something like this in your pom, if using maven:
https://mvnrepository.com/artifact/io.appium/java-client/6.0.0
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>6.0.0</version>
</dependency>
My dependancy:
Hope this helps...
I try to use selenium(latest version, chrome version 58) with org.openqa.selenium.chrome.ChromeDriver. This class has documentation which appears in eclipse. It includes simple test:
import java.io.File;
import java.io.IOException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import junit.framework.TestCase;
#RunWith(JUnit4.class)
public class ChromeTest extends TestCase {
private static ChromeDriverService service;
private WebDriver driver;
#BeforeClass
public static void createAndStartService() {
service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"))
.usingAnyFreePort().build();
try {
service.start();
} catch (IOException e) {
System.out.println("service didn't start");
// TODO Auto-generated catch block
e.printStackTrace();
}
}
#AfterClass
public static void createAndStopService() {
service.stop();
}
#Before
public void createDriver() {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--disable-gpu");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
driver = new RemoteWebDriver(service.getUrl(), capabilities);
}
#After
public void quitDriver() {
driver.quit();
}
#Test
public void testGoogleSearch() {
driver.get("http://www.google.com");
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("webdriver");
// searchBox.quit();
assertEquals("webdriver - Google Search", driver.getTitle());
}
}
When I run it, new google chrome window appears on desktop. And in eclipse console I see:
ERROR:child_thread_impl.cc(762)] Request for unknown Channel-associated interface: ui::mojom::GpuMain
I tried to solve it by using :
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--disable-gpu");
But it didn't help. I still have the same error.
After I did debug I see that this error message appears on console when native method java.lang.Thread.start0() is called. Inside java.lang.Thread.start method there is call to native start0().
What is wrong with my comp(windows 7)?
How to solve this ?
Thank you!
Solved it.
I misunderstood method usingDriverExecutable of ChromeDriverService.Builder().
This method expects path to chromedriver.exe file but I set path to chrome.exe. Correct code is:
#BeforeClass
public static void createAndStartService() {
service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File("D:\\Downloads\\chromedriver_win32\\chromedriver.exe"))
.withVerbose(false).usingAnyFreePort().build();
try {
service.start();
} catch (IOException e) {
System.out.println("service didn't start");
// TODO Auto-generated catch block
e.printStackTrace();
}
}
You can also set it with webdriver.chrome.driver system property:
System.setProperty("webdriver.chrome.driver", "D:\\Downloads\\chromedriver_win32\\chromedriver.exe");
To download latest chromedriver.exe go to https://sites.google.com/a/chromium.org/chromedriver/downloads. From this page they send you to https://chromedriver.storage.googleapis.com/index.html?path=2.29/.
I want to automate test a basic Hybrid Mobile Application build on top of Cordova running in Android. I used Apppium for that. I followed the tutorial video to get started. I downloaded and Added Selenum, selendroid and java client .jar files to the build path of the Application.
Below is my code,
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
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;
import io.appium.java_client.remote.MobileCapabilityType;
public class AppiumTest {
public static void main(String[] args) throws MalformedURLException, InterruptedException {
URL serverAddress = new URL("http://0.0.0.0:4723/wd/hub");
WebDriver driver = new AndroidDriver<MobileElement>(serverAddress, getDesiredCapabilities());
try{
Set<String> contextNames = ((AppiumDriver<MobileElement>) driver).getContextHandles();
for (final String contextName : contextNames) {
System.out.println(contextName);
if (contextName.contains("WEBVIEW_0")) {
Thread.sleep(3000);
driver.switchTo().window("WEBVIEW_0");
}
}
//Change color to Red
driver.findElement(By.cssSelector("p.recieved")).click();
Thread.sleep(2000);
//Change color to Red
driver.findElement(By.cssSelector("recieved")).click();
Thread.sleep(2000);
driver.get("http//appium.io/");
Thread.sleep(2000);
}
finally {
driver.quit();
}
System.out.println("Driver "+driver);
}
public static DesiredCapabilities getDesiredCapabilities() {
DesiredCapabilities capability = new DesiredCapabilities();
capability.setCapability(MobileCapabilityType.AUTOMATION_NAME, "selendroid");
capability.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capability.setCapability("platformVersion", "4.4.4");
capability.setCapability("deviceName", "Android-Dev");
capability.setCapability("app",
"C:/Joseph/Appium/HybridProject/AppiumTest/platforms/android/build/outputs/apk/android-debug.apk");
capability.setCapability("appPackage", "com.joseph.appiumtest");
capability.setCapability("appActivity", ".MainActivity");
return capability;
}
}
I can able to get the Capabilities and Contexts. On switching the window (driver.switchTo().window("WEBVIEW_0")), I am getting error like Exception in thread "main" org.openqa.selenium.WebDriverException: CATCH_ALL: java.lang.VerifyError: io/selendroid/server/model/SelendroidWebDriver
Versions :
Android : 4.4.4
Appium : 1.6.3
Selenium : 3.0.1
Selendroid: 0.17.0
After lots of tries, got the Automation testing in Hybrid Mobile Application using Appium worked.
Basically in Capabilities, its not necessary to set the package name and activity name. Instead get the file path of the Application package name(.apk).
File app= new File("project/platforms/android/build/outputs/apk/android-debug.apk");
DesiredCapabilities capabilities= new DesiredCapabilities();
capabilities.setCapability("deviceName", "Android-Dev");
capabilities.setCapability("platformVersion", "4.4.4");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "MobilePlatform.ANDROID");
capabilities.setCapability("app", app.getAbsolutePath());
Then do not explicitly switch the window to WEBVIEW. Get the context and set the dynamic context of Webview particular for the Application.
try {
Set<String> contextNames = ((AppiumDriver) driver).getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextName);
if (contextName.contains("WEBVIEW")) {
((AppiumDriver<MobileElement>) driver).context(contextName);
}
}
}
catch(Exception e){
e.printStackTrace();
}
And finally with the driver set, do the action.
driver.findElement(By.xpath("//*[#id='login']")).click();
I am a beginner of Appium and Java. When I perform my first demo for Android test, I just get 2 errors and have no idea how to fix them after google. So I have to find some help here.
Code:
import java.net.MalformedURLException;
import java.net.URL;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
public class AutoTest {
private AndroidDriver<WebElement> driver;
#Before
public void Setup() throws MalformedURLException{
//File classPathRoot = new java.io.File(System.getProperty("user.dir"));
//File appDir = new File(classPathRoot,"app/login.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "emulator-5554");
capabilities.setBrowserName("Android");
capabilities.setCapability(CapabilityType.VERSION, "6.0.1");
capabilities.setPlatform(Platform.ANDROID);
//capabilities.setCapability("app", appDir.getAbsolutePath());
capabilities.setCapability("appPackage", "com.study.kukaka.login");
capabilities.setCapability("appActivity", "LoginActivity");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723"),capabilities);
}
#Test
public void test() {
driver.findElement(By.id("email")).sendKeys("myemail#hotmail.com");
driver.findElement(By.id("password")).sendKeys("whatever");
driver.findElement(By.id("email_sign_in_button")).click();
System.out.println("Test pass!");
}
#After
public void End(){
driver.quit();
}
}
And the errors:
The project was not built since its build path is incomplete. Cannot find the class file for org.openqa.selenium.remote.service.DriverService$Builder. Fix the build path then try building this project
The type org.openqa.selenium.remote.service.DriverService$Builder cannot be resolved. It is indirectly referenced from required .class files
The library I used is as below.
Library I used
Any help is appreciated!
You may need to selenium remote driver jar file to build path. ( I could not seen it your build path )
Download from maven
http://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-remote-driver/2.44.0
and put it to your build path. If not works again, putting error logs will be more heplfull.