I'm trying to explore Mobile App Automation, i'm running into this issue.
package sample;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
public class AndroidTest {
static WebDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException
{
File app= new File("C:\\Users\\ASSOUND\\Downloads\\DevOps\\mymbfs60_simulator_0301.apk");
DesiredCapabilities capabilities= new DesiredCapabilities();
capabilities.setCapability("deviceName", "Android Emulator");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
driver.findElement(By.id("com.android.packageinstaller:id/permission_allow_button")).click();
driver.quit();
}
}
This code Installs & Launches the App, but when i try to locate the Element and click, i'm getting this error:
Exception in Thread "main" org.openga.selenium.WebDriverException: Method has not yet been implemented (WARNING: The server did not Provide..
Note: i tried to include enough time-wait before locating the element, but its still the same.
Related
I am automating mobile web application using Appium Server and Selenium.
All I want to do is to retrieve the titles of android notification, to achieve this i tried to using the locator: findElementsByAndroidUIAutomator to identify an element using resourceId.
Below is the code written by me:
package com.roofandfloor.test;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.MobileBy;
import io.appium.java_client.android.AndroidDriver;
public class test02 {
public static void main(String[] args) throws MalformedURLException, InterruptedException {
DesiredCapabilities desc = null;
URL url = null;
desc = new DesiredCapabilities();
desc.setCapability("automationName","Appium");
desc.setCapability("platformName", "Android");
desc.setCapability("platformVersion", "5.0");
desc.setCapability("deviceName", "Lenovo K50a40");
desc.setCapability("browserName", "Chrome");
desc.setCapability("appPackage", "com.android.chrome");
desc.setCapability("appActivity", "com.google.android.apps.chrome.Main");
url = new URL("http://0.0.0.0:4723/wd/hub");
AndroidDriver driver = new AndroidDriver(url,desc);
driver.openNotifications();
Thread.sleep(5000);
List<WebElement>allNotifications=driver.findElementsByAndroidUIAutomator("new UiSelector().resourceId(\"android:id/title\")");
System.out.println(allNotifications.size());
}
}
When I run the above code I am getting the error shown below:
org.openqa.selenium.WebDriverException: unknown error: Unsupported locator strategy: -android uiautomator
I have alternatively tried to use the below code.
List<WebElement>allNotifications=driver.findElements(MobileBy.AndroidUIAutomator("new UiSelector().resourceId(\"android:id/title\")"));
I am getting the same error as above.
Please help me resolving the issue.
I am not able to connect or runb a script on a real android device from android studio and geeting the following error:
The code is as follows:
import org.junit.Before;
import java.net.URL;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import io.appium.java_client.android.AndroidDriver;
public class Sample {
private static RemoteWebDriver driver;
#Before
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device","Android");
capabilities.setCapability("app", "Chrome");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(CapabilityType.VERSION, "4.4.2");
capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),
capabilities);
}
#Test
public void testcase_001() throws Exception{
driver.get("http://www.google.com");
WebElement keyword = driver.findElementByName("q");
keyword.sendKeys("appium");
driver.findElement(By.id("btnK")).click();
Thread.sleep(5000);
}
}
But the device is listed in Android device monitor
And shown connected in cmd
And the things that I tried is changing the following settings:
Android studio > Run > Edit Configuration > In Gerenal tab > set Target as USB DEVICE.
Any Idea what is wrong
Remove the last apk if you already installed before and try to install new apk.
I try to automate tests for a native android app with Appium. The feature I want to test is that certain user settings, for example, favorite search result, of the app can retain after updating to a newer version of the app. I have two version of the app and manually tested that this feature works. But when I automate the test, all the settings are cleared/reset.
My automation is done in two steps. First, in one session, install the old version, and set the favorite settings; second, start a new session, install the new version.
First step works just fine. In my second step
If I set full reset to my capability before starting new session, the app is reinstalled with new version but all the settings are cleared.
If I set no reset to my capability before starting new session, then I found the app is NOT reinstalled with new version at all.
How should I set the appium server flag so that in my second step, I can get my new version installed while still keeping the settings? I am guessing this has something to do with plist file of the app?
Here is my code.
settingOldVersion.java
package RR.upgradeTest;
import java.io.File;
import java.net.URL;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import RR.utility.RRhelper;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
public class settingOldVersion{
public static AndroidDriver DRIVER;
public static String APK_file = "oldversion.apk";
#BeforeClass
public static void setUpBeforeClass() throws Exception {
File appDir = new File("src");
File app = new File(appDir, APK_file);
DesiredCapabilities cap=new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.0.1");
cap.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
System.out.println("\n\n******************************************************");
System.out.println("Installation and startup app "+APK_file);
//Android Driver
DRIVER=new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
System.out.println("Driver obtained");
Thread.sleep(2000);
}
#AfterClass
public static void tearDownAfterClass() throws Exception {
DRIVER.quit();
}
#Test
public void settingFavorite() throws Exception
{
System.out.println("setting favorite");
//Add search result into favorite
....
//Take a screenshot of the favorite page
....
String image_path=".//result//UpgradeTest/OldVersion//";
String name="FavoriteSetting"+APK_file;
RRhelper.takeScreenshot(DRIVER, name, image_path);
}
}
Here is my code for checking new version: verifyNewVersion.java
package RR.upgradeTest;
import java.io.File;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.List;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import RR.utility.RRhelper;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
public class varifyNewVersion{
public static AndroidDriver DRIVER;
public static String APK_file = "newversion.apk";
#BeforeClass
public static void setUpBeforeClass() throws Exception {
File appDir = new File("src");
File app = new File(appDir, APK_file);
DesiredCapabilities cap=new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.0.1");
cap.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
// cap.setCapability("fullReset", true);
// cap.setCapability("noReset", false);
System.out.println("\n\n******************************************************");
System.out.println("Installation and startup app "+app.getAbsolutePath());
//Android Driver
DRIVER=new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
System.out.println("Driver obtained");
Thread.sleep(2000);
}
#AfterClass
public static void tearDownAfterClass() throws Exception {
DRIVER.quit();
}
#Test
public void checkingFavorite() throws Exception
{
//Come to Favorite page
Assert.assertTrue(RRhelper.ComeToMenuItem(DRIVER, "Favoritter"));
Thread.sleep(300);
String image_path=".//result//UpgradeTest/NewVersion//";
String name="FavoriteSetting_"+APK_file;
RRhelper.takeScreenshot(DRIVER, name, image_path);
....
}
}
Using two different apks you cannot reserve the package settings unless they are synced by the application using the deviceID you are installing it on(application end handling.) For an upgrade, usually the applications have an option of updating the app which could be done using the playstore/linking to a local server.
Also fullReset and noReset works on the package specified, if it would already be there noReset would not override the existing and fullReset would uninstall and then install the application.
More or so, it depends on your application how is the state of the flag/settings reserved, do you want a user to keep using the same settings while he is trying to force download another apk version or do you want to restore default settings in that case.
With appium server setting, either fullreset or noreset can server my purpose of testing the retaining of user setting after upgrade the app. As described in the question. Now I found a solution, which is to install the app with adb install -r, which means reinstall an exisiting app, keeping its data.
This command line can be wrapped up in my JAVA test code. After installation with adb, start the session with appium without installation of the app,
cap.setCapability(MobileCapabilityType.APP_PACKAGE, "package name");
cap.setCapability(MobileCapabilityType.APP_ACTIVITY, "activity name");
Then I can see the settings are retained.
I ran the following code for Automating a simple Test for Android via Appium:
package appiumtest;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.*;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.AppiumSetting;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.*;
import org.testng.*;
//import org.junit.*;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.*;
public class AppiumTest {
public static void main(String[] args) throws InterruptedException, MalformedURLException{
// TODO Auto-generated method stub
AppiumTest testcases = new AppiumTest();
testcases.launchtest();
}
public void launchtest() throws InterruptedException, MalformedURLException{
File app = new File("D:\\Radio\\ebayTest.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
capabilities.setCapability(CapabilityType.BROWSER_NAME,"");
capabilities.setCapability("platformname", "Android");
capabilities.setCapability(CapabilityType.VERSION,"4.4.2");
capabilities.setCapability("deviceName", "07d4bb0a00caa300");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.ebay.mobile");
capabilities.setCapability("appActivity", ".activities.eBay");
Thread.sleep(3000);
System.out.println("App launched");
WebElement signin = driver.findElement(By.id("button_sign_in"));
signin.click();
Thread.sleep(4000);
}
}
Now after running the test, I continuously see the error message shown below in the logs and the Appium Server Window:
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: The following desired capabilities are required, but were not provided: deviceName) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 200 milliseconds
Why am I seeing this error message? I have provided the correct device name parameter in Desired Capabilities as seen in 'adb devices'.
You initialized the driver with the capabilities before all the capabilities were set.
Move this line AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
after this line capabilities.setCapability("appActivity", ".activities.eBay");
I am trying to automate Gmail App on android using Selenium WebDriver and Appium. I need to read an email content and then validate it. But the complete element is displayed as a single webview and I am I am unable to read any text from the email. Please suggest a way so that I can read the email content
Code Used:
package com.example.appium;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class GmailInvoke {
/**
* #param args
* #throws MalformedURLException
* #throws InterruptedException
*/
public static void main(String[] args) throws MalformedURLException, InterruptedException {
DesiredCapabilities capabilities=new DesiredCapabilities();
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "Android");
//Gmail
capabilities.setCapability("appPackage","com.google.android.gm");
capabilities.setCapability("appActivity", ".ui.MailActivityGmail");
WebDriver driver=new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
List <WebElement> emails = driver.findElements(By.className("android.widget.FrameLayout"));
emails.get(5).click();
System.out.println(driver.findElement(By.id("com.google.android.gm:id/webview")).getText());
Thread.sleep(5000);
driver.quit();
}
}
I think that its impossible to automate pre-installed apps. I tried it too.