I am busy testing automation. WebDriiver + Java. PageObject + PageFactory.
Here is the code for the page:
public ManageSubscriptionsTab hitResumeButtonIfDisplayed ( ){ if (resumeSubscriptionButton.isDisplayed()){ resumeSubscriptionButton.click(); } else {cancelSubscriptionButton.click();} return this; } I tried it like this:
public ManageSubscriptionsTab hitResumeButtonIfDisplayed (boolean value ){ if (resumeSubscriptionButton.isDisplayed() == value){ resumeSubscriptionButton.click(); } else {cancelSubscriptionButton.click();} return this; } Essence, if there is no button on the page - press another button. But for some reason, the driver does not perform action, doesn’t perform, or rather, but not correctly. I can’t find the button (resumeSubscriptionButton), but according to the logic of the test, if it doesn’t exist, I need to press another button (cancelSubscriptionButton), but it doesn’t press it, but is still looking for the first one.
here for the test:
@Test public void cancelSubscription (){ LoginPage loginPage = PageFactory.initElements(driver, LoginPage.class); ManageSubscriptionsTab manageSubscriptionsTab = PageFactory.initElements(driver, ManageSubscriptionsTab.class); loginPage.logInToTheAccount("",""); driver.get("https://.../manage-subscription"); manageSubscriptionsTab.hitResumeButtonIfDisplayed(); WebDriverWait wait = (new WebDriverWait(driver, 5)); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[3]/div/div[2]/standard-form/form/div/div/button"))); manageSubscriptionsTab.clickSubmitCancellation(); Assert.assertTrue(manageSubscriptionsTab.yellowContainerIsDisplayed()); String textContainer = manageSubscriptionsTab.whenTheSubscriptionIsCanceledText(); Assert.assertEquals("Your subscription has been canceled. " +