diff --git a/aem65/build.gradle b/aem65/build.gradle index 03290f5..25ffbc1 100644 --- a/aem65/build.gradle +++ b/aem65/build.gradle @@ -36,7 +36,7 @@ def profiles = [ ] task loadProperties { - System.setProperty("bobcat.config", "yaml"); + System.setProperty("bobcat.config", "yaml") def profile = System.getProperty('profile', 'default') if (!profile.equals('default')) { System.setProperty("bobcat.config.contexts", profiles[profile]) diff --git a/aem65/src/main/java/com/cognifide/qa/bb/aem65/tests/pageobjects/corecomponents/ImageComponent.java b/aem65/src/main/java/com/cognifide/qa/bb/aem65/tests/pageobjects/corecomponents/ImageComponent.java new file mode 100644 index 0000000..2e8c8c0 --- /dev/null +++ b/aem65/src/main/java/com/cognifide/qa/bb/aem65/tests/pageobjects/corecomponents/ImageComponent.java @@ -0,0 +1,39 @@ +package com.cognifide.qa.bb.aem65.tests.pageobjects.corecomponents; + +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +import com.cognifide.qa.bb.constants.HtmlTags.Attributes; +import com.cognifide.qa.bb.qualifier.CurrentScope; +import com.cognifide.qa.bb.qualifier.PageObject; +import com.google.inject.Inject; + +@PageObject(css = ".cmp-image__image") +public class ImageComponent { + + @Inject + @CurrentScope + private WebElement component; + + @FindBy(xpath = "../span[contains(@class,'cmp-image__title')]") + private WebElement caption; + + @FindBy(xpath = "..") + private WebElement link; + + public String getSrc() { + return component.getAttribute(Attributes.SRC); + } + + public String getAlt() { + return component.getAttribute(Attributes.ALT); + } + + public String getCaption() { + return caption.getText(); + } + + public String getLink() { + return link.getAttribute(Attributes.HREF); + } +} diff --git a/aem65/src/test/java/com/cognifide/qa/bb/aem65/tests/corecomponents/ImageComponentTest.java b/aem65/src/test/java/com/cognifide/qa/bb/aem65/tests/corecomponents/ImageComponentTest.java new file mode 100644 index 0000000..5ba138b --- /dev/null +++ b/aem65/src/test/java/com/cognifide/qa/bb/aem65/tests/corecomponents/ImageComponentTest.java @@ -0,0 +1,104 @@ +package com.cognifide.qa.bb.aem65.tests.corecomponents; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import com.cognifide.qa.bb.aem.core.api.AemActions; +import com.cognifide.qa.bb.aem.core.component.actions.ConfigureComponentData; +import com.cognifide.qa.bb.aem.core.component.configuration.ResourceFileLocation; +import com.cognifide.qa.bb.aem.core.pages.sling.SlingDataXMLBuilder; +import com.cognifide.qa.bb.aem.core.pages.sling.SlingPageData; +import com.cognifide.qa.bb.aem65.tests.AbstractAemAuthorTest; +import com.cognifide.qa.bb.aem65.tests.pageobjects.corecomponents.ImageComponent; +import com.cognifide.qa.bb.aem65.tests.pages.TestPage; +import com.cognifide.qa.bb.api.actions.ActionException; +import com.cognifide.qa.bb.junit5.guice.Modules; +import com.cognifide.qa.bb.modules.BobcatRunModule; + +import io.qameta.allure.Epic; +import io.qameta.allure.Feature; + +@Modules(BobcatRunModule.class) +@Epic("Core Components authoring tests") +@Feature("Image Component configuration") +@DisplayName("Author can configure for Image Component the...") +public class ImageComponentTest extends AbstractAemAuthorTest { + + private static final String TEST_PAGE_PATH = "/content/we-retail/us/en/image-component-test-page"; + + private TestPage page; + private ImageComponent component; + + @BeforeEach + public void setup() throws ActionException { + controller.execute(AemActions.CREATE_PAGE_VIA_SLING, new SlingPageData(TEST_PAGE_PATH, + SlingDataXMLBuilder.buildFromFile("testpages/core-components/imageComponentTestPage.xml"))); + page = bobcatPageFactory.create("/editor.html" + TEST_PAGE_PATH + ".html", TestPage.class); + page.open(); + } + + @Test + @DisplayName("asset") + public void configureAsset() throws ActionException { + controller.execute(AemActions.CONFIGURE_COMPONENT, + new ConfigureComponentData("container", "Image", 1, + new ResourceFileLocation("component-configs/core-components/image/asset.yaml"))); + component = page.getContent(ImageComponent.class, 1); + assertThat(component.getSrc()).as("Check if the img src is configured") + .matches(String.format(".*%s.*majestic-rainbow.jpeg", TEST_PAGE_PATH)); + } + + @Test + @DisplayName("decorative image metadata") + public void configureDecorativeImage() throws ActionException { + controller.execute(AemActions.CONFIGURE_COMPONENT, + new ConfigureComponentData("container", "Image", 0, new ResourceFileLocation( + "component-configs/core-components/image/decorative-image.yaml"))); + component = page.getContent(ImageComponent.class, 0); + assertThat(component.getAlt()).as("Check if the alt attribute is empty").isEmpty(); + } + + @Test + @DisplayName("alternative text metadata") + public void configureAlternativeText() throws ActionException { + controller.execute(AemActions.CONFIGURE_COMPONENT, + new ConfigureComponentData("container", "Image", 0, new ResourceFileLocation( + "component-configs/core-components/image/alt-text.yaml"))); + component = page.getContent(ImageComponent.class, 0); + assertThat(component.getAlt()).as("Check if the alt text is configured") + .matches("Custom alt text"); + + } + + @Test + @DisplayName("caption metadata") + public void configureCaption() throws ActionException { + controller.execute(AemActions.CONFIGURE_COMPONENT, + new ConfigureComponentData("container", "Image", 0, + new ResourceFileLocation("component-configs/core-components/image/caption.yaml"))); + component = page.getContent(ImageComponent.class, 0); + assertThat(component.getCaption()).as("Check if the caption text is configured") + .matches("Custom caption"); + } + + @Test + @DisplayName("link metadata") + public void configureLink() throws ActionException { + controller.execute(AemActions.CONFIGURE_COMPONENT, + new ConfigureComponentData("container", "Image", 0, + new ResourceFileLocation("component-configs/core-components/image/link.yaml"))); + component = page.getContent(ImageComponent.class, 0); + assertThat(component.getLink()).as("Check if the link is configured") + .endsWith("/content/we-retail/us/en.html"); + } + + @AfterEach + public void cleanup() throws ActionException { + controller.execute(AemActions.DELETE_PAGE_VIA_SLING, new SlingPageData(TEST_PAGE_PATH)); + } + +} diff --git a/aem65/src/test/resources/component-configs/core-components/image/alt-text.yaml b/aem65/src/test/resources/component-configs/core-components/image/alt-text.yaml new file mode 100644 index 0000000..b13aa31 --- /dev/null +++ b/aem65/src/test/resources/component-configs/core-components/image/alt-text.yaml @@ -0,0 +1,7 @@ +Metadata: +- label: Get alternative text from DAM + type: CHECKBOX + value: false +- label: Alternative Text * + type: TEXTFIELD + value: Custom alt text \ No newline at end of file diff --git a/aem65/src/test/resources/component-configs/core-components/image/asset.yaml b/aem65/src/test/resources/component-configs/core-components/image/asset.yaml new file mode 100644 index 0000000..ae716f2 --- /dev/null +++ b/aem65/src/test/resources/component-configs/core-components/image/asset.yaml @@ -0,0 +1,3 @@ +Asset: +- type: IMAGE + value: majestic-rainbow.jpg \ No newline at end of file diff --git a/aem65/src/test/resources/component-configs/core-components/image/caption.yaml b/aem65/src/test/resources/component-configs/core-components/image/caption.yaml new file mode 100644 index 0000000..ea9be03 --- /dev/null +++ b/aem65/src/test/resources/component-configs/core-components/image/caption.yaml @@ -0,0 +1,10 @@ +Metadata: +- label: Get caption from DAM + type: CHECKBOX + value: false +- label: Caption + type: TEXTFIELD + value: Custom caption +- label: Display caption as pop-up + type: CHECKBOX + value: false \ No newline at end of file diff --git a/aem65/src/test/resources/component-configs/core-components/image/decorative-image.yaml b/aem65/src/test/resources/component-configs/core-components/image/decorative-image.yaml new file mode 100644 index 0000000..52f99ae --- /dev/null +++ b/aem65/src/test/resources/component-configs/core-components/image/decorative-image.yaml @@ -0,0 +1,4 @@ +Metadata: +- label: Image is decorative + type: CHECKBOX + value: true \ No newline at end of file diff --git a/aem65/src/test/resources/component-configs/core-components/image/link.yaml b/aem65/src/test/resources/component-configs/core-components/image/link.yaml new file mode 100644 index 0000000..23c166d --- /dev/null +++ b/aem65/src/test/resources/component-configs/core-components/image/link.yaml @@ -0,0 +1,4 @@ +Metadata: +- label: Link + type: PATHBROWSER + value: /content/we-retail/us/en \ No newline at end of file diff --git a/aem65/src/test/resources/testpages/core-components/imageComponentTestPage.xml b/aem65/src/test/resources/testpages/core-components/imageComponentTestPage.xml new file mode 100644 index 0000000..20f471b --- /dev/null +++ b/aem65/src/test/resources/testpages/core-components/imageComponentTestPage.xml @@ -0,0 +1,33 @@ + + + + + + + + + + +