gpt4 book ai didi

android - 无法使用 AWS Device farm 打开和关闭通知面板

转载 作者:太空狗 更新时间:2023-10-29 13:48:35 25 4
gpt4 key购买 nike

我的测试需要打开和关闭通知面板并从 Android 设备(Moto G4 Android 7 - AWS 设备场)返回到应用程序。所以我在测试中调用了以下方法

androidActivity.openAndCloseNotifications();

在哪里

public void openAndCloseNotifications() throws InterruptedException{ 
TimeUnit.SECONDS.sleep(3);
driver.openNotifications();
TimeUnit.SECONDS.sleep(3);
driver.pressKeyCode(AndroidKeyCode.BACK);
}

测试在设备本地通过,但当我在 AWS 设备场上运行它时,我可以看到通知面板永远不会打开,因此测试失败。此时 AWS device farm 是否允许与通知面板交互?如果没有,我该如何处理?因为这对我们的大多数测试来说都是一个问题。提前致谢!

这是失败的测试,在 androidActivity.openAndCloseNotifications(); 行失败:

    public boolean run() throws Exception {
MainActivity mainActivity = new MainActivity(driver);
AndroidActivity androidActivity = new AndroidActivity(driver);
LoginActivity loginActivity = new LoginActivity(driver);



try {
if(device.getCapability("manufacturer")=="Huawei")
{
driver.closeApp();
driver.launchApp();
loginActivity.registerApp("whateverhere");
androidActivity.openAndCloseNotifications();
mainActivity.verifyAppIsReady();
assertTrue(mainActivity.check());
return true;

}

else {

driver.closeApp();
driver.launchApp();
loginActivity.registerApp("whateverhere");
androidActivity.openAndCloseNotifications();
mainActivity.verifyAppIsReady();
System.out.println("Verified Stop button is displayed");
assertTrue(mainActivity.check());
System.out.println("Verified title is displayed");
return true;
}
}

catch(Exception e) {
System.out.println(e);
return false;
}

}

来自 AWS 设备场的日志(本地没有故障) java.lang.AssertionError:预期 [true] 但发现 [false]\n\tat org.testng.Assert.fail(Assert.java:94)\n\tat org.testng.Assert.failNotEquals(Assert.java:494 )\n\tat org.testng.Assert.assertTrue(Assert.java:42)\n\tat org.testng.Assert.assertTrue(Assert.java:52)\n\tat com.OneMeter.Robirdo.TestSequence1.test1 (TestSequence1.java:48)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat sun.reflect.DelegatingMethodAccessorImpl。调用(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:498)\n\tat org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)\n\tat org.testng.internal.Invoker.invokeMethod(Invoker.java:714)\n\tat org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)\n\tat org.testng.internal.Invoker。 invokeTestMethods(Invoker.java:1231)\n\tat org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodW orker.java:127)\n\tat org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)\n\tat org.testng.TestRunner.privateRun(TestRunner.java:767)\n\tat 组织。 testng.TestRunner.run(TestRunner.java:617)\n\tat org.testng.SuiteRunner.runTest(SuiteRunner.java:348)\n\tat org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343)\n\tat org.testng.SuiteRunner.privateRun(SuiteRunner.java:305)\n\tat org.testng.SuiteRunner.run(SuiteRunner.java:254)\n\tat org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java: 52)\n\tat org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)\n\tat org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)\n\tat org.testng.TestNG.runSuitesLocally( TestNG.java:1149)\n\tat org.testng.TestNG.run(TestNG.java:1057)\n\tat org.testng.TestNG.privateMain(TestNG.java:1364)\n\tat org.testng。 TestNG.main(TestNG.java:1333)\n\n

最佳答案

用 OnePlus 3T 在本地测试,成功

能力:

capabilities.setCapability("app", "C:\\Users\\james\\Desktop\\stackoverflow\\question_50172058_unable-to-open-and-close-notifications-panel-with-aws-device-farm\\testofopenNotifications\\app-debug.apk");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "OnePlus");

Appium 版本:1.7.1

Appium 服务器输出:

[info] [HTTP] --> POST /wd/hub/session/51cf9f0e-2106-4e34-b0d5-7df3caebc223/appium/device/open_notifications {}
[debug] [MJSONWP] Calling AppiumDriver.openNotifications() with args: ["51cf9f0e-2106-4e34-b0d5-7df3caebc223"]
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"openNotification","params":{}}[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Responding to client with driver.openNotifications() result: true
[info] [HTTP] <-- POST /wd/hub/session/51cf9f0e-2106-4e34-b0d5-7df3caebc223/appium/device/open_notifications 200 328 ms - 76

使用来自 example tests 的程序集和 pom 打包测试后使用命令 mvn clean package -DskipTests=true 这是使用 Moto G4 Android 7 的设备农场的结果:

Appium 服务器版本:1.7.1如所述使用空的所需功能对象 here

成功并打开通知。 See video

Appium 服务器日志:

2018-05-05 16:55:06:839 - [HTTP] --> POST /wd/hub/session/c70b3b24-b7d6-4c6b-a7e2-d4ff5e91aa22/appium/device/open_notifications {}
2018-05-05 16:55:06:868 - [debug] [MJSONWP] Calling AppiumDriver.openNotifications() with args: ["c70b3b24-b7d6-4c6b-a7e2-d4ff5e91aa22"]
2018-05-05 16:55:06:872 - [debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"openNotification","params":{}}
2018-05-05 16:55:06:888 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"openNotification","params":{}}
2018-05-05 16:55:06:889 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
2018-05-05 16:55:06:890 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: openNotification
2018-05-05 16:55:06:891 - [debug] [AndroidBootstrap] Received command result from bootstrap
2018-05-05 16:55:06:893 - [debug] [MJSONWP] Responding to client with driver.openNotifications() result: true
2018-05-05 16:55:06:907 - [HTTP] <-- POST /wd/hub/session/c70b3b24-b7d6-4c6b-a7e2-d4ff5e91aa22/appium/device/open_notifications 200 55 ms - 76

这是我执行的测试方法:

@Test public void testOpenNotifications(){
//docs: https://github.com/appium/appium/blob/62700d3b1dc0edd985502cc1279747a782f3ee74/docs/en/commands/device/system/open-notifications.md
driver.openNotifications();
}

我认为调用 sleep 的代码可能会导致问题,但它似乎也能正常工作。见video

代码:

@Test public void testOpenNotificationsWithSleep() throws InterruptedException{
TimeUnit.SECONDS.sleep(3);
driver.openNotifications();
TimeUnit.SECONDS.sleep(3);
}

能否分享您在 Device Farm 中执行的 appium 服务器日志?它将显示来自 UIAutomator 或 UIAutomator2 的响应,我们可以从那里开始。

这是我的完整测试类,用于比较:

package Tests;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

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

public class OpenNotificationsTest{

/**
* Make the driver static. This allows it to be created only once
* and used across all of the test classes.
*/
public static AndroidDriver<MobileElement> driver;

/**
* This method runs before any other method.
*
* Appium follows a client - server model:
* We are setting up our appium client in order to connect to Device Farm's appium server.
*
* We do not need to and SHOULD NOT set our own DesiredCapabilities
* Device Farm creates custom settings at the server level. Setting your own DesiredCapabilities
* will result in unexpected results and failures.
*
* @throws MalformedURLException An exception that occurs when the URL is wrong
*/
@BeforeSuite
public void setUpAppium() throws MalformedURLException {

final String URL_STRING = "http://127.0.0.1:4723/wd/hub";

URL url = new URL(URL_STRING);

//Use a empty DesiredCapabilities object fro device farm
DesiredCapabilities capabilities = new DesiredCapabilities();

//local capabilities
capabilities.setCapability("app", "C:\\Users\\james\\Desktop\\stackoverflow\\question_50172058_unable-to-open-and-close-notifications-panel-with-aws-device-farm\\testofopenNotifications\\app-debug.apk");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "OnePlus");

driver = new AndroidDriver<MobileElement>(url, capabilities);

//Use a higher value if your mobile elements take time to show up
driver.manage().timeouts().implicitlyWait(35, TimeUnit.SECONDS);
}

@Test public void testOpenNotifications(){
//docs: https://github.com/appium/appium/blob/62700d3b1dc0edd985502cc1279747a782f3ee74/docs/en/commands/device/system/open-notifications.md
driver.openNotifications();
}

@Test public void testOpenNotificationsWithSleep() throws InterruptedException{
TimeUnit.SECONDS.sleep(3);
driver.openNotifications();
TimeUnit.SECONDS.sleep(3);
}

/**
* Always remember to quit
*/
@AfterSuite
public void tearDownAppium() {
driver.quit();
}

/**
* Restart the app after every test class to go back to the main
* screen and to reset the behavior
*/
@AfterClass
public void restartApp() {
driver.resetApp();
}
}

希望尽快收到您的来信。

-詹姆斯

关于android - 无法使用 AWS Device farm 打开和关闭通知面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50172058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com