I'm working on Hybrid Application Automation.
I have asked a developer to provide webview enabled .apk file for automation.
I got the .apk and I installed in on my real device (Samsung Galaxy) and checked in chrome://inspect to view the app in inspector mode. - It is displayed
In my code I have tried System.out.println("ContextName:- " + contextNames); to check that Native and Webview context displaying. It successfully displayed both Webview and Native.
I have the following issue:
I'm able to find element till my Login page (using Native and Webview context).
After Login page I have a main screen in mobile app that contains list of tables and text, links, thus I'm unable to find any element in this page.
I tried copying the xpath using => inspector - copyxpath feature. I searched with that xpath in Chrome inspector and it's highlighted (showing) the elements. I'm using the same xpath in my code to check the size of that xpath details. But it's showing size = 0 for all my elements.
I also tried:
I swicthed to Webview context once after the login page;
I switched to Webview mode before login screen itself.
Still, I'm unable to find any element on my page.
Is it possible to capture all available elements in the page to check if at least I'm on right track? I'm not sure where is the mistake I made. Can any one suggest me some solution?
!!! Note: I have the following limitation: I can only use a real (physical) device, not an emulator.
Code:
File f = new File("D:\\APK\\");
File fs = new File(f,"android-4.0-8071-Pulse_Deb_Mode.apk");
AndroidDriver driver;
DesiredCapabilities cap =new DesiredCapabilities();
//cap.setCapability(MobileCapabilityType.DEVICE_NAME,"Auto1");
cap.setCapability(MobileCapabilityType.DEVICE_NAME,"89959777"); //5bce9757
cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
//cap.setCapability("appPackage", "au.com.ventia.apps.WMS");
//cap.setCapability("appActivity", "au.com.ventia.apps.WMS.MainActivity");
//cap.setCapability("platformName", "MobilePlatform.ANDROID");
//cap.setCapability("automationName", "Appium");
//cap.setCapability("autoWebview", true);
//cap.setCapability(MobileCapabilityType.BROWSER_NAME, "BROWSER");
//cap.setCapability(MobileCapabilityType.VERSION, "4.4.2");
//cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "21");
driver = new AndroidDriver (new URL("http://127.0.0.1:4723/wd/hub"),cap);
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
System.out.println(((AndroidDriver) driver).getOrientation());
System.out.println("Device Connected");
try{
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println("ContextName:- "+contextNames); //prints out something like NATIVE_APP \n WEBVIEW_1
// System.out.println("Working as:- "+ driver.getTitle());
}
Thread.sleep(40000);
driver.context((String) contextNames.toArray()[1]); // set context to WEBVIEW_1
List<WebElement> user_name = driver.findElementsById("userNameInput");
List<WebElement> pass_name = driver.findElementsById("passwordInput");
System.out.println("Checking"+user_name.size() + pass_name.size());
user_name.get(0).clear();
pass_name.get(0).clear();
user_name.get(0).sendKeys("<<>><<>>");
pass_name.get(0).sendKeys("<<>><<><");
driver.pressKeyCode(66);
Thread.sleep(30000);
//driver.context((String) contextNames.toArray()[0]); // set context to WEBVIEW_1
List<WebElement> li = driver.findElementsByXPath("//*[#id='app']/ion-pane/ion-side-menus/ion-side-menu-content/ion-header-bar/div[3]");
System.out.println("Check1-"+li.size());
List<WebElement> li2 = driver.findElementsByXPath(".//*[#id='app']/ion-pane/ion-side-menus/ion-side-menu-content/ion-header-bar/div[3]");
System.out.println("Refresh-"+li2.size());
List<WebElement> li3 = driver.findElementsByXPath("//*[#id=\"app\"]/ion-pane/ion-side-menus/ion-side-menu-content/ion-header-bar/div[3]");
System.out.println("Satus"+li3.size());
List<WebElement> li4 = driver.findElementsByXPath("//*[#id=\"au.com.ventia.apps.WMS\"]/ion-pane/ion-side-menus/ion-side-menu-content/ion-header-bar/div[3]");
System.out.println("Task"+li4.size());
}catch (Exception e){
System.out.println("Error Code---> "+e);
}
OUTPUT:
PORTRAIT
Device Connected
ContextName:- [NATIVE_APP, WEBVIEW_au.com.ventia.apps.WMS]
ContextName:- [NATIVE_APP, WEBVIEW_au.com.ventia.apps.WMS]
Checking11
Check1-0
Refresh-0
Satus0
Task0
Related
I am testing a website on Chrome (v65) installed on Android (7.1.1 API 25).
Chromedriver version 2.37.
Appium latest desktop version (v1.5.0, shows server version 1.7.2)
I need to upload an image from the device itself.
Although on the web-browser I am able to upload an image with sendKeys, its not working on the android emulator.
This is what the image selection page in the emulator looks like:
I used UiAutomator to get the resource id: "com.android.chrome:id/bitmap_view" and the class: "android.widget.ImageView"
I have used the following line(s) of code to try and look for the element:
(a)
driver.findElement(By.xpath("//android.widget.ImageView[contains(#resource-id,'com.android.chrome:id/bitmap_view')]")).click();
(b) When I use below, I get an empty list
List<WebElement> elements = driver.findElementsByClassName("android.widget.ImageView");
(c) I got this xpath from Appium Inspector Session
MobileElement el8 = (MobileElement) driver.findElementByXPath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.support.v7.widget.Af/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.support.v7.widget.RecyclerView/android.widget.FrameLayout[3]/android.widget.FrameLayout/android.widget.ImageView");
el8.click();
I don't know what I am missing.
[Update] []2
Did you change the context to the NATIVE_APP in your test?
Since you mentioned you test chrome, it means your test is using WEBVIEW context. But as soon as you open Upload files screen it is a NATIVE_APP view and you need to switch to it before start searching:
AndroidDriver<MobileElement> driver = new AndroidDriver<>(
new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.get(<your_web_site>);
// do what you need in browser, open Upload files screen
// switch to Native context to search inside it
Set<String> contexts = driver.getContextHandles();
for (String context : contexts) {
System.out.println(contexts);
if (context.equals("NATIVE_APP")) {
driver.context(context);
break;
}
}
List<MobileElement> images = driver.findElementsByClassName("android.widget.ImageView");
// click the last image in view if exist
images.stream()
.reduce((first, second) -> second)
.orElseThrow(NotFoundException::new)
.click();
I am new of mobile app automation tested using Appium with TestNG.Am practicing to automate amazon app, App was launching successfully but when I try to click login option, it's getting:
"FAILED: login org.openqa.selenium.NoSuchElementException: An
element could not be located on the page using the given search
parameters. (WARNING: The server did not provide any stacktrace
information) Command duration or timeout: 0 milliseconds"
public void login() throws InterruptedException{
System.out.println("Login check");
Thread.sleep(3000);
// String sample = driver.findElementByXPath("//*[#class='android.widget.Button' and #index='5']").getText();
System.out.println("Next sleep");
// driver.findElement(By.xpath("//[#class='android.widget.Button' and #index='5']')]")).click();
// driver.findElement(By.id("in.amazon.mShop.android.shopping:id/sign_in_button")).click();
driver.findElement(By.xpath("//android.widget.Button[#index='5']")).click();
Thread.sleep(3000);
System.out.println("Pass");
}
Image:
"//android.widget.Button[#index='5']" is invalid xpath locator. If you will ever what to use index (but I strongly suggest not to do it), do it this way:
"(//android.widget.Button)[5]"
But in your case the best is to search by resource-id:
driver.findElement(By.id("sign_in_button")).click();
And if it still doesn't work you can print app screen xml structure just before you search for element:
System.out.println(driver.getPageSource())
Analyse the xml you get if it contains your button and what are the attributes of it.
Please try this code:
MobileElement el1 = (MobileElement) driver.findElementById("in.amazon.mShop.android.shopping:id/sign_in_button");
el1.click();
I am using Appium 1.4.16 to automate apk file stored in my system in real android device. I am using java-client 3.4.1
Here is the code:
public static void main(String[] args) {
File app = new File("C:\\Users\\dell\\Downloads\\App.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device", " Android");
//mandatory capabilities
capabilities.setCapability("deviceName","Android");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("udid", "849e82c6");
capabilities.setCapability("app",app.getAbsolutePath());
capabilities.setCapability("appPackage", "xxxxxxxxxxx");
capabilities.setCapability("appActivity", "xxxxxxxxxx.MainActivity");
try{
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
System.out.println("Device Started");
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
RemoteWebElement number = (RemoteWebElement)driver.findElement(By.xpath("//android.widget.EditText[#resource-id='xxxx' and #content-desc = 'Mobile Number']"));
number.sendKeys("90002");
RemoteWebElement passwordKey = (RemoteWebElement)driver.findElement(By.xpath("//android.widget.EditText[#resource-id='yyyyy']"));
passwordKey.sendKeys("ezr123");
RemoteWebElement loginButton = (RemoteWebElement)driver.findElement(By.xpath("//android.view.View[#resource-id='ezm_submit_login_form']"));
loginButton.click();
}catch(Exception e){
e.printStackTrace();
}
}
}
I am not getting any error in Appium server but facing strange actions in UI.
While entering value in username field, it automatically clicks on Login Button then again enters value in password field. Here, it always starts with entering '2' in the field and ends with 8-digit password.But my supplied password is 6-digit long.Then nothing happens.
I have also tried giving Thread.sleep() between each action.But no change is observed.
Best solution is to tap on the element first using the xpath or Id, then type on the element , this is fail proof and will work
U can also give timeout after tap and also hide keyboard by pressing key value for back (4)
Or hide keyboard command
I try to open a website in chrome and native android browser (emulated Android 5.0 and 6) to check several items.
every time i run the test, the choosen browser get started and in the url field stays 'data:,' btw the actual tab is also loaded two times.
I know there is a way to do this with selenium webdriver, but this is not the right way for me because i used the followed code for several emulated devices to test this website and on iOS/Mac osx its working.
So why not on android. My way to test this website is with capybara, appium and ruby.
on iOS there exists a
:safariInitialUrl =>'http://www.mypage.com'
cap.
but not for android.
So, my question is: how is it possible to start my website on an emulated android devices without using selenium webdriver.
code:
Capybara.register_driver :androidphone do |app|
capabilities = {
:deviceName => 'nex5_5',
:avd => 'nex5_5',
:browserName => 'Chrome',
:platformVersion => '5.0',
:platformName => 'Android',
:automationName => 'Appium',
}
url = "http://localhost:4723/wd/hub"
appium_lib_options = {
server_url: url
}
all_options = {
appium_lib: appium_lib_options,
caps: capabilities,
}
Appium::Capybara::Driver.new app, all_options
You have to add this line in your config file :
exports.config = {
directConnect:false,
}
I think you have also to add the Timeout in your configuration file, if you are using jasmine framework for example add this code :
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
I am trying to automate Google Hangouts app using appium(in java).
I am using Appium CLient v 1.3.7 I am using Samsung Galaxy S5 Android os version 5.0.
I want to send text using element.sendkeys() method to the field having content description as "Type a name,email,number or circle" field. Appium does find the field but after executing sendkeys() command, it does not show anything in the same field. Appium clicks at the left edge of the app.
This field does not have resource-id. I tried element.click() before using sendkeys() but din't help. Any suggestion?
dr = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capa);
WebElement el1 = dr.findElementByName("Type a name, email, number or circle");
el1.click();
el1.sendKeys("0000000");
It does not have name which you are considering , you can identify that element by following way :
WebElement el1 = driver.findElement(By.id("com.google.android.apps.hangouts:id/people_audience_view_chip_container")).click();
el1.sendKeys("0000000");