Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Core components content fragment handling fixes #391

Merged
merged 8 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public DialogField getDialogField(WebElement parentElement, String type) {
private List<WebElement> getFieldElements(WebElement parentElement, String type) {
By selector =
getSelectorFromClass(getClassForType(type), pageObjectInjector.getOriginalInjector())
.orElse(By.cssSelector(Locators.FIELD_WRAPPER_CSS));
.orElse(By.cssSelector(".coral-Form-fieldwrapper"));

return parentElement.findElements(selector);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2019 Cognifide Ltd.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.cognifide.qa.bb.aem.core.component.dialog.dialogfields;

import static org.openqa.selenium.support.ui.ExpectedConditions.not;
import static org.openqa.selenium.support.ui.ExpectedConditions.elementToBeClickable;

import java.util.List;
import java.util.NoSuchElementException;

import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import com.cognifide.qa.bb.qualifier.Global;
import com.cognifide.qa.bb.qualifier.PageObject;
import com.cognifide.qa.bb.wait.BobcatWait;
import com.cognifide.qa.bb.wait.TimingsBuilder;
import com.google.inject.Inject;

/**
* Default implementation of {@link ContentFragmentPathBrowser}
*/
@PageObject(css = Locators.AUTOCOMPLETE_CSS)
public class DefaultContentFragmentPathBrowser implements ContentFragmentPathBrowser {

@FindBy(css = ".coral3-Textfield")
private WebElement input;

@FindBy(xpath = Locators.ALTERNATE_LABEL_XPATH)
private List<WebElement> label;

@FindBy(css = ".foundation-picker-buttonlist.coral3-Overlay.is-open")
private WebElement firstResult;

@Global
@FindBy(css = ".coral3-Dialog--warning.is-open .coral3-Button--primary")
private WebElement warningConfirmation;

@Inject
private BobcatWait bobcatWait;

@Override
public void setValue(Object value) {
input.clear();
input.sendKeys(String.valueOf(value));
bobcatWait.until(elementToBeClickable(firstResult));
input.sendKeys(Keys.ENTER);
closeWarningDialogIfRequired();
}

@Override
public String getLabel() {
return label.isEmpty() ? "" : label.get(0).getText();
}

// The warning dialog doesn't always appear, so it's handled within an if-clause
private void closeWarningDialogIfRequired() {
if (bobcatWait
.tweak(new TimingsBuilder().explicitTimeout(1).build())
.ignoring(NoSuchElementException.class)
.isConditionMet(elementToBeClickable(warningConfirmation))) {
warningConfirmation.click();
bobcatWait.tweak(new TimingsBuilder().explicitTimeout(1).build())
.isConditionMet(not(elementToBeClickable(warningConfirmation)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/**
* Default implementation of {@link Multifield}
*/
@PageObject(css = Locators.MULTIFIELD_CSS)
@PageObject(css = "coral-multifield")
public class DefaultMultifield implements Multifield {

@FindBy(css = "button[coral-multifield-add]")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2019 Cognifide Ltd.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.cognifide.qa.bb.aem.core.component.dialog.dialogfields;

import java.util.List;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import com.cognifide.qa.bb.qualifier.PageObject;

/**
* Default implementation of {@link NumberInput}
*/
@PageObject(css = "coral-numberinput")
public class DefaultNumberInput implements NumberInput {

@FindBy(css = "input")
private WebElement input;

@FindBy(xpath = Locators.ALTERNATE_LABEL_XPATH)
private List<WebElement> label;

@Override
public void setValue(Object value) {
input.clear();
input.sendKeys(String.valueOf(value));
}

@Override
public String getLabel() {
return label.isEmpty() ? "" : label.get(0).getText();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.util.List;

import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

Expand Down Expand Up @@ -52,8 +53,8 @@ public class DefaultPathBrowser implements PathBrowser {
public void setValue(Object value) {
input.clear();
input.sendKeys(String.valueOf(value));

bobcatWait.until(elementToBeClickable(firstResult)).click();
bobcatWait.until(elementToBeClickable(firstResult));
input.sendKeys(Keys.ENTER);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change from the previous implementation?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous implementation didn't support external links, like to github.com - BB would click the first result suggestem by AEM, so a page within the AEM instance instead of github.com

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,23 @@
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import com.cognifide.qa.bb.qualifier.CurrentScope;
import com.cognifide.qa.bb.qualifier.PageObject;
import com.google.inject.Inject;

/**
* Default implementation of {@link Select}
*/
@PageObject(xpath = "//coral-select/..")
@PageObject(css = ".coral3-Select")
public class DefaultSelect implements Select {

private static final String SELECT_OPTIONS_CSS = ".coral3-SelectList-item";

@FindBy(css = ".coral3-Select")
@Inject
@CurrentScope
private WebElement selectField;

@FindBy(css = Locators.LABEL_CSS)
@FindBy(xpath = Locators.ALTERNATE_LABEL_XPATH)
private List<WebElement> label;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,21 @@
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import com.cognifide.qa.bb.qualifier.CurrentScope;
import com.cognifide.qa.bb.qualifier.PageObject;
import com.google.inject.Inject;

/**
* Default implementation of {@link Textfield}
*/
@PageObject(css = Locators.FIELD_WRAPPER_CSS)
@PageObject(css = ".coral3-Textfield:not([type='hidden'])")
public class DefaultTextfield implements Textfield {

@FindBy(css = ".coral3-Textfield:not([type='hidden']")
@Inject
@CurrentScope
private WebElement input;

@FindBy(css = Locators.LABEL_CSS)
@FindBy(xpath = Locators.ALTERNATE_LABEL_XPATH)
private List<WebElement> label;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class Fields {
public static final String RADIO_GROUP = "RADIO_GROUP";
public static final String RICHTEXT = "RICHTEXT";
public static final String TAGBROWSER = "TAGBROWSER";
public static final String NUMBER_INPUT = "NUMBER_INPUT";
public static final String CONTENT_FRAGMENT_PATHBROWSER = "CONTENT_FRAGMENT_PATHBROWSER";

private Fields() {
//empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ private Locators() {
//util
}

public static final String FIELD_WRAPPER_CSS = ".coral-Form-fieldwrapper";
public static final String LABEL_CSS = ".coral-Form-fieldlabel";
public static final String MULTIFIELD_CSS = "coral-multifield";
public static final String AUTOCOMPLETE_CSS = "foundation-autocomplete";
public static final String ALTERNATE_LABEL_XPATH = "../label";
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
import org.slf4j.LoggerFactory;

import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.Checkbox;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.ContentFragmentPathBrowser;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.DefaultContentFragmentPathBrowser;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.DefaultCheckbox;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.DefaultImage;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.DefaultMultifield;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.DefaultMultifieldItem;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.DefaultNumberInput;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.DefaultPathBrowser;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.DefaultRadioGroup;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.DefaultRichText;
Expand All @@ -35,6 +38,7 @@
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.Image;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.Multifield;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.MultifieldItem;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.NumberInput;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.PathBrowser;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.RadioGroup;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.RichText;
Expand Down Expand Up @@ -62,6 +66,8 @@ protected void configure() {
bind(RichText.class).to(DefaultRichText.class);
bind(Select.class).to(DefaultSelect.class);
bind(Textfield.class).to(DefaultTextfield.class);
bind(NumberInput.class).to(DefaultNumberInput.class);
bind(ContentFragmentPathBrowser.class).to(DefaultContentFragmentPathBrowser.class);

install(new FieldsRegistryModule());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.DefaultContentFragmentPathBrowser;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.DefaultCheckbox;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.DefaultImage;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.DefaultMultifield;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.DefaultMultifieldItem;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.DefaultNumberInput;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.DefaultPathBrowser;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.DefaultRadioGroup;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.DefaultRichText;
Expand Down Expand Up @@ -62,12 +64,16 @@ protected void configure() {
registerField(fieldsBinder, Fields.MULTIFIELD_ITEM, DefaultMultifieldItem.class);
registerField(fieldsBinder, Fields.RADIO_GROUP, DefaultRadioGroup.class);
registerField(fieldsBinder, Fields.TAGBROWSER, DefaultTagBrowser.class);
registerField(fieldsBinder, Fields.NUMBER_INPUT, DefaultNumberInput.class);

registerField(fieldsBinder, Fields.RICHTEXT, DefaultRichText.class);
registerField(fieldsBinder, Options.RTE_OPTIONS, RteOption.class);
registerField(fieldsBinder, Options.RTE_OPTIONS_HYPERLINK, Hyperlink.class);
registerField(fieldsBinder, Options.RTE_OPTIONS_LISTS, Lists.class);
registerField(fieldsBinder, Options.RTE_OPTIONS_PARAGRAPH_FORMATS, ParagraphFormats.class);

registerField(fieldsBinder, Fields.CONTENT_FRAGMENT_PATHBROWSER,
DefaultContentFragmentPathBrowser.class);
}

private void registerField(MapBinder<String, DialogField> binder, String name,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2019 Cognifide Ltd.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.cognifide.qa.bb.aem.core.component.dialog.dialogfields;

import com.cognifide.qa.bb.qualifier.PageObjectInterface;

/**
* This class represents path browser dialog field.
*/
@PageObjectInterface
public interface ContentFragmentPathBrowser extends DialogField {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2019 Cognifide Ltd.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.cognifide.qa.bb.aem.core.component.dialog.dialogfields;

import com.cognifide.qa.bb.qualifier.PageObjectInterface;

/**
* This class represents single line number input dialog field.
*/
@PageObjectInterface
public interface NumberInput extends DialogField {
}