gpt4 book ai didi

java - 无法在单独的类中执行事件

转载 作者:行者123 更新时间:2023-11-28 21:25:22 25 4
gpt4 key购买 nike

**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");
}

}

最佳答案

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

public class HomePage {
AndroidDriver driver;

public HomePage(AndroidDriver driver) {
this.driver = driver;
}

public void switchToFlightBook() throws InterruptedException { ... }
}

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

关于java - 无法在单独的类中执行事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42178694/

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