**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");
}
}
答案 0 :(得分:1)
您似乎没有初始化driver
类的HomePage
成员。如果是这种情况,只需将其作为构造函数参数传递给HomePage
类:
public class HomePage {
AndroidDriver driver;
public HomePage(AndroidDriver driver) {
this.driver = driver;
}
public void switchToFlightBook() throws InterruptedException { ... }
}
为了使您能够使用所呈现的其余架构,您必须从launchAppium
类的Setup
方法返回驱动程序,将其存储在{{1}的成员中在您实例化SearchPageTest
类的地方传递它。