This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
1 / 4
Jul 2016

The problem

driver.Pagesource() not giving the complete details for an element of a native app. XML while designing the screen has details of font-type,color, etc...for the button where the XML file generated using the command driver.Pagesource() in a program is not giving even a single details of the button that might be alike the XML file while designing

Environment

  • Appium version ---1.4.16.1
  • Desktop OS/version used to run Appium: Windows 7 Professional SP1
  • Node.js version (unless using Appium.app|exe):0.12.2
  • Mobile platform/version under test: Android 4.3
  • Real device or emulator/simulator: Samsung Galaxy Note II
  • Appium CLI or Appium.app|exe:

Details

I am planning to automate my task for which I am planning to use Appium. I am designing a screen with a button providing the background color and font color and provided an action as when clicked navigate to next screen that displays a textbox. I am launching the app in Android and iOS devices and after opening the initial screen in a real android/ios devices with the button I am making the screen to wait for 5 seconds and using driver.getPagesource(); to get the XML that contain all the details of the button like button size, button background color, button font type, button font color besides when clicked navigating to next screen I am planning to get textbox font color,fonttype,etc... but this command(pageSource) is not all giving details but only stopping at the button class only after that not giving any details.
XML file taken from Page source for Button
<?xml version="1.0" encoding="UTF-8"?>
<hierarchy rotation="0">
<android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.testinglo62.mobile" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][720,1280]" resource-id="" instance="0">
<android.view.View index="0" text="" class="android.view.View" package="com.testinglo62.mobile" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][720,1280]" resource-id="android:id/action_bar_overlay_layout" instance="0">
<android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.testinglo62.mobile" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,50][720,1280]" resource-id="android:id/content" instance="1">
<android.widget.ViewAnimator index="0" text="" class="android.widget.ViewAnimator" package="com.testinglo62.mobile" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,50][720,1280]" resource-id="" instance="0">
<android.widget.RelativeLayout index="0" text="" class="android.widget.RelativeLayout" package="com.testinglo62.mobile" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,50][720,1280]" resource-id="" instance="0">
<android.widget.LinearLayout index="0" text="" class="android.widget.LinearLayout" package="com.testinglo62.mobile" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,50][720,1280]" resource-id="" instance="0">
<android.widget.ScrollView index="1" text="" class="android.widget.ScrollView" package="com.testinglo62.mobile" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,50][720,1280]" resource-id="" instance="0">
<android.widget.LinearLayout index="0" text="" class="android.widget.LinearLayout" package="com.testinglo62.mobile" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,50][720,167]" resource-id="" instance="1">
<android.widget.LinearLayout index="0" text="" class="android.widget.LinearLayout" package="com.testinglo62.mobile" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[36,86][684,167]" resource-id="" instance="2">
<android.widget.LinearLayout index="0" text="" class="android.widget.LinearLayout" package="com.testinglo62.mobile" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[36,86][684,167]" resource-id="" instance="3">
<android.widget.LinearLayout index="0" text="" class="android.widget.LinearLayout" package="com.testinglo62.mobile" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[36,86][684,167]" resource-id="" instance="4">
<android.widget.LinearLayout index="0" text="" class="android.widget.LinearLayout" package="com.testinglo62.mobile" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[36,86][684,167]" resource-id="" instance="5">
<android.widget.Button index="0" text="Submit" class="android.widget.Button" package="com.testinglo62.mobile" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[36,86][684,167]" resource-id="" instance="0"/>
</android.widget.LinearLayout>
</android.widget.LinearLayout>
</android.widget.LinearLayout>
</android.widget.LinearLayout>
</android.widget.LinearLayout>
</android.widget.ScrollView>
</android.widget.LinearLayout>
</android.widget.RelativeLayout>
</android.widget.ViewAnimator>
</android.widget.FrameLayout>
</android.view.View>
</android.widget.FrameLayout>
</hierarchy>

XML for Button taking while designing the screen
`












`
From the above two XML files I am expecting to display the content under STI tag of "XML while designing" through program using driver.pageSource()....being so unlucky I tried looking into lots of forums and tried to implement few features but unable to get even single details for Button hence desperately I expect that I may get some solution from this forum

Code To Reproduce Issue [ Good To Have ]

package com.mobiexautomation.xmlfiles ;

import io.appium.java_client.AppiumDriver ;
import io.appium.java_client.android.AndroidDriver ;

import java.io.File ;
import java.net.URL ;
import java.util.ArrayList ;
import java.util.List ;

import org.openqa.selenium.By ;
import org.openqa.selenium.WebElement ;
import org.openqa.selenium.remote.DesiredCapabilities ;
import org.testng.annotations.Test ;

import com.mobeixautomation.utils.WaitScenarios ;

public class AndroidNativeXMLCheck {

AppiumDriver < WebElement > driver ;
WaitScenarios ws = new WaitScenarios ( ) ;

@ Test
public void getXMLFile ( ) throws Exception {

	File classpathRoot = new File ( System.getProperty ( "user.dir" ) ) ;
	File appDir = new File ( classpathRoot , "/APK" ) ;
	File app = new File ( appDir , "app-debug.apk" ) ;
	new DesiredCapabilities ( ) ;
	DesiredCapabilities capa = new DesiredCapabilities ( ) ;
	capa.setCapability ( "platformName" , "Android" ) ;
	capa.setCapability ( "platformVersion" , "4.3" ) ;
	capa.setCapability ( "deviceName" , "Samsung Galaxy Note II" ) ;
	capa.setCapability ( "app" , app.getAbsolutePath ( ) ) ;
	capa.setCapability ( "appPackage" , "com.testinglo62.mobile" ) ;
	capa.setCapability ( "appActivity" , ".MainActivity" ) ;
	driver = new AndroidDriver < WebElement > ( new URL ( "http://localhost:4723/wd/hub" ) , capa ) {

		@ Override
		public WebElement scrollTo ( String a ) {

			return null ;
		}

		@ Override
		public WebElement scrollToExact ( String a ) {

			return null ;
		}

		@ Override
		public void swipe ( int arg0 , int arg1 , int arg2 , int arg3 , int arg4 ) {

			// TODO Auto-generated method stub

		}
	} ;

	ws.waitbyXpath ( "//android.view.View[1]/android.widget.FrameLayout[1]/android.widget.ViewAnimator[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.Button[1]" , driver ) ;
	Thread.sleep ( 5000 ) ;
	String xmlFireforButton = driver.getPageSource ( ) ;
	System.out.println ( "XML File Value for Button==" + xmlFireforButton ) ;
	driver.findElement ( By.xpath ( "//android.view.View[1]/android.widget.FrameLayout[1]/android.widget.ViewAnimator[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.Button[1]" ) ).click ( ) ;
	ws.waitbyXpath ( "//android.view.View[1]/android.widget.FrameLayout[1]/android.widget.ViewAnimator[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.TextView[1]" , driver ) ;
	Thread.sleep ( 5000 ) ;
	String xmlFireforTextBox = driver.getPageSource ( ) ;
	System.out.println ( "XML File Value for TextBox==" + xmlFireforTextBox ) ;

}

}

  • created

    Jul '16
  • last reply

    Jul '16
  • 3

    replies

  • 3.0k

    views

  • 3

    users

<android.widget.Button index="0" text="Submit" class="android.widget.Button" package="com.testinglo62.mobile" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[36,86][684,167]" resource-id="" instance="0"/>

This looks like the standard array of element attributes that Appium provides, nothing is missing.

As far as I know there's no way to have Appium see additional attributes, nor is Appium aware of or able to report colors of elements.

To follow up on Christopher's comments, Appium uses UIAutomator. If the attributes you are trying to access aren't visible to UIAutomater, they won't be available in the output from page_source. I agree with Christopher's assessment -- those are the standard attributes available through UIAutomator. The ones you are looking for are not available, in my experience.

Hi All, Thanks a lot for the replies.....your information is so valuable but as per my requirement I must have the values which I explained in my post are required as I am trying to verify them when a screen is loaded in the device against the designed screen so that if there any descripencies I can inform my developers that their code could be wrong as the designed screen is not displaying as expected in the device when the screen is loading in the device. I hope I can do this for Hybrid Apps by connecting the device to Chrome browser when the screen is loaded but I want the same type of inespection for Native Apps too hence found Appium is the only source to get this information but as per your posts I found it might not be possible as UIAutomator not loading it hence can you suggest any other tool that will provide this information besides if there are any secured features to be disabled in the app only for the testing environment please do let me know so that I will request my developers to enable this feature