wttech/bobcat

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

henrykuijpers opened this issue · 3 comments

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.

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();
    }
}

Any thoughts @mkrzyzanowski ?