我尝试将“noReset”功能设置为“true”(用户已经登录),并且首先只在Test方法中使用这些语句:
assertTrue(app.dashboardPage().isDashboardOpened());
Thread.sleep(5000);
app.dashboardPage().clickProfileIcon();
assertTrue(app.profilePage().isProfileOpened());
app.profilePage().openSettings();
assertTrue(app.settingsPage().isSettingsOpened());
app.settingsPage().clickNotificationSettings();
assertTrue(app.notificationPage().isNotificationOpened());
assertTrue(app.notificationPage().isToggleOff());
然后它就过去了。
但是,当我尝试在测试中添加这些语句时,我的测试失败(用户必须先登录)
doLogin();
if (app.onboardingPage().isNotificationMessageDisplayed() == true) {
app.onboardingPage().clickNo();
}
if (app.onboardingPage().isUpdateRealAgeDisplayed() == true) {
app.onboardingPage().clickNo();
}
if (app.onboardingPage().isLaterVisible() == true) {
app.onboardingPage().clickLater();
assertTrue(app.onboardingPage().isContinueLaterVisible());
app.onboardingPage().clickDialogYes();
}
当我在屏幕上看到 profile_icon 时,我不明白它是如何产生TimeOutException的。我已经尝试过更改等待时间,但仍会产生TimeOutException。
以下是我的课程:
测试类
@BeforeMethod
public void connect() throws MalformedURLException {
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "7.0");
caps.setCapability("deviceName", "Sony Xperia XA Ultra");
caps.setCapability("appPackage", "---");
caps.setCapability("appActivity", ".ui.MainActivity");
caps.setCapability("noReset", "false");
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
app = new App(driver);
}
public void doLogin() {
app.landingPage().allowPermission();
app.landingPage().goToLoginPage();
credentials = new UserCredentials("lmpgdn@gmail.com", "11111111");
app.loginPage().enterEmailAddress(credentials.getEmailAddress());
app.loginPage().enterPassword(credentials.getPassWord());
app.loginPage().clickLogin();
assertTrue(app.onboardingPage().isOnboardingOpened());
}
@Test (priority = 2)
public void dontAllowNotifications() throws InterruptedException {
doLogin();
if (app.onboardingPage().isNotificationMessageDisplayed() == true) {
app.onboardingPage().clickNo();
}
if (app.onboardingPage().isUpdateRealAgeDisplayed() == true) {
app.onboardingPage().clickNo();
}
if (app.onboardingPage().isLaterVisible() == true) {
app.onboardingPage().clickLater();
assertTrue(app.onboardingPage().isContinueLaterVisible());
app.onboardingPage().clickDialogYes();
}
assertTrue(app.dashboardPage().isDashboardOpened());
Thread.sleep(5000);
app.dashboardPage().clickProfileIcon();
assertTrue(app.profilePage().isProfileOpened());
app.profilePage().openSettings();
assertTrue(app.settingsPage().isSettingsOpened());
app.settingsPage().clickNotificationSettings();
assertTrue(app.notificationPage().isNotificationOpened());
assertTrue(app.notificationPage().isToggleOff());
}
PageObject类
public void clickProfileIcon() {
waitForElementToBeClickable(profile_icon, 15);
profile_icon.click();
}
public boolean isDashboardOpened() {
try {
waitForElementToBeVisibleBy(By.id("toolbar"), 15);
return true;
} catch (NoSuchElementException e) { return false; }
}
@AndroidFindBy(id="toolbar")
private MobileElement toolbar;
@AndroidFindBy(xpath="/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/"
+ "android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/"
+ "android.widget.FrameLayout/android.widget.FrameLayout[3]/android.widget.RelativeLayout/"
+ "android.widget.ViewAnimator/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/"
+ "android.widget.ScrollView/android.widget.RelativeLayout/android.widget.LinearLayout[1]/"
+ "android.widget.FrameLayout/android.view.ViewGroup/android.widget.ImageButton")
private MobileElement profile_icon;
结果
org.openqa.selenium.TimeoutException:预期的条件失败:等待元素可点击:按定位器地图定位: - 原生内容:“By.chained({By.xpath:/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget .FrameLayout / android.widget.FrameLayout / android.widget.FrameLayout / android.widget.FrameLayout [3] /android.widget.RelativeLayout/android.widget.ViewAnimator/android.widget.FrameLayout/android.widget.FrameLayout/android。 widget.FrameLayout / android.widget.ScrollView / android.widget.RelativeLayout / android.widget.LinearLayout 1 / android.widget.FrameLayout / android.view.ViewGroup / android.widget.ImageButton})” - html内容:“通过id或名称”profile_icon“”(尝试15秒,间隔500 MILLISECONDS)