This question already has answers here:
"driver cannot be resolved" in Java program
(2 answers)
Closed 3 years ago.
I am very new to programming. My main goal is to write code that logs into a android app and does everything that you would have to do with your fingers. So far I've only got the app to open, now I'm stuck on entering the login information.
I am not familiar with every aspect that has to do with Java, Eclipse, Appium, and Selenium.
Here is my code:
package OpenOfferUpTest;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import io.appium.java_client.android.AndroidDriver;
public class OpenOfferUp {
#Test
public void OpensOfferUp() throws MalformedURLException
{
File OfferUp = new File("C:\\Users\\boung\\Desktop\\OfferUp.apk");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("deviceName", "Virtual Device");
cap.setCapability("platformName", "android");
cap.setCapability("null", "OfferUp");
cap.setCapability("appPackage", "com.offerup");
cap.setCapability("appActivity", "com.offerup.android.login.splash.LoginSplashActivity");
AndroidDriver driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), cap);
}
#Test
public void SimpleTest() {
driver.findElement(By.id("email_button")).sendKeys("sourgta#gmail.com");
}
}
At driver, it is underlined red, and says that it cannot be resolved. I am not sure on how to fix this.
These are the options I am given:
package OpenOfferUpTest;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import org.testng.annotations.*;
import io.appium.java_client.android.AndroidDriver;
public class OpenOfferUp {
AndroidDriver driver;
#BeforeTest
public void OpensOfferUp() throws MalformedURLException
{
File OfferUp = new File("C:\\Users\\boung\\Desktop\\OfferUp.apk");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("deviceName", "Virtual Device");
cap.setCapability("platformName", "android");
cap.setCapability("null", "OfferUp");
cap.setCapability("appPackage", "com.offerup");
cap.setCapability("appActivity", "com.offerup.android.login.splash.LoginSplashActivity");
driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), cap);
}
#Test
public void SimpleTest() {
driver.findElement(By.id("email_button")).sendKeys("sourgta#gmail.com");
}
}
Try updated code
Related
I am trying to run a mini appium project, I have the emulator and an appium server running and here's my code, it says that .getBinaryPath() is undefined for type WebDriverManager "caps.setCapability("chromedriverExecutable", WebDriverManager.chromedriver().getBinaryPath());"
package appiumBasics;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.github.bonigarcia.wdm.WebDriverManager;
#Test
public class RubWebApplicationAndroidEmulator {
public void OpenWebApplication() throws MalformedURLException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(MobileCapabilityType.BROWSER_NAME, "chrome");
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "HaidyEmulator");
WebDriverManager.chromedriver().setup();
caps.setCapability("chromedriverExecutable", WebDriverManager.chromedriver().getBinaryPath());
AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),caps);
}
}
That is because if you actually go to the repository and open the problematic class, you find there is no such method defined for WebDriverManager:
https://github.com/bonigarcia/webdrivermanager/blob/master/src/main/java/io/github/bonigarcia/wdm/WebDriverManager.java
Presumably this was changed at some point. Possibly you need WebDriverManager#getDownloadedDriverPath():
#Test
public class RubWebApplicationAndroidEmulator {
public void OpenWebApplication() throws MalformedURLException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(MobileCapabilityType.BROWSER_NAME, "chrome");
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "HaidyEmulator");
WebDriverManager.chromedriver().setup();
caps.setCapability("chromedriverExecutable", WebDriverManager.chromedriver().getDownloadedDriverPath());
AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),caps);
}
}
Code with errors:
package TestCase;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import com.gargoylesoftware.htmlunit.javascript.host.URL;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
public class TestWebBrowser {
//AppiumDriver driver = new IOSDriver();
public static AndroidDriver driver;
public static void main(String[] args) throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
}
The message error is:
The constructor URL(string) is undefined
The constructor AndroidDriver(URL, DesiredCapabilities) is undefined
AndroidDriver is a raw type
I have tried with different versions of java-client and still the problem persists
You need to use an existen constructor like this:
https://appium.github.io/java-client/io/appium/java_client/android/AndroidDriver.html
You need use java.net.URL and not com.gargoylesoftware.htmlunit.javascript.host.URL
#Lorena, hi.
1. Firstly, could You please double check the imports ? Sharing code snippet below with correct ones
package tests.web;
import java.net.MalformedURLException;
import java.net.URL;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileBrowserType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
public class AndroidWebTest {
private static final String ACCESS_KEY = System.getenv(“SEETEST_IO_ACCESS_KEY”);
private static final String CLOUD_URL = “https://cloud.seetest.io:443/wd/hub”;
private static final String TITLE = “Testing Website on Android Chrome with Java”;
private AndroidDriver driver = null;
#Before
public void setUp() throws MalformedURLException {
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(“testName”, TITLE);
dc.setCapability(“accessKey”, ACCESS_KEY);
dc.setBrowserName(MobileBrowserType.CHROME);
driver = new AndroidDriver(new URL(CLOUD_URL), dc);
}
#Test
public void testAppiumOnChrome() {
driver.get(“https://amazon.com”);
System.out.println(driver.getTitle());
if (driver.getCapabilities().getCapability(“device.category”).equals(“TABLET”)) {
driver.findElement(By.xpath(“//*[#name=’field-keywords’]”)).sendKeys(“iPhone”);
driver.findElement(By.xpath(“//*[#text=’Go’]”)).click();
} else {
driver.findElement(By.xpath(“//*[#name=’k’]”)).sendKeys(“iPhone”);
driver.findElement(By.xpath(“//*[#value=’Go’]”)).click();
}
}
#After
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
}
Please see the Comparing and combining web and mobile test automation drivers article for more details.
If You project is maven-based, could You please also double check the dependencies?
For example, please see latest appium updates here
Appropriate maven repo to check for (latest) java client:
https://mvnrepository.com/artifact/io.appium/java-client
stacktrace screenshot I am trying to run different tests that I have written, through Appium on an Android device, but I am getting the following errors:
unable to load class 'org.eclipse.ui.internal.ide.application.addons.ModelCleanupAddon' from bundle '731'
or
unable to load class 'org.eclipse.ui.internal.ide.application.addons.ModelCleanupAddon' from bundle '561'
My code is:
import org.openqa.selenium.By;
//import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.WebElement;
//import org.openqa.selenium.remote.DesiredCapabilities;
//import org.openqa.selenium.remote.RemoteWebDriver;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
//import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.testng.annotations.AfterTest;
import java.io.File;
import java.net.URL;
import java.net.MalformedURLException;
//import java.util.concurrent.TimeUnit;
//import org.junit.Test;
public class CustomerLogin {
AppiumDriver driver;
takeScreenshot SC;
#BeforeClass
public void setUp() throws MalformedURLException{
File app = new File(System.getProperty("user.dir")+ "\\apks\\DropCarOwner-STAGE-v2.1.0-rc.1.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("DeviceName","306SH");
capabilities.setCapability("PlatformValue", "4.4.2");
capabilities.setCapability("PlatformName", "Android");
capabilities.setCapability("app",app.getAbsolutePath());
driver= new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
}*/
#Test
public void Login() throws Exception{
WebElement email= driver.findElement(By.id("com.dropcar.owner:id/editTextEmailAddress"));//com.dropcar.owner:id/editTextEmailAddress
email.sendKeys("a","w","a","i","s","d","u","r","r","a","n","i","8","7","#","g","m","a","i","l",".","c","o","m");
WebElement password= driver.findElement(By.id("com.dropcar.owner:id/editTextPassword")); //com.dropcar.owner:id/editTextPassword
password.sendKeys("c","h","e","c","k","i","n","g","1","2","3");
WebElement check= driver.findElement(By.name("Remember me")); //com.dropcar.owner:id/checkBoxRememberMe
driver.tap(0, check,0);
//check.click();
WebElement signIn=driver.findElement(By.name("SIGN IN"));
driver.tap(1,signIn,1);
//signIn.click();
SC.Screenshot(driver);
}
#AfterTest
public void end(){
driver.quit();
}
}
I am using Eclipse 4.4.1. How can I resolve this error?
Make sure before running the script appium-doctor command is working successfully. If you will attach the appium log then it will be more easy to tell you the actual solution of your problem.
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.
Performing automation test on android emulator using appium. Browser in emulator is not opening when it is automated via code. I have copied my code below kindly look into it and help me out. Thanks in advance
package report;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.swing.JOptionPane;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class emulator {
WebDriver driver;
public void setUp() throws MalformedURLException
{
DesiredCapabilities capabilities= new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME,"browser");
capabilities.setCapability(CapabilityType.VERSION,"4.4");
capabilities.setCapability(CapabilityType.PLATFORM,"windows");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("devices","Android");
capabilities.setCapability("avd","nexus");
capabilities.setCapability("deviceName","");
capabilities.setCapability("appPackage", "com.android.browser");
capabilities.setCapability("appActivity", "com.android.browser.BrowserActivity");
driver=new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
public void cal(){
driver.get("http://www.google.com");
}
public static void main(String[] args) throws MalformedURLException
{
emulator a=new emulator();
a.setUp();
a.cal();
}
}
The lock screen will deactivate the other script of our program. So I tried open the emulator manually and disable the lock screen (Settings -> Security -> None). Then close the emulator. Now open the emulator automatically and run the script.
public void setUp(int p) throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "browser");
capabilities.setCapability(CapabilityType.VERSION, "");
capabilities.setCapability(CapabilityType.PLATFORM, "windows");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("udid", "emulator-" + p);
capabilities.setCapability("devices", "Android");
capabilities.setCapability("avd", "Nexus7");
capabilities.setCapability("deviceName", "");
capabilities.setCapability("appPackage", "com.android.browser");
capabilities.setCapability("appActivity", "com.android.browser.BrowserActivity");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:" + this.port + "/wd/hub"),
capabilities);
}
When working on mobile browser we need not to pass all the above desiredcapabilities like apppackage and appactivitiy. You can check the details of required capabilities # http://qaautomationcafe.blogspot.in/2015/09/mobile-web-automation-using-appium.html