返回错误:java.lang.SecurityException:在appium中使用touchaction类时,注入另一个应用程序需要INJECT_EVENTS权限

问题描述 投票:1回答:1

返回错误:java.lang.SecurityException:在appium中使用touchaction类时,注入另一个应用程序需要INJECT_EVENTS权限

try {
    logger.info("Launching the app");
    driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    logger.info("Value of driver ----" +driver);
    MobileElement seekbar=driver.findElementByClassName("android.widget.SeekBar");
    int startX=seekbar.getLocation().getX();
    int startY=seekbar.getLocation().getY();
    int endX=(startX+seekbar.getSize().getWidth());
    TouchAction action=new TouchAction(driver);
    action.longPress(startX, startY).moveTo((int) (endX*0.5), startY).release().perform();      
} catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

在这一行中获得错误......

action.longPress(startX, startY).moveTo((int) (endX*0.5), startY).release().perform(); 

以下是堆栈跟踪

Exception in thread "main" org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
System info: host: 'sysadmin-ThinkPad-L440', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.16.0-30-generic', java.version: '1.8.0_151'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {appActivity: nu.lower.brightness.SplashS..., appPackage: nu.lower.brightness, browserName: android, databaseEnabled: false, desired: {appActivity: nu.lower.brightness.SplashS..., appPackage: nu.lower.brightness, browserName: android, deviceName: MauryaJi, newCommandTimeout: 120, noReset: true, platform: ANDROID, platformName: Android, udid: 93ffd01a0803, version: 7.0 NRD90M}, deviceManufacturer: Xiaomi, deviceModel: Redmi Note 4, deviceName: 93ffd01a0803, deviceScreenSize: 1080x1920, deviceUDID: 93ffd01a0803, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, newCommandTimeout: 120, noReset: true, platform: ANDROID, platformName: ANDROID, platformVersion: 7.0, takesScreenshot: true, udid: 93ffd01a0803, version: 7.0 NRD90M, warnings: {}, webStorageEnabled: false}
Session ID: 45824a17-fa92-4570-b5e4-a09c578b3367
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
    at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:89)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at io.appium.java_client.PerformsTouchActions.performTouchAction(PerformsTouchActions.java:41)
    at io.appium.java_client.TouchAction.perform(TouchAction.java:325)
    at com.appium.test.TestCase1.brightnessControl(TestCase1.java:125)
    at com.appium.test.ExecuteTest.main(ExecuteTest.java:11)``
java selenium appium
1个回答
4
投票

我通过访问移动设备的开发人员选项解决了我的问题并启用了设备的安全设置这不是编码问题。我已经更改了手机中的设置。设置 - >附加设置 - >开发人员选项 - >(USB调试安全设置)。供参考Image Attach.enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.