简体   繁体   中英

Android: External file in uiautomator

I have developed mobile automation project for android in java using uiautomator.

I have follow all the steps like :-

  1. Create jar
  2. Push jar to device
  3. and at last run the test case

I need to automate the login functionality with user name and password . I have created excel file for reading usernames and password like selenium .

But when I access this Excel file, it gives File Not Found exception.

adb shell uiautomator runtest /sdcard/myApp.jar -c com.example.LoginTest

Is there any way to access other files in uiautomator ?

UIAutomator runs inside the shell as a process, so we would not be able to access excel file which runs in PC

How ever, there are two ways you can automate it:

1.Write a Script to parse excel sheet and set them as dummy system properties, use UIAutomator to read the same

//set android dummy property using script
adb shell setprop dummy value 

//Read Value of property in UIAutomator
getProperty("dummy");

//Subroutine for Reading Property from Android
public String getProperty(String propName) {
String propValue = null;
try {
propValue = (String) Class.forName("android.os.SystemProperties").getMethod("get", new Class[] { String.class }).invoke(null, propName);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return propValue;
}

2.Write values to a text file and parse it in Java in UIAutomator class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM