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 #326 from Cognifide/64sp2
Browse files Browse the repository at this point in the history
AEM 6.4 SP2
  • Loading branch information
mkrzyzanowski committed May 17, 2019
2 parents ab7064c + 4663b37 commit a92de27
Show file tree
Hide file tree
Showing 7 changed files with 355 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import static com.cognifide.qa.bb.constants.HtmlTags.Attributes.CLASS;
import static org.openqa.selenium.support.ui.ExpectedConditions.attributeContains;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
Expand Down Expand Up @@ -55,7 +56,7 @@ public class GlobalBarImpl implements GlobalBar {

@Override
public void toggleSidePanel() {
toggleSidePanelButton.click();
bobcatWait.until(visibilityOf(toggleSidePanelButton)).click();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public DialogField getDialogField(WebElement parentElement, String label, String
List<WebElement> fields = getFields(parentElement, type);

if (fields.isEmpty()) {
throw new IllegalStateException("There are no fields in the tab");
throw new IllegalStateException(String.format(
"There are no fields in the tab matching the following: type=%s, label='%s', parent element=%s",
type, label, parentElement));
}

WebElement scope = StringUtils.isEmpty(label) ? fields.get(0) : fields.stream() //
Expand Down
85 changes: 85 additions & 0 deletions bb-aem-64sp2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
#%L
Bobcat
%%
Copyright (C) 2018 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%
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>bobcat</artifactId>
<groupId>com.cognifide.qa.bb</groupId>
<version>2.0.4-SNAPSHOT</version>
</parent>

<artifactId>bb-aem-64sp2</artifactId>
<name>Bobcat AEM 6.4 SP2</name>

<dependencies>
<dependency>
<groupId>com.cognifide.qa.bb</groupId>
<artifactId>bb-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.cognifide.qa.bb</groupId>
<artifactId>bb-aem-64</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.cognifide.qa.bb</groupId>
<artifactId>bb-aem-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*-
* #%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.aem64sp2.core.component.dialog;

import static org.apache.commons.lang3.StringUtils.containsIgnoreCase;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.cognifide.qa.bb.aem.core.component.dialog.DialogFieldRetriever;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.DialogField;
import com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.Fields;
import com.cognifide.qa.bb.utils.AopUtil;
import com.cognifide.qa.bb.utils.PageObjectInjector;
import com.google.inject.Inject;

/**
* Default AEM 6.4 SP2 Bobcat implementation of the {@link DialogFieldRetriever}
*/
public class DialogFieldRetrieverImpl implements DialogFieldRetriever {

private static final By FIELD_LOCATOR = By.cssSelector(".coral-Form-fieldwrapper");

private static final By LABEL_SELECTOR = By
.cssSelector("label.coral-Form-fieldlabel, label.coral-Form-field");

private static final By CHECKBOX_LABEL_SELECTOR = By
.cssSelector("label.coral3-Checkbox-description");
private static final By IMAGE_LOCATOR = By.cssSelector(".coral-Form-field.cq-FileUpload");
private static final By CHECKBOX_LOCATOR = By.cssSelector(".coral-Form-field.coral3-Checkbox");
private static final By RADIO_GROUP_LOCATOR =
By.cssSelector(".coral-Form-field.coral-RadioGroup");
private static final By RICHTEXT_LOCATOR = By.cssSelector(".coral-Form-field.cq-RichText");
private static final By RICHTEXT_FONT_FORMAT_LOCATOR = By.cssSelector(".rte-ui");

@Inject
private Map<String, DialogField> fieldTypeRegistry;

@Inject
private PageObjectInjector pageObjectInjector;

/**
* Finds the dialog field of given type within a WebElement based on the provided label. If label
* is not present, returns the first field from the tab.
* <p>
* {@inheritDoc}
*/
@Override
public DialogField getDialogField(WebElement parentElement, String label, String type) {
List<WebElement> fields = getFields(parentElement, type);

if (fields.isEmpty()) {
throw new IllegalStateException(String.format(
"There are no fields in the tab matching the following: type=%s, label='%s', parent element=%s",
type, label, parentElement));
}

WebElement scope = StringUtils.isEmpty(label) ? fields.get(0) : fields.stream() //
.filter(field -> containsIgnoreCase(getFieldLabel(field, type), label)) //
.findFirst() //
.orElseThrow(() -> new IllegalStateException(
"Dialog field not found with the provided label: " + label));

return getFieldObject(scope, type);
}

/**
* {@inheritDoc}
*/
@Override
public DialogField getDialogField(WebElement parentElement, String type) {
WebElement scope = parentElement.findElement(By.tagName("input"));
return getFieldObject(scope, type);
}

private List<WebElement> getFields(WebElement parentElement, String type) {
List<WebElement> toReturn;
switch (type) {
case Fields.IMAGE:
toReturn = parentElement.findElements(IMAGE_LOCATOR);
break;
case Fields.CHECKBOX:
toReturn = parentElement.findElements(CHECKBOX_LOCATOR);
break;
case Fields.RADIO_GROUP_MULTI:
toReturn = parentElement.findElements(RADIO_GROUP_LOCATOR);
break;
case Fields.RICHTEXT:
toReturn = parentElement.findElements(RICHTEXT_LOCATOR);
break;
case Fields.RICHTEXT_FONT_FORMAT:
case Fields.RICHTEXT_LIST:
case Fields.RICHTEXT_JUSTIFY:
toReturn = parentElement.findElements(RICHTEXT_FONT_FORMAT_LOCATOR);
break;
default:
toReturn = parentElement.findElements(FIELD_LOCATOR);
break;
}

return toReturn;
}

/**
* Returns the label of given field. Label may not be present in the field, thus a workaround
* using list is introduced here.
*
* @param field WebElement corresponding to the given field
* @return label of the field or {@code StringUtils.Empty} when there is none
*/
private String getFieldLabel(WebElement field, String type) {
List<WebElement> labelField =
type.equals(Fields.CHECKBOX) ? field.findElements(CHECKBOX_LABEL_SELECTOR)
: field.findElements(LABEL_SELECTOR);
return labelField.isEmpty() ? StringUtils.EMPTY : labelField.get(0).getText();
}

private DialogField getFieldObject(WebElement scope, String type) {
DialogField dialogField = fieldTypeRegistry.get(type);
return (DialogField) pageObjectInjector
.inject(AopUtil.getBaseClassForAopObject(dialogField.getClass()), scope);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2018 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.aem64sp2.core.modules;

import com.cognifide.qa.bb.aem.core.modules.AemConfigModule;
import com.cognifide.qa.bb.aem.core.modules.AemCoreModule;
import com.cognifide.qa.bb.aem.core.modules.AemFieldsModule;
import com.cognifide.qa.bb.aem.core.modules.AemLoginModule;
import com.cognifide.qa.bb.aem.core.modules.AemPageModule;
import com.cognifide.qa.bb.aem.core.modules.AemSidePanelModule;
import com.cognifide.qa.bb.aem.core.modules.AemSitesAdminModule;
import com.cognifide.qa.bb.aem.core.modules.SlingPageActionsModule;
import com.google.inject.AbstractModule;

/**
* Main module that needs to be installed to use AEM 6.4 functions.
* <p>
* It install all sub-modules related to AEM 6.4.
*/
public class Aem64SP2FullModule extends AbstractModule {

@Override
protected void configure() {
install(new AemCoreModule());
install(new AemLoginModule());
install(new AemSitesAdminModule());
install(new SlingPageActionsModule());
install(new AemComponentModule());
install(new AemSidePanelModule());
install(new AemPageModule());
install(new AemFieldsModule());
install(new AemConfigModule());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2018 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.aem64sp2.core.modules;

import com.cognifide.qa.bb.aem.core.api.AemActions;
import com.cognifide.qa.bb.aem.core.component.actions.ConfigureComponent;
import com.cognifide.qa.bb.aem.core.component.actions.EditComponent;
import com.cognifide.qa.bb.aem.core.component.dialog.ConfigDialog;
import com.cognifide.qa.bb.aem.core.component.dialog.ConfigDialogImpl;
import com.cognifide.qa.bb.aem.core.component.dialog.DialogFieldRetriever;
import com.cognifide.qa.bb.aem.core.component.toolbar.CommonToolbarOption;
import com.cognifide.qa.bb.aem.core.component.toolbar.CommonToolbarOptions;
import com.cognifide.qa.bb.aem.core.component.toolbar.ComponentToolbar;
import com.cognifide.qa.bb.aem.core.component.toolbar.ComponentToolbarImpl;
import com.cognifide.qa.bb.aem.core.component.toolbar.ToolbarOption;
import com.cognifide.qa.bb.aem64sp2.core.component.dialog.DialogFieldRetrieverImpl;
import com.cognifide.qa.bb.api.actions.ActionWithData;
import com.google.inject.AbstractModule;
import com.google.inject.multibindings.MapBinder;
import java.util.Arrays;

/**
* Module that contains bindings for AEM 6.4 components
*/
public class AemComponentModule extends AbstractModule {

@Override
protected void configure() {
bindComponentActions();
bind(ComponentToolbar.class).to(ComponentToolbarImpl.class);
bind(ConfigDialog.class).to(ConfigDialogImpl.class);
bind(DialogFieldRetriever.class).to(DialogFieldRetrieverImpl.class);
bindCommonToolbarOptions();
}

private void bindComponentActions() {
MapBinder<String, ActionWithData> componentActions =
MapBinder.newMapBinder(binder(), String.class, ActionWithData.class);
componentActions.addBinding(AemActions.EDIT_COMPONENT).to(EditComponent.class);
componentActions.addBinding(AemActions.CONFIGURE_COMPONENT)
.to(ConfigureComponent.class);
}

private void bindCommonToolbarOptions() {
MapBinder<String, ToolbarOption> toolbarOptions =
MapBinder.newMapBinder(binder(), String.class, ToolbarOption.class);
Arrays.stream(CommonToolbarOptions.values()).forEach(
option -> toolbarOptions.addBinding(option.getTitle())
.toInstance(new CommonToolbarOption(option.getTitle())));
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ limitations under the License.
<module>bb-junit5</module>
<module>bb-aem-core</module>
<module>bb-aem-64</module>
<module>bb-aem-64sp2</module>
</modules>

<scm>
Expand Down

0 comments on commit a92de27

Please sign in to comment.