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

Tests for Teaser component #12

Merged
merged 11 commits into from
Oct 15, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.cognifide.qa.bb.aem65.tests.pageobjects.TextComponent;
import com.cognifide.qa.bb.aem65.tests.pageobjects.TextComponentImpl;
import com.cognifide.qa.bb.aem65.tests.pageobjects.corecomponents.teaser.TeaserComponent;
import com.cognifide.qa.bb.aem65.tests.pageobjects.corecomponents.teaser.TeaserComponentImpl;
import com.google.inject.AbstractModule;

/**
Expand All @@ -18,5 +20,6 @@ public class GuiceModule extends AbstractModule {
@Override
protected void configure() {
bind(TextComponent.class).to(TextComponentImpl.class);
bind(TeaserComponent.class).to(TeaserComponentImpl.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no need to create the TeaserComponent interface. I recommend deleting the interface and renaming the TeaserComponentImpl class to TeaserComponent. No binding in the Guice Module required then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.cognifide.qa.bb.aem65.tests.pageobjects.corecomponents.teaser;

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

@PageObjectInterface
public interface TeaserComponent {
Copy link
Contributor

Choose a reason for hiding this comment

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

See the comment for GuiceModule - no Java interface required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


String getTeaserImage();

String getTeaserTitle();

String getTeaserTitleLink();

String getTeaserDescription();

String getTeaserTitleFromLinkedPage();

String getTeaserDescriptionFromLinkedPage();

void checkDescriptionVisibility();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.cognifide.qa.bb.aem65.tests.pageobjects.corecomponents.teaser;

import com.cognifide.qa.bb.constants.HtmlTags;
import com.cognifide.qa.bb.qualifier.CurrentScope;
import com.cognifide.qa.bb.qualifier.PageObject;
import com.cognifide.qa.bb.wait.BobcatWait;
import com.google.inject.Inject;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.springframework.util.Assert;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use assertions from AssertJ or Junit only, to stay consistent throughout the project

Copy link
Contributor Author

Choose a reason for hiding this comment

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

after moved assertion to test class this issue isn't exist anymore


import java.util.List;

@PageObject (css = ".cmp-teaser")
public class TeaserComponentImpl implements TeaserComponent {

@Inject
@CurrentScope
private WebElement component;

@FindBy (css = ".cmp-image__image")
private WebElement image;

@FindBy (css = ".cmp-teaser__title")
private WebElement title;

@FindBy (css = ".cmp-teaser__title-link")
private WebElement titleLink;

@FindBy (css = ".cmp-teaser__description > p")
private WebElement description;

@FindBy (css = ".cmp-teaser__description")
private List<WebElement> elements;

@FindBy (css = ".cmp-teaser__description")
private WebElement isDescriptionVisible;

@Inject
private BobcatWait bobcatWait;

public void checkDescriptionVisibility(){
Assert.isTrue(elements.isEmpty(),"Element exist when it shouldn't");
Copy link
Contributor

@kaczymuczy kaczymuczy Oct 14, 2019

Choose a reason for hiding this comment

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

Please keep assertions in test classes only, for maximum visibility and role separation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, I moved assertion into test class

}

public String getTeaserDescriptionFromLinkedPage() { return isDescriptionVisible.getAttribute(HtmlTags.Properties.INNER_HTML); }

public String getTeaserImage() { return image.getAttribute(HtmlTags.Attributes.TITLE); }

public String getTeaserTitle() { return title.getAttribute(HtmlTags.Properties.INNER_HTML); }

public String getTeaserTitleFromLinkedPage() { return titleLink.getAttribute(HtmlTags.Properties.INNER_HTML); }

public String getTeaserTitleLink () { return titleLink.getAttribute(HtmlTags.Properties.OUTER_HTML);}

public String getTeaserDescription () { return description.getAttribute(HtmlTags.Properties.INNER_HTML);}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package com.cognifide.qa.bb.aem65.tests.corecomponents;

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.teaser.TeaserComponent;
import com.cognifide.qa.bb.aem65.tests.pageobjects.corecomponents.teaser.TeaserComponentImpl;
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 com.cognifide.qa.bb.wait.BobcatWait;
import com.google.inject.Inject;
import io.qameta.allure.Epic;
import io.qameta.allure.Feature;
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 static org.assertj.core.api.Assertions.assertThat;

@Modules(BobcatRunModule.class)
@Epic("Core Components authoring tests")
@Feature("Teaser Component configuration")
@DisplayName("Author can configure for Teaser Component the...")


public class TeaserComponentTest extends AbstractAemAuthorTest {

private static final String TEST_PAGE_PATH = "/content/we-retail/us/en/teaserComponentTestPage";

private TestPage page;
private TeaserComponentImpl component;

@Inject
private BobcatWait bobcatWait;

@BeforeEach
public void createAndOpenTestPage() throws ActionException {
controller.execute(AemActions.CREATE_PAGE_VIA_SLING, new SlingPageData(TEST_PAGE_PATH,
SlingDataXMLBuilder.buildFromFile("testpages/core-components/teaserComponentTestPage.xml")));
page = bobcatPageFactory.create("/editor.html" + TEST_PAGE_PATH + ".html", TestPage.class);
page.open();
}

@Test
@DisplayName("image")
public void configureImageTeaser() throws ActionException {
controller.execute(AemActions.CONFIGURE_COMPONENT,
new ConfigureComponentData("container", "Teaser (v1)", 0,
new ResourceFileLocation("component-configs/core-components/teaser/image.yaml")));
component = (TeaserComponentImpl) page.getContent(TeaserComponent.class, 0);
assertThat(component.getTeaserImage())
.as("Check if image is configured")
.matches("Gray lava rock formation");
}

@Test
@DisplayName("title")
public void configureTitle() throws ActionException {
controller.execute(AemActions.CONFIGURE_COMPONENT,
new ConfigureComponentData("container", "Teaser (v1)", 0,
new ResourceFileLocation("component-configs/core-components/teaser/title.yaml")));
component = (TeaserComponentImpl) page.getContent(TeaserComponent.class,0);
assertThat(component.getTeaserTitle().replaceAll("[\r\n]", "").replaceAll("^\\s+","").replaceFirst("\\s++$", ""))
.as("Check if the title is configured")
.matches("This is teaser title");
}

@Test
@DisplayName("link on title")
public void configureTitleLink() throws ActionException {
controller.execute(AemActions.CONFIGURE_COMPONENT,
new ConfigureComponentData("container", "Teaser (v1)", 0,
new ResourceFileLocation("component-configs/core-components/teaser/titleLink.yaml")));
component = (TeaserComponentImpl) page.getContent(TeaserComponent.class, 0);
assertThat(component.getTeaserTitleLink().replaceAll("[\r\n]", "").replaceAll("\"","").replaceAll("<a class=","").replaceFirst("cmp-teaser__title-link", "").replaceFirst(">This is teaser title</a>", "").replaceAll("^\\s+","").replaceFirst("\\s++$", ""))
.as("Check if the link is configured")
.matches("href=/content/core-components-examples/library/teaser.html");
}


@Test
@DisplayName("title taken from linked page")
public void configureTitleFromLinkedPage() throws ActionException {
controller.execute(AemActions.CONFIGURE_COMPONENT,
new ConfigureComponentData("container", "Teaser (v1)", 0,
new ResourceFileLocation("component-configs/core-components/teaser/titleFromLinkedPage.yaml")));
component = (TeaserComponentImpl) page.getContent(TeaserComponent.class,0);
assertThat(component.getTeaserTitleFromLinkedPage().replaceAll("[\r\n]", "").replaceAll("^\\s+","").replaceFirst("\\s++$", ""))
.as("Check if the title is taken from linked page")
.matches("Women");
}

@Test
@DisplayName("description")
public void configureDescription() throws ActionException {
controller.execute(AemActions.CONFIGURE_COMPONENT,
new ConfigureComponentData("container", "Teaser (v1)", 0,
new ResourceFileLocation("component-configs/core-components/teaser/description.yaml")));
component = (TeaserComponentImpl) page.getContent(TeaserComponent.class,0);
assertThat(component.getTeaserDescription().replaceAll("[\r\n]", "").replaceAll("^\\s+","").replaceFirst("\\s++$", ""))
.as("Check if the descriotion is configured")
Copy link
Contributor

Choose a reason for hiding this comment

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

description

.matches("This is teaser description<br>");
}

@Test
@DisplayName("empty description taken from linked page")
public void configureDescriptionFromLinkedPage() throws ActionException {
controller.execute(AemActions.CONFIGURE_COMPONENT,
new ConfigureComponentData("container", "Teaser (v1)", 0,
new ResourceFileLocation("component-configs/core-components/teaser/descriptionEmptyFromLinkedPage.yaml")));
component = (TeaserComponentImpl) page.getContent(TeaserComponent.class,0);
component.checkDescriptionVisibility();
}

@Test
@DisplayName("description taken from linked page")
public void configureDescriptionFromLinkedPage2() throws ActionException {
controller.execute(AemActions.CONFIGURE_COMPONENT,
new ConfigureComponentData("container", "Teaser (v1)", 0,
new ResourceFileLocation("component-configs/core-components/teaser/descriptionFromLinkedPage.yaml")));
component = (TeaserComponentImpl) page.getContent(TeaserComponent.class,0);
assertThat(component.getTeaserDescriptionFromLinkedPage())
.as("Check if the description is taken from linked page")
.matches("Test description from Properties");
}

@AfterEach
public void deleteTestPage() throws ActionException {
controller.execute(AemActions.DELETE_PAGE_VIA_SLING, new SlingPageData(TEST_PAGE_PATH));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Link &amp; Actions:
- label: Link
type: PATHBROWSER
value: https://cognifide.github.io/bobcat/
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Text:
- label: Title
type: TEXTFIELD
value: This is teaser title

- label: Description
type: RICHTEXT
value: This is teaser description
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Text:
- label: Title
type: TEXTFIELD
value: This is teaser title

- label: Description
type: RICHTEXT
value: This is teaser description

- label: Get description from linked page
type: CHECKBOX
value: true

Link & Actions:
- label: Link
type: PATHBROWSER
value: /content/we-retail/language-masters/en/women
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Link & Actions:
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of configuring multiple dialog fields in one test I suggest only to configure the verified fields, and the rest have preconfigured and created by Sling. So you then have multiple components with different configs delivered by Sling and only choose which component to work on during a test case - much faster than configuring everything with Bobcat in the UI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done - I extended content on test page

- label: Link
type: PATHBROWSER
value: /content/we-retail/us/en/teaserComponentTestPage

Text:
- label: Title
type: TEXTFIELD
value: This is teaser title

- label: Description
type: RICHTEXT
value: This is teaser description

- label: Get description from linked page
type: CHECKBOX
value: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Image:
- type: IMAGE
value: lava-rock-formation.jpg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Text:
- label: Title
type: TEXTFIELD
value: This is teaser title
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Text:
- label: Get title from linked page
type: CHECKBOX
value: true

Link & Actions:
- label: Link
type: PATHBROWSER
value: /content/we-retail/language-masters/en/women
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Text:
- label: Title
type: TEXTFIELD
value: This is teaser title

Link & Actions:
- label: Link
type: PATHBROWSER
value: /content/core-components-examples/library/teaser
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="cq:Page">
<jcr:content
cq:template="/conf/core-components-examples/settings/wcm/templates/content-page"
jcr:description="Test description from Properties"
jcr:primaryType="cq:PageContent"
jcr:title="Teaser Component Test Page"
sling:resourceType="core-components-examples/components/page"
navTitle="Teaser Component Test Page"
pageTitle="Teaser Component Test Page">
<root
jcr:primaryType="nt:unstructured"
sling:resourceType="wcm/foundation/components/responsivegrid">
<responsivegrid
jcr:primaryType="nt:unstructured"
sling:resourceType="wcm/foundation/components/responsivegrid">
<teaser
jcr:primaryType="nt:unstructured"
sling:resourceType="core/wcm/components/teaser/v1/teaser"/>
</responsivegrid>
</root>
</jcr:content>
</jcr:root>