如何使用Eclipse在Appium上运行脚本测试?

时间:2018-02-15 14:11:41

标签: java android eclipse testing appium

您好我写了这段代码,我试图通过使用Appium进行APP测试登录过程。当我运行测试它返回我这个错误:

  

org.openqa.selenium.WebDriverException:处理命令时发生未知的服务器端错误。原始错误:错误   在启动App时发生。原始错误:执行adbExec时出错。   原始错误:'命令   ' C:\用户\卢卡斯\应用程序数据\本地\ Android的\ SDK \平台工具\ adb.exe   -P 5037 -s 5210ce98fa7eb4b3 shell启动-W -n com.consul.android.smartbeer.qa/com.whirlpool.ted.View.DashBoardActivity   -S'退出代码1&#39 ;; Stderr:' java.lang.SecurityException:权限拒绝:启动Intent {flg = 0x10000000   CMP = com.consul.android.smartbeer.qa / com.whirlpool.ted.View.DashBoardActivity   launchParam = MultiScreenLaunchParams {mDisplayId = 0 mBaseDisplayId = 0   mFlags = 0}}从null(pid = 867,uid = 2000)未从uid 10226导出     在android.os.Parcel.readException(Parcel.java:1703)at   android.os.Parcel.readException(Parcel.java:1653)at   android.app.ActivityManagerProxy.startActivityAndWait(ActivityManagerNative.java:3680)     在com.android.commands.am.Am.runStart(Am.java:658)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)     在com.android.internal.os.RuntimeInit.main(RuntimeInit.java:316)&#39 ;;   代码:' 1' (警告:服务器未提供任何堆栈跟踪   信息)命令持续时间或超时:28.33秒构建信息:   版本:' 3.9.1',修订版:' 63f7b50',时间:   ' 2018-02-07T22:42:22.379Z'系统信息:主持人:' LAPTOP-PFJQUV00',ip:   ' 192.168.116.1',os.name:' Windows 10',os.arch:' amd64',os.version:   ' 10.0',java.version:' 1.8.0_152'驱动程序信息:driver.version:   AndroidDriver在   sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)     at sun.reflect.NativeConstructorAccessorImpl.newInstance(未知   来源)at   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(未知   来自java.lang.reflect.Constructor.newInstance(未知来源)     在   org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)     在   org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)     在   org.openqa.selenium.remote.JsonWireProtocolResponse.lambda $新的$ 0(JsonWireProtocolResponse.java:53)     在   org.openqa.selenium.remote.JsonWireProtocolResponse.lambda $ getResponseFunction $ 2(JsonWireProtocolResponse.java:91)     在   org.openqa.selenium.remote.ProtocolHandshake.lambda $ $了createSession 0(ProtocolHandshake.java:123)     在java.util.stream.ReferencePipeline $ 3 $ 1.accept(未知来源)at   java.util.Spliterators $ ArraySpliterator.tryAdvance(未知来源)at   java.util.stream.ReferencePipeline.forEachWithCancel(未知来源)     在java.util.stream.AbstractPipeline.copyIntoWithCancel(未知   来自java.util.stream.AbstractPipeline.copyInto(未知来源)     at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)     at java.util.stream.FindOps $ FindOp.evaluateSequential(Unknown Source)     在java.util.stream.AbstractPipeline.evaluate(未知来源)at   java.util.stream.ReferencePipeline.findFirst(未知来源)at   org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)     在   org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)     在   org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:138)     在   io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:89)     在   org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)     在   io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)     at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)     在   io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)     在   org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)     在   org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:142)     在   io.appium.java_client.DefaultGenericMobileDriver。(DefaultGenericMobileDriver.java:38)     在io.appium.java_client.AppiumDriver。(AppiumDriver.java:83)     在io.appium.java_client.AppiumDriver。(AppiumDriver.java:93)     在   io.appium.java_client.android.AndroidDriver。(AndroidDriver.java:72)     在test.FacebookLoginTest.testLoginFB(FacebookLoginTest.java:30)at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)at   sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at   java.lang.reflect.Method.invoke(未知来源)at   org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:50)     在   org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)     在   org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)     在   org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)     在org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)at   org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)     在   org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)     在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:290)at at   org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:71)at at   org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)at at   org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:58)at at   org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:268)at at   org.junit.runners.ParentRunner.run(ParentRunner.java:363)at at   org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)     在   org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)

我试图运行一个简单的登录测试,但我已经陷入了困境。 Appium没有打开应用程序:(

以下是Java中的类clode:

    package test;

    import io.appium.java_client.android.AndroidDriver;

    import java.net.MalformedURLException; import java.net.URL; 
    import java.util.concurrent.TimeUnit; 
    import org.openqa.selenium.remote.DesiredCapabilities; 
    import io.appium.java_client.AppiumDriver; 
    import io.appium.java_client.MobileElement; 
    import io.appium.java_client.android.AndroidDriver;

    import org.junit.Test;

    public class TedLoginTest {

    @Test

    public void testLoginFB() throws MalformedURLException, InterruptedException    {   

    DesiredCapabilities capabilities = new DesiredCapabilities() ;  

    capabilities.setCapability("automationName","Appium");  
    capabilities.setCapability("platformnName","Android");  
    capabilities.setCapability("platformVersion","7.0");    
    capabilities.setCapability("deviceName","Lucas" );  
    capabilities.setCapability("udid", "5210ce98fa7eb4b3");     
    capabilities.setCapability("app","C:\\Users\\lucas\\Downloads\\TED.apk");
    capabilities.setCapability("appActivity", "com.whirlpool.ted.View.DashboardActivity");
    AndroidDriver driver = new AndroidDriver (new URL ("http://0.0.0.0:4723/wd/hub"), capabilities) ;
    driver.manage().timeouts().implicitlyWait(100,TimeUnit.SECONDS);

    driver.findElementByAndroidUIAutomator("new UiSelector().resourceId(\"com.consul.android.smartbeer.qa:id/edEmail\")").sendKeys("tedusp01@yahoo.com");
    driver.findElementByAndroidUIAutomator("new UiSelector().resourceId(\"com.consul.android.smartbeer.qa:id/edPassword\")").sendKeys("Smart2000");
    driver.findElementByAndroidUIAutomator("new UiSelector().resourceId(\"com.consul.android.smartbeer.qa:id/login\").text(\"Entrar\")").click();
    Thread.sleep(8000);

     }
    }

有谁知道我做错了什么?我错过了任何导入,还是语法错误?

1 个答案:

答案 0 :(得分:0)

在搜索SO时,我发现了许多与此类似的问题,并且它们的答案大致相同。

您需要在声明此活动的AndroidManifest.xml文件中设置android:exported="true"

<activity
    android:name="com.example.lib.MainActivity"
    android:label="LibMain" 
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" >
        </action>
    </intent-filter>
</activity>

参考:https://stackoverflow.com/a/19829733/2533443