unknown error: Unsupported locator strategy: -android uiautomator - android

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.

Related

unable to find a way to run my code in sauce labs real time device

How to run the below Appium code in sauce labs? When I checked sauce labs website there is only one line given below
driver = new WebDriver(
new URL("https://balajimscit09:a30f3417-cbe6-48ce-92b5-e9a6d0814879#ondemand.us-west-1.saucelabs.com:443")
);
Below is my code
package mobile_Appium;
import static io.appium.java_client.touch.TapOptions.tapOptions;
import static io.appium.java_client.touch.WaitOptions.waitOptions;
import static io.appium.java_client.touch.offset.ElementOption.element;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.FindsByAndroidUIAutomator;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidTouchAction;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.touch.WaitOptions;
import io.appium.java_client.touch.offset.PointOption;
public class InstallTestAndroid10 {
static AppiumDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException {
File f = new File("src");
File fs = new File(f, "ApiDemos-debug.apk");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
cap.setCapability(MobileCapabilityType.VERSION, "10.0");
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Device");
cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Uiautomator2");
cap.setCapability("autoGrantPermissions", true);
cap.setCapability("noReset", "false");
cap.setCapability("fullReset", "true");
cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
/*driver.findElement(By.xpath("//android.widget.Button[#text='OK']")).click();
Thread.sleep(10000);
((FindsByAndroidUIAutomator<MobileElement>) driver).findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\"Views\").instance(0))");
driver.findElement(By.xpath("//android.widget.TextView[#text='Views']")).click(); */
}}
How to integrate with a real device present in sauce labs?
Your App should be upload to sauce storage.
After that, the app capability should point to this file.
Fo example:
cap.setCapability(MobileCapabilityType.APP, "storage:filename=ApiDemos-debug.apk");
You can read more here:
https://wiki.saucelabs.com/display/DOCS/Application+Storage
Also, you should change your access key after publishing it here
In those capabilities, it looks like you are still pointing to a local URL. You need to add a URL for sauce labs with your username and access key, and upload an app. See how it is done in this video: https://www.youtube.com/watch?v=hwp5YeF5Me4
There are 3 basic things that you need to do to run an Appium test
Upload your app to Sauce Labs so your test can run against it in the Real Device Cloud
Update your Test code with your Sauce Username and Access Key (Set as environment vars), and use these to start a driver with the endpoint (or URL) to test against
Update your capabilities for the real device you want to test including app name, device, platform version and more.
System.out.println("Sauce iOS Native - BeforeMethod hook");
String username = System.getenv("SAUCE_USERNAME");
String accesskey = System.getenv("SAUCE_ACCESS_KEY");
String sauceUrl;
if (region.equalsIgnoreCase("eu")) {
sauceUrl = "#ondemand.eu-central-1.saucelabs.com:443";
} else {
sauceUrl = "#ondemand.us-west-1.saucelabs.com:443";
}
String SAUCE_REMOTE_URL = "https://" + username + ":" + accesskey + sauceUrl +"/wd/hub";
String appName = "iOS.RealDevice.SauceLabs.Mobile.Sample.app.2.7.1.ipa";
String methodName = method.getName();
URL url = new URL(SAUCE_REMOTE_URL);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "iPhone 8.*");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("automationName", "XCuiTest");
capabilities.setCapability("app", "storage:filename="+appName); // or "storage:"+appID
capabilities.setCapability("name", methodName);
iosDriver.set(new IOSDriver(url, capabilities));

Appium Automation - Method has not yet been implemented

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.

Not able to connect/run a operation on android device in android studio

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.

Appium: Why am I seeing a desiredcapabilties error in the log even after I have provided all the relevant values?

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");

Read HTML content from a WebView using WebDriver and Appium

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.

Categories

Resources