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

Commit

Permalink
Merge pull request #394 from Cognifide/clear-for-dialog-fields
Browse files Browse the repository at this point in the history
Clear for dialog fields
  • Loading branch information
mkrzyzanowski authored Oct 22, 2019
2 parents 096e32a + 1fbaaec commit 3b961c7
Show file tree
Hide file tree
Showing 26 changed files with 300 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ public void configureWith(ComponentConfiguration config) {
/**
* Method used to access DialogField for further configuration.
*
* @param label Label of element to access
* @param tab Name of a tab that element is placed on
* @param label Label of element to access
* @param tab Name of a tab that element is placed on
* @param fieldType Type of field we would like to access
* @return DialogField with our field
*/
Expand All @@ -153,9 +153,9 @@ public DialogField getFieldOnTab(String label, String tab, String fieldType) {
/**
* Method used to configure a field on a dialog.
*
* @param label Label of field to configure
* @param label Label of field to configure
* @param fieldType Type of field to configure
* @param value Value that field will be filled with
* @param value Value that field will be filled with
* @return ConfigDialog this instance
*/
@Override
Expand All @@ -167,7 +167,7 @@ public ConfigDialog setField(String label, String fieldType, Object value) {
/**
* Method can be used to access a field on currently opened tab
*
* @param label Field's label to access
* @param label Field's label to access
* @param fieldType Type of field to access
* @return DialogField with our field
*/
Expand Down Expand Up @@ -204,9 +204,14 @@ private void configure(ComponentConfiguration config) {

private void setFields(List<FieldConfig> value) {
WebElement parent = determineParentScope();
value.forEach(fieldConfig -> dialogConfigurer
.getDialogField(parent, fieldConfig.getLabel(), fieldConfig.getType())
.setValue(fieldConfig.getValue()));
value.forEach(fieldConfig -> {
DialogField field = dialogConfigurer
.getDialogField(parent, fieldConfig.getLabel(), fieldConfig.getType());
if (fieldConfig.getClear()) {
field.clearField();
}
field.setValue(fieldConfig.getValue());
});
}

private WebElement determineParentScope() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.cognifide.qa.bb.aem.core.component.dialog.dialogfields;

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

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

Expand All @@ -40,15 +41,14 @@ public void select() {
}

/**
* Performs click action on the checkbox if passed param is 'true' string.
* Sets the checkbox's state with a click according to the passed boolean value.
*
* @param value string boolean representation
*/
@Override
public void setValue(Object value) {
if (Boolean.valueOf(String.valueOf(value))) {
if (Boolean.valueOf(String.valueOf(value)) != checkboxElement.isSelected()) {
select();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.cognifide.qa.bb.qualifier.PageObject;
import com.cognifide.qa.bb.scope.frame.FramePath;
import com.google.inject.Inject;

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

Expand Down Expand Up @@ -60,5 +61,4 @@ public void setValue(Object value) {
Droppable droppable = dragAndDropFactory.createDroppable(dropArea, FramePath.parsePath("/"));
draggable.dropTo(droppable);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,19 @@ public void setValue(Object value) {
mapper.convertValue(value, new TypeReference<List<MultifieldEntry>>() {
});

items.forEach(MultifieldItem::deleteItem);

cfg.forEach(entry -> addField());
while(items.size() < cfg.size()) {
addField();
}

Iterator<MultifieldItem> itemsIterator = items.iterator();
cfg.forEach(entry -> itemsIterator.next().setValue(entry));
}

@Override
public void clearField() {
items.forEach(MultifieldItem::deleteItem);
}

/**
* Returns MultifieldItem at declared index position
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,4 @@ public void setValue(Object value) {
By.cssSelector(".foundation-picker-buttonlist.coral3-Overlay.is-open")));
currentScope.findElement(By.className("coral-Form-fieldlabel")).click();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ public void setValue(Object value) {
() -> new IllegalStateException("Provided option is not present in the group"));
radioLabel.findElement(By.xpath(".//..")).click();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@

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

import java.util.Arrays;
import java.util.List;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
Expand All @@ -52,18 +54,17 @@ public class RichText implements DialogField {
public void setValue(Object value) {
String text = (String) value;
actions.keyDown(input, CONTROL) //
.sendKeys("a") //
.keyUp(CONTROL) //
.sendKeys(BACK_SPACE);
.sendKeys("a") //
.keyUp(CONTROL) //
.sendKeys(BACK_SPACE);

List<String> textDividedByLines = Arrays.asList(text.split("\\\\n"));
for (int i = 0; i < textDividedByLines.size(); i++) {
if(i!=0) {
if (i != 0) {
actions.sendKeys(RETURN);
}
actions.sendKeys(textDividedByLines.get(i).trim());
}
actions.perform();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
package com.cognifide.qa.bb.aem.core.component.dialog.dialogfields;

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

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
Expand Down Expand Up @@ -51,5 +53,4 @@ public void setValue(Object value) {
.orElseThrow(() -> new NoSuchElementException(
String.format("Option with text %s not found", value.toString()))).click();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.cognifide.qa.bb.aem.core.component.dialog.dialogfields;

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

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

Expand All @@ -42,5 +43,4 @@ public void setValue(Object value) {
input.clear();
input.sendKeys(String.valueOf(value));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ public void configureWith(ComponentConfiguration config) {
/**
* Method used to access DialogField for further configuration.
*
* @param label Label of element to access
* @param tab Name of a tab that element is placed on
* @param label Label of element to access
* @param tab Name of a tab that element is placed on
* @param fieldType Type of field we would like to access
* @return DialogField with our field
*/
Expand All @@ -153,9 +153,9 @@ public DialogField getFieldOnTab(String label, String tab, String fieldType) {
/**
* Method used to configure a field on a dialog.
*
* @param label Label of field to configure
* @param label Label of field to configure
* @param fieldType Type of field to configure
* @param value Value that field will be filled with
* @param value Value that field will be filled with
* @return ConfigDialog this instance
*/
@Override
Expand All @@ -167,7 +167,7 @@ public ConfigDialog setField(String label, String fieldType, Object value) {
/**
* Method can be used to access a field on currently opened tab
*
* @param label Field's label to access
* @param label Field's label to access
* @param fieldType Type of field to access
* @return DialogField with our field
*/
Expand Down Expand Up @@ -205,9 +205,14 @@ private void configure(ComponentConfiguration config) {

private void setFields(List<FieldConfig> value) {
WebElement parent = determineParentScope();
value.forEach(fieldConfig -> dialogConfigurer
.getDialogField(parent, fieldConfig.getLabel(), fieldConfig.getType())
.setValue(fieldConfig.getValue()));
value.forEach(fieldConfig -> {
DialogField field = dialogConfigurer
.getDialogField(parent, fieldConfig.getLabel(), fieldConfig.getType());
if (fieldConfig.getClear()) {
field.clearField();
}
field.setValue(fieldConfig.getValue());
});
}

private WebElement determineParentScope() {
Expand Down
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) 2016 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 All @@ -55,9 +55,9 @@ public void setValue(Object value) {
mapper.convertValue(value, new TypeReference<List<MultifieldEntry>>() {
});

items.forEach(MultifieldItem::deleteItem);

cfg.forEach(entry -> addField());
while(items.size() < cfg.size()) {
addField();
}

Iterator<MultifieldItem> itemsIterator = items.iterator();
cfg.forEach(entry -> itemsIterator.next().setValue(entry));
Expand All @@ -68,6 +68,11 @@ public String getLabel() {
return label.isEmpty() ? "" : label.get(0).getText();
}

@Override
public void clearField() {
items.forEach(MultifieldItem::deleteItem);
}

@Override
public MultifieldItem getItemAtIndex(int index) {
int itemsSize = items.size();
Expand Down
Loading

0 comments on commit 3b961c7

Please sign in to comment.