【问题标题】:Unable to execute events in separate class无法在单独的类中执行事件
【发布时间】:2017-06-29 22:35:47
【问题描述】:
**Here are the classes i am using.**

在主页类中使用的操作不起作用。我在设置课程后调用这个课程。

 public class HomePage {

        AndroidDriver driver;

        public  void switchToFlightBook() throws InterruptedException
        {

            WebElement allow2 = driver.findElement(By.xpath("//*[@resource-id='com.cleartrip.android:id/switcher_image']"));

            allow2.click();
            System.out.println("allowed");
    }
    }

这是我用来启动 appium 的设置类。所以像点击这样的动作和我在这里使用的所有动作都可以正常工作,但是当我在主页类中使用相同的动作时它不起作用。

  public class Setup {

         AndroidDriver<WebElement> driver;

        public void launchAppium() throws MalformedURLException {
            File apkFilePath = new File("/Users/practo/Documents/workspace/cleartrip/apps/Cleartrip.apk");
            File app = new File(apkFilePath, "Cleartrip.apk");

            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("device", "Android");
            capabilities.setCapability("deviceName", "Raj");
            capabilities.setCapability("platformName", "Android");
            capabilities.setCapability("autoAcceptAlerts", true);
            capabilities.setCapability("autoDismissAlerts", true);
            capabilities.setCapability("platformVersion", "6.0.1");

            driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);


            WebElement allow2 = driver.findElement(By.xpath("//*[@resource-id='com.android.packageinstaller:id/permission_allow_button']"));
            allow2.click();

        }
    }



public class SearchPageTest {   
    @Test
    public void VerifySearchPage() throws InterruptedException 
    {
        HomePage homepage = new HomePage(); 
        homepage.switchToFlightBook();
    }
    @BeforeTest
      public void beforeTest() throws MalformedURLException 
    {
          System.out.println("Starting setup");
          Setup setup = new Setup();
          setup.launchAppium();
          System.out.println("Setup is done");
      }
    @AfterTest
      public void afterTest() {
          System.out.println("Test case completed");
      }

    }

【问题讨论】:

    标签: java selenium testing appium


    【解决方案1】:

    看起来您没有初始化 HomePage 类的 driver 成员。如果是这种情况,只需将其作为构造函数参数传递给您的 HomePage 类:

    public class HomePage {
      AndroidDriver driver;
    
      public HomePage(AndroidDriver driver) {
        this.driver = driver;
      }
    
      public void switchToFlightBook() throws InterruptedException { ... }
    }
    

    要使其与您介绍的其余架构一起工作,您必须从 Setup 类的 launchAppium 方法返回驱动程序,将其存储在 SearchPageTest 类的成员中并传递它在您实例化 HomePage 类的位置。

    【讨论】:

    • 这真的很有帮助。我能够解决这个问题。谢谢
    猜你喜欢
    • 2010-11-04
    • 1970-01-01
    • 1970-01-01
    • 2016-03-03
    • 2019-12-31
    • 1970-01-01
    • 1970-01-01
    • 2014-02-18
    • 1970-01-01
    相关资源
    最近更新 更多