我在Java中有这个脚本:
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.interactions.internal.MouseAction.Button;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
public class PABT_Test {
public static void main(String[] args) throws MalformedURLException, InterruptedException {
File appDir = new File("src");
File app = new File(appDir, "me.user.myapp.apk");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "9889db344647575839");
//cap.setCapability(MobileCapabilityType.DEVICE_NAME, "9889db344647575839");
// cap.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
cap.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
// cap.setCapability(AndroidMobileCapabilityType.APP_WAIT_ACTIVITY, "me.user.*");
// cap.setCapability("appActivity", "md56babf71b8936f51000b2474a3f146837.SplashActivity");
// cap.setCapability("waitForAppScript","$.delay(100); true;");
// cap.setCapability("appWaitActivity", "md56babf71b8936f51000b2474a3f146837.SplashActivity, " + "md56babf71b8936f51000b2474a3f146837.MainActivity" );
AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"),cap);
AndroidElement Skip =driver.findElementByLinkText("Skip");
Skip.click();
driver.wait(3000);
}
}
我也尝试在机器人框架中做到这一点。代码如下:
*** Settings ***
Library AppiumLibrary
*** Variables ***
${App_PA} C:/Android/me.user.myapp.apk
*** Test Cases ***
Open_App
${App} Set Variable ${App_PA}
Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=7.0 deviceName=9889db344647575839 app=${App} automationName=appium
sleep 1s
Click Text Next
sleep 1s
Click Text Next
sleep 1s
Click Text Get Started
Wait Until Page Contains Main Menu
在这两种情况下,我都会遇到相同的错误
[ADB] Running 'C:\Users\user\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","9889db344647575839","shell","dumpsys","window"]
[AndroidDriver] Screen already unlocked, doing nothing
[ADB] Device API level: 24
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\user\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","9889db344647575839","shell","am","start","-W","-n","me.user.myapp/md56babf71b8936f51000b2474a3f146837.SplashActivity","-S"]
[ADB] Waiting up to 20000ms for activity matching pkg: 'me.user.myapp' and activity: 'md56babf71b8936f51000b2474a3f146837.SplashActivity' to be focused
[ADB] Possible activities, to be checked: 'md56babf71b8936f51000b2474a3f146837.SplashActivity'
[ADB] Getting focused package and activity
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\user\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","9889db344647575839","shell","dumpsys","window","windows"]
[ADB] Found package: 'me.user.myapp' and fully qualified activity name : 'md56babf71b8936f51000b2474a3f146837.MainActivity'
[ADB] Incorrect package and activity. Retrying.
[ADB] Getting focused package and activity
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
....
[AndroidDriver] Shutting down Android driver
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\user\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","9889db344647575839","shell","am","force-stop","me.user.myapp"]
[ADB] Pressing the HOME button
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
我搜索了SO和其他资源,并根据我测试过的反馈...您可以在Java代码的注释部分看到我失败的尝试。
使用adb直接执行更新:
我运行以下命令并且应用程序已加载,但我无法在java或机器人上复制此成功
c:\Users\user\AppData\Local\Android\Sdk\platform-tools>adb shell am start -a android.intent.action.MAIN -n me.user.myapp/md56babf71b8936f51000b2474a3f146837.SplashActivity
Starting: Intent { act=android.intent.action.MAIN cmp=me.user.myapp/md56babf71b8936f51000b2474a3f146837.SplashActivity launchParam=MultiScreenLaunchParams { mDisplayId=0 mBaseDisplayId=0 mFlags=0 } }
另一方面,当活动设置为&#34; MainActivity&#34;时,运行此命令实际上无法启动应用程序。并显示权限被拒绝错误。
c:\Users\user\AppData\Local\Android\Sdk\platform-tools>adb shell am start -a android.intent.action.MAIN -n me.user.myapp/md56babf71b8936f51000b2474a3f146837.MainActivity
Starting: Intent { act=android.intent.action.MAIN cmp=me.user.myapp/md56babf71b8936f51000b2474a3f146837.MainActivity launchParam=MultiScreenLaunchParams { mDisplayId=0 mBaseDisplayId=0 mFlags=0 } }
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=me.user.myapp/md56babf71b8936f51000b2474a3f146837.MainActivity launchParam=MultiScreenLaunchParams { mDisplayId=0 mBaseDisplayId=0 mFlags=0 } } from null (pid=2984, uid=2000) not exported from uid 10497
at android.os.Parcel.readException(Parcel.java:1693)
at android.os.Parcel.readException(Parcel.java:1646)
at android.app.ActivityManagerProxy.startActivityAsUser(ActivityManagerNative.java:3603)
at com.android.commands.am.Am.runStart(Am.java:663)
at com.android.commands.am.Am.onRun(Am.java:392)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:51)
at com.android.commands.am.Am.main(Am.java:125)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:316)
答案 0 :(得分:0)
做一件事,只要求开发人员为应用程序提供启动器活动。上周我遇到了与Android应用程序相同的问题,问题是我认为活动的活动不是那个。发射活动是另一回事。所以只需与开发人员澄清一次。
来自Upwork
答案 1 :(得分:0)
尝试使用
adb shell pm dump PACKAGE_NAME
这将为您提供确切的包名称和应用程序活动列表。 配置中提到的包看起来是混淆的,请查看appium的日志以获取有关此问题的更多详细信息。
cap.setCapability("appActivity", "md56babf71b8936f51000b2474a3f146837.SplashActivity");
您可以使用adb activity manager(adb shell am)验证活动
答案 2 :(得分:0)
可以尝试使用以下功能,我发现没有appPackage和appActivity功能。
${androiddriver}= Open Application http://localhost:4723/wd/hub platformName=android platformVersion=7.0 deviceName=9889db344647575839 automationName=uiautomator2
... appPackage=me.user.myapp newCommandTimeout=2500 appActivity=md56babf71b8936f51000b2474a3f146837.SplashActivity noReset=True app=${App}