wttech / bobcat

Bobcat is an automated testing framework for functional testing of web applications.
https://cognifide.github.io/bobcat/
Apache License 2.0
91 stars 40 forks source link

CreatePageWizardImpl uses labels to find buttons, which will not work if the UI has a different language #465

Open henrykuijpers opened 3 years ago

henrykuijpers commented 3 years ago

In CreatePageWizardImpl, there are 3 button labels ("Next", "Create" and "Done"), which are used to find certain buttons in the Create Page Wizard.

However, these button labels are in English and our project is in Dutch, so we are unable to find those buttons and therefore the code is failing to execute.

It is unacceptable for us to translate the buttons back to English.

I would suggest to find a better way to find these buttons and click them. Or, but I think that's a worse solution, make the button text configurable in some way.

henrykuijpers commented 3 years ago

I suggest the following implementation, replacing the one that is present now:

/**
 * Default Bobcat implementation of {@link CreatePageWizard} for AEM 6.4
 */
@PageObject(css = "form.cq-siteadmin-admin-createpage")
public class CreatePageWizardImpl implements CreatePageWizard {
    @FindBy(css = "[type=submit][data-foundation-wizard-control-action=next]")
    private WebElement createButton;

    @FindBy(css = "[type=button][data-foundation-wizard-control-action=next]")
    private WebElement nextButton;

    @FindPageObject
    private TemplateList templateList;

    @Global
    @FindPageObject
    private CreatePageProperties createPageProperties;

    @Global
    @FindBy(css = ".coral3-Dialog-wrapper")
    private WebElement pageCreatedModal;

    @Inject
    protected BobcatWait wait;

    @Override
    @Step("Select template {templateName}")
    public CreatePageWizard selectTemplate(String templateName) {
        templateList.selectTemplate(templateName);
        nextButton.click();
        return this;
    }

    @Override
    @Step("Provide name {name}")
    public CreatePageWizard provideName(String name) {
        createPageProperties.getNameTextField().sendKeys(name);
        return this;
    }

    @Override
    @Step("Provide title {title}")
    public CreatePageWizard provideTitle(String title) {
        createPageProperties.getTitleTextField().sendKeys(title);
        return this;
    }

    @Override
    @Step("Submit page for creation")
    public void submit() {
        wait.until(input -> createButton.isEnabled());
        createButton.click();
        List<WebElement> elements =
                pageCreatedModal.findElements(By.cssSelector(".coral3-Dialog--success [variant='secondary']"));

        elements.stream()
                .findFirst()
                .orElseThrow(() -> new NoSuchElementException("\"Done\" button not found"))
                .click();
    }
}
henrykuijpers commented 3 years ago

Any thoughts @mkrzyzanowski ?

henrykuijpers commented 3 years ago

@mkrzyzanowski ping