Test was successful , but got a Class Not Found Exception - android

I am getting this error given below :
java.lang.ClassNotFoundException, If I run the below code :
#Test
public void alert() throws MalformedURLException, InterruptedException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("browserName", "");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "emulator-5554");
capabilities.setCapability("platformVersion", "5.1");
capabilities.setCapability("appPackage", "com.example.android.apis");
capabilities.setCapability("appActivity","com.example.android.apis.ApiDemos");
capabilities.setCapability("newCommandTimeout", "1000");
driver = (AndroidDriver) new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
Please let me know why this error is being thrown, have I missed any jar .
I am using :
Selenium 3.0.0 , Java Client 4.2.1 Jar , Selenium Android Driver Jar and Appium 1.16.4.1

Use jar
selenium-api-2.53.0
selenium-java-2.53.0
selenium-remote-server-2.53.0
selenium-server-standalone-2.53.0
java-client-4.1.2

Related

Program gets hanged when trying to automate a mobile application

Below program hangs completely, after trying to find elements. Doesn't look like anything wrong with xpath either. I need to terminate the program manually each time. Is there anything which i need to change in code or should i need to add something?
public class Test123 {
public static void main(String[] args) throws MalformedURLException, InterruptedException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("noReset", "true");
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "8.1.0");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"Android");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.talentpace.substk");
capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.talentpace.substk.MainActivity");
URL url=new URL("http://127.0.0.1:4723/wd/hub");
AndroidDriver driver=new AndroidDriver(url,capabilities);
Thread.sleep(5000);
driver.findElementByXPath("//node[#class='android.widget.EditText']").click();
}
}
Change your AUTOMATION_NAME in desired capabilites from Appium to uiautomator2
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
Seems that you have given the wrong xpath
the correct one should look like this
//android.widget.EditText[#class='Enter Class name here..']

While , Automating calculator,I had a following error?

A new session could not be created.
[error: No app set; either start appium with --app or pass in an 'app' value in desired capabilities, or set android Package to launch pre-existing app on device)
While running code with appium using eclipse, I had this error.
public class FirstAppiumProgram {
public static void main(String[] args) throws MalformedURLException {
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("BROWSER_NAME", "");
dc.setCapability(MobileCapabilityType.PLATFORM_NAME,Platform.ANDROID);
dc.setCapability(MobileCapabilityType.VERSION, "5.1.1");
dc.setCapability("APP_PACKAGE", "com.android.calculator2");
dc.setCapability("APP_ACTIVITY", "com.android.calculator2.Calculator");
dc.setCapability(MobileCapabilityType.DEVICE_NAME,"Nexus 5");
WebDriver driver= new RemoteWebDriver(new
URL("http://127.0.0.1:4723/wd/hub"),dc);
System.out.println(dc.toString());
driver.quit();
}
}
I think your error is because your capabilities are set wrongly.
At least appPackage and appActivity.
Read how capabilities are. Your possible capabilities:
//Your capabilities should be something like this:
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("platformName", "Android");
dc.setCapability("platformVersion", "5.1.1");
dc.setCapability("deviceName", "Nexus 5");
dc.setCapability("appPackage", "com.android.calculator2");
dc.setCapability("appActivity", "com.android.calculator2.Calculator");
Give it a try and let me know if you made it work

appium returns 200 status code but the click is not performed on the device

I am stuck with a game application where the appium returns 200 status code for a spin click(none of the clicks on game page is working though appium returns 200 code) but the click is not performed on the device. It is a web application and I am using the real device. Any help would be greatly appreciated.
I have tried using implicit, explicit waits, wait using Thread, Javascript, coordinates based click but no luck.
I am using the below code:
public class AndriodDriver {
AndroidDriver<WebElement> driver;
#Test
public void testFirstCalculator() throws IOException, InterruptedException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Samsung Galaxy S7");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
capabilities.setCapability("platformVersion", "7.0");
driver = new AndroidDriver<WebElement>(new
URL("http://0.0.0.0:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("https://pa03-mob.wi-gameserver.com/resource-service/test-
lobby/index.html");
driver.manage().timeouts().implicitlyWait(200, TimeUnit.SECONDS);
System.out.println("main url");
driver.findElement(By.xpath(".//*[#id='Open Lobby with debug properties']")).click();
System.out.println("lobby opened");
driver.findElement(By.xpath(".//*[#id='brucelee']")).click();
System.out.println("game loading");
WebDriverWait wait= new WebDriverWait(driver, 30);
//wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*
[#id='spin-button']")));
Thread.sleep(3500);
driver.findElementByXPath(".//*[#id='spin-button']").click();
}
}
First step:
Please add the following capability :
cap.setCapability("automationName","MyTest");
Second step:
Please replace the line :
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
by this:
cap.setCapability("browserName","Chrome");

how to create fat jar in android studio

public class WaitTests {
WebDriver driver;
#Before
public void setUp() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "XT1562");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability(CapabilityType.VERSION, "6.0.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.android.calculator2");
capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}
#Test
public void testFirstCalculator() {
driver.findElements(By.xpath("//android.widget.Button")).get(0).click();
driver.findElement(By.name("7")).click();
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
}
please any one tell me how to create fat jar in android studio (I am search in google but not getting any proper way for creating fat.jar ) so. I want to create executable file for run my above code. without any IDE

How to create apk from appium automation

I am trying to do appium automation and i had written the appium automation code. i had used appium server and my code is mention below :
public class WaitTests {
WebDriver driver;
#Before
public void setUp() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "XT1562");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability(CapabilityType.VERSION, "6.0.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.android.calculator2");
capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}
#Test
public void testFirstCalculator() {
driver.findElements(By.xpath("//android.widget.Button")).get(0).click();
driver.findElement(By.name("7")).click();
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
}
I want to run the code without IDE after creating .apk so what should i do to achieve. please suggest me
I've had this same problem and could fix it by creating a new Java module in Android Studio, adding a new gradle task in my build.gradle file:
task(runAppium, dependsOn: 'classes', type: JavaExec) {
main = 'com.mypackage.appium.Appium'
classpath = sourceSets.main.runtimeClasspath
}
and then launching it with:
gradle runAppium
As it's a Java module you'll need to have a public static void main(String[] args) function which will launch the test.
Hope it helps!

Categories

Resources