由于未识别PageFactory,因此无法在Appium中执行操作

时间:2018-07-25 06:42:31

标签: selenium-webdriver appium appium-android page-factory

我要启动并执行诸如在应用程序中输入用户名详细信息之类的操作  但由于错误

,我的执行一次又一次失败
My Code 




public class VerifyProjectFromApp {

    WebDriver driver;
    AppLaunch toDoistAppLaunch;
    HomePage homePage;
    LoginPage login;

    @BeforeMethod
    public void startapplication() {
        toDoistAppLaunch= new AppLaunch(driver);        
        this.driver=toDoistAppLaunch.launchApplication();   
    }

    @Test
    public void verifyCreatedProjectInApp() {
     try{   
        //-Read create project value from properties file
        Properties prop = new Properties();
        InputStream input = null;
        input = new FileInputStream(System.getProperty("user.dir") + 

File.separator +“ TodoistInputData.properties”);             prop.load(input);

        //-Read uuid from properties file 
        String email_id = prop.getProperty("email_id");
        System.out.println("\t" + "email_id =" + email_id + "\r\n");

        //-Read project name from properties file 
        String password = prop.getProperty("password");
        System.out.println("\t" + "projectName =" + password + "\r\n");

        login = new LoginPage(driver);
        homePage = new HomePage(driver);
        login.loginInApplication(email_id, password);
        Utils.waitForPageLoadingToComplete(driver);
        homePage.clickOnSideMenu();
        Utils.pauseTestExecution(10);

     } catch (Exception e) {
         e.printStackTrace();
     }

    }



===================================================

public class LoginPage {

    public static final String packageName = "com.todoist";
    AndroidDriver<MobileElement> driver;

     public LoginPage(WebDriver driver){
      this.driver = (AndroidDriver<MobileElement>)driver;
      PageFactory.initElements(new AppiumFieldDecorator(driver), this);
     }

     @AndroidFindBy(id=packageName+":id/btn_welcome_continue_with_email")
     MobileElement continueButtonWithGmail;

     @AndroidFindBy(id=packageName+":id/email_exists_input")
     MobileElement enterEmailId;

     @AndroidFindBy(id=packageName+":id/log_in_password")
     MobileElement enterPassword;

     @AndroidFindBy(id=packageName+":id/btn_continue_with_email")
     MobileElement loginwithGmail;

     @AndroidFindBy(id=packageName+":id/btn_log_in")
     MobileElement loginButton;


     public void clickOnContinueButtonWithGmail() {
         continueButtonWithGmail.click();
     }

     public void enterEmailAddress(String emailId) {
         enterEmailId.sendKeys(emailId);
     }

     public void enterPassword(String pass) {
         enterPassword.sendKeys(pass);
     }

     public void clickOnGmailButton() {
         loginwithGmail.click();
     }

     public void clickOnLoginButton() {
         loginButton.click();
     }

     public void loginInApplication(String emailId,String password) {
      try {
         clickOnContinueButtonWithGmail();
         Utils.waitForPageLoadingToComplete(driver);
         enterEmailAddress(emailId);
         Utils.waitForPageLoadingToComplete(driver);
         clickOnGmailButton();
         Utils.waitForPageLoadingToComplete(driver);
         enterPassword(password);
         Utils.waitForPageLoadingToComplete(driver);
         clickOnLoginButton(); 
      } catch(Exception e) {
          e.printStackTrace();
      }      
     } 

================================================ ==========================================

出现错误

[TestNG] Running:
  C:\Users\Daffodil-255\AppData\Local\Temp\testng-eclipse--467741697\testng-customsuite.xml

Print app path E:\TodoistAutomation\Android_Todoist_Project\apkfile\Todoist_v12.8_apkpure.com.apk
Jul 25, 2018 11:57:52 AM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: W3C
    email_id =tarun.dabbs@daffodilsw.com

    projectName =123456

Jul 25, 2018 11:57:52 AM org.openqa.selenium.remote.ErrorCodes toStatus
INFO: HTTP Status: '404' -> incorrect JSON status mapping for 'unknown method' (405 expected)
FAILED CONFIGURATION: @AfterMethod closeApplication
org.openqa.selenium.UnsupportedCommandException: Method has not yet been implemented
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:32:14.902Z'
System info: host: 'DAFFODILLAP-265', ip: '172.18.1.128', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_65'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {app: E:\TodoistAutomation\Androi..., appActivity: com.todoist.activity.HomeAc..., appPackage: com.todoist, appium-version: 1.8.1, databaseEnabled: false, desired: {app: E:\TodoistAutomation\Androi..., appActivity: com.todoist.activity.HomeAc..., appPackage: com.todoist, appium-version: 1.8.1, deviceName: Nexus5X1, platformName: android, platformVersion: 7.1.1}, deviceManufacturer: Google, deviceModel: Android SDK built for x86, deviceName: emulator-5554, deviceScreenSize: 1080x1920, deviceUDID: emulator-5554, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, platform: LINUX, platformName: Android, platformVersion: 7.1.1, takesScreenshot: true, warnings: {}, webStorageEnabled: false}
Session ID: 7333c28b-2ec8-48b2-89c0-b04e2c90ec74
    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:422)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:231)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:46)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.close(RemoteWebDriver.java:438)
    at com.todoist.tests.VerifyProjectFromApp.closeApplication(VerifyProjectFromApp.java:61)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:703)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:774)
    at org.testng.TestRunner.run(TestRunner.java:624)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
    at org.testng.SuiteRunner.run(SuiteRunner.java:261)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
    at org.testng.TestNG.run(TestNG.java:1048)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)

FAILED: verifyCreatedProjectInApp
java.lang.NoClassDefFoundError: net/sf/cglib/proxy/MethodInterceptor
    at com.todoist.pages.LoginPage.<init>(LoginPage.java:22)
    at com.todoist.tests.VerifyProjectFromApp.verifyCreatedProjectInApp(VerifyProjectFromApp.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:774)
    at org.testng.TestRunner.run(TestRunner.java:624)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
    at org.testng.SuiteRunner.run(SuiteRunner.java:261)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
    at org.testng.TestNG.run(TestNG.java:1048)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
Caused by: java.lang.ClassNotFoundException: net.sf.cglib.proxy.MethodInterceptor
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 26 more


===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
    Configuration Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================

[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@19bb089b: 171 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@35bbe5e8: 14 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@6bdf28bb: 8 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@1fbc7afb: 65 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@129a8472: 15 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 11 ms

2 个答案:

答案 0 :(得分:0)

问题是由于以下原因发生的:

ClassNotFoundException: net.sf.cglib.proxy.MethodInterceptor

要解决此问题,您需要添加cglib:cglib依赖项:

<!-- https://mvnrepository.com/artifact/cglib/cglib -->
<dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib</artifactId>
    <version>3.2.7</version>
</dependency>

希望这会有所帮助,

答案 1 :(得分:0)

在您的项目中同时添加cglib和asm依赖项。这样可以解决您的问题。