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

Commit

Permalink
Merge pull request #20 from Cognifide/core-components-form-components…
Browse files Browse the repository at this point in the history
…-tests

Core components form components tests
  • Loading branch information
kaczymuczy authored Dec 17, 2019
2 parents 4baf0c3 + 285fa2b commit 340d45c
Show file tree
Hide file tree
Showing 25 changed files with 1,004 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.cognifide.qa.bb.aem65.tests.pageobjects.corecomponents.formcomponents;

import org.openqa.selenium.WebElement;

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

@PageObject(css = "button.cmp-form-button")
public class FormButtonComponent {

@CurrentScope
@Inject
private WebElement component;

public String getType() {
return component.getAttribute("type");
}

public String getTitle() {
return component.getText();
}

public String getName() {
return component.getAttribute("name");
}

public String getValue() {
return component.getAttribute("value");
}

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

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 = "form.cmp-form")
public class FormContainerComponent {

@CurrentScope
@Inject
private WebElement component;

@FindBy(css = "input[name=':redirect']")
private WebElement thankYouPagePathPropertyElement;

public boolean isDisplayed() {
return component.isDisplayed();
}

public String getThankYouPagePath() {
return thankYouPagePathPropertyElement.getAttribute(Attributes.VALUE);
}

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

import org.openqa.selenium.WebElement;

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

@PageObject(css = ".hidden > input")
public class FormHiddenComponent {

@CurrentScope
@Inject
private WebElement component;

public String getId() {
return component.getAttribute("id");
}

public String getName() {
return component.getAttribute("name");
}

public String getValue() {
return component.getAttribute("value");
}

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

import java.util.List;
import java.util.stream.Collectors;

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

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

@PageObject(css = "fieldset.cmp-form-options")
public class FormOptionsComponent {

@FindBy(css = "legend")
private WebElement title;

@FindBy(css = "p.cmp-form-options__help-message")
private WebElement helpMessage;

@FindPageObject
private List<FormOptionsComponentField> fields;

public String getTitle() {
return title.getText();
}

public String getHelpMessage() {
return helpMessage.getText();
}

public List<String> getFieldTypes() {
return fields.stream().map(FormOptionsComponentField::getType).collect(Collectors.toList());
}

public List<String> getFieldNames() {
return fields.stream().map(FormOptionsComponentField::getName).collect(Collectors.toList());
}

public List<String> getFieldValues() {
return fields.stream().map(FormOptionsComponentField::getValue).collect(Collectors.toList());
}

public List<String> getFieldTexts() {
return fields.stream().map(FormOptionsComponentField::getText).collect(Collectors.toList());
}

public boolean isFieldSelected(int fieldNumber) {
return fields.get(fieldNumber).isSelected();
}

public boolean isFieldEnabled(int fieldNumber) {
return fields.get(fieldNumber).isEnabled();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.cognifide.qa.bb.aem65.tests.pageobjects.corecomponents.formcomponents;

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

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

@PageObject(css = "label.cmp-form-options__field-label")
public class FormOptionsComponentField {

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

@FindBy(css = "span")
private WebElement label;

public String getType() {
return input.getAttribute("type");
}

public String getName() {
return input.getAttribute("name");
}

public String getValue() {
return input.getAttribute("value");
}

public String getText() {
return label.getText();
}

public boolean isSelected() {
return input.isSelected();
}

public boolean isEnabled() {
return input.isEnabled();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.cognifide.qa.bb.aem65.tests.pageobjects.corecomponents.formcomponents;

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;

@PageObject(css = "input.cmp-form-text__text")
public class FormTextComponent {

@CurrentScope
@Inject
private WebElement component;

@FindBy(xpath = "./..")
private WebElement wrapper;

public String getConstraint() {
return component.getAttribute("type");
}

public String getAriaLabel() {
return component.getAttribute("aria-label");
}

public String getElementName() {
return component.getAttribute("name");
}

public String getValue() {
return component.getAttribute("value");
}

public String getPlaceholder() {
return component.getAttribute("placeholder");
}

public boolean isReadOnly() {
return Boolean.parseBoolean(component.getAttribute("readonly"));
}

public String getConstraintMessage() {
return wrapper.getAttribute("data-cmp-constraint-message");
}

public String getRequiredMessage() {
return wrapper.getAttribute("data-cmp-required-message");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,58 +22,65 @@
import io.qameta.allure.Epic;
import io.qameta.allure.Feature;

/**
* These tests verify if Bobcat can handle the configuration of the Breadcrumb Component
* https://opensource.adobe.com/aem-core-wcm-components/library/breadcrumb.html
*/
@Modules(BobcatRunModule.class)
@Epic("Core Components authoring tests")
@Feature("Breadcrumb Component configuration")
@DisplayName("Author can configure for Breadcrumb Component the...")
public class BreadcrumbComponentTest extends AbstractAemAuthorTest {

private static final String HIDDEN_PAGE_PATH = "/content/core-components-examples/breadcrumbhiddentestpage";
private static final String COMPONENT_PAGE_PATH =
"/content/core-components-examples/breadcrumbhiddentestpage/breadcrumbtestpage";
private static final String HIDDEN_PAGE_PATH = "/content/core-components-examples/breadcrumbhiddentestpage";
private static final String COMPONENT_PAGE_PATH =
"/content/core-components-examples/breadcrumbhiddentestpage/breadcrumbtestpage";

private TestPage testPage;
private BreadcrumbComponent component;
private TestPage testPage;
private BreadcrumbComponent component;

@BeforeEach
public void createAndOpenTestPage() throws ActionException {
controller.execute(AemActions.CREATE_PAGE_VIA_SLING, new SlingPageData(HIDDEN_PAGE_PATH,
SlingDataXMLBuilder.buildFromFile(
"testpages/core-components/breadcrumb/breadcrumbComponentHiddenTestPage.xml")));
@BeforeEach
public void createAndOpenTestPage() throws ActionException {
controller.execute(AemActions.CREATE_PAGE_VIA_SLING, new SlingPageData(HIDDEN_PAGE_PATH,
SlingDataXMLBuilder.buildFromFile(
"testpages/core-components/breadcrumb/breadcrumbComponentHiddenTestPage.xml")));

controller.execute(AemActions.CREATE_PAGE_VIA_SLING, new SlingPageData(COMPONENT_PAGE_PATH,
SlingDataXMLBuilder.buildFromFile(
"testpages/core-components/breadcrumb/breadcrumbComponentTestPage.xml")));
controller.execute(AemActions.CREATE_PAGE_VIA_SLING, new SlingPageData(COMPONENT_PAGE_PATH,
SlingDataXMLBuilder.buildFromFile(
"testpages/core-components/breadcrumb/breadcrumbComponentTestPage.xml")));

testPage = bobcatPageFactory.create("/editor.html" + COMPONENT_PAGE_PATH + ".html", TestPage.class);
testPage.open();
}
testPage = bobcatPageFactory
.create("/editor.html" + COMPONENT_PAGE_PATH + ".html", TestPage.class);
testPage.open();
}

@Test
@DisplayName("navigation start level - decrease default value")
public void decreaseNavigationStartLevel() throws ActionException {
controller.execute(AemActions.CONFIGURE_COMPONENT,
new ConfigureComponentData("container", "Breadcrumb (v2)", 0,
new ResourceFileLocation("component-configs/core-components/breadcrumb/navigation-start-level.yaml")));
component = testPage.getContent(BreadcrumbComponent.class, 0);
assertThat(component.getText()).as("Check if breadcrumb value contains first level page")
.contains("Core Components");
}
@Test
@DisplayName("navigation start level - decrease default value")
public void decreaseNavigationStartLevel() throws ActionException {
controller.execute(AemActions.CONFIGURE_COMPONENT,
new ConfigureComponentData("container", "Breadcrumb (v2)", 0,
new ResourceFileLocation(
"component-configs/core-components/breadcrumb/navigation-start-level.yaml")));
component = testPage.getContent(BreadcrumbComponent.class, 0);
assertThat(component.getText()).as("Check if breadcrumb value contains first level page")
.contains("Core Components");
}

@Test
@DisplayName("checkbox values change to true")
public void changeCheckboxesToTrue() throws ActionException {
controller.execute(AemActions.CONFIGURE_COMPONENT,
new ConfigureComponentData("container", "Breadcrumb (v2)", 0,
new ResourceFileLocation("component-configs/core-components/breadcrumb/checkbox-configuration.yaml")));
component = testPage.getContent(BreadcrumbComponent.class, 0);
assertThat(component.getText()).as("Check if current page is not present in breadcrumb")
.doesNotContain("breadcrumbTestPage").contains("breadcrumbHiddenTestPage");
}
@Test
@DisplayName("checkbox values change to true")
public void changeCheckboxesToTrue() throws ActionException {
controller.execute(AemActions.CONFIGURE_COMPONENT,
new ConfigureComponentData("container", "Breadcrumb (v2)", 0,
new ResourceFileLocation(
"component-configs/core-components/breadcrumb/checkbox-configuration.yaml")));
component = testPage.getContent(BreadcrumbComponent.class, 0);
assertThat(component.getText()).as("Check if current page is not present in breadcrumb")
.doesNotContain("breadcrumbTestPage").contains("breadcrumbHiddenTestPage");
}

@AfterEach
public void deleteTestPage() throws ActionException {
controller.execute(AemActions.DELETE_PAGE_VIA_SLING, new SlingPageData(COMPONENT_PAGE_PATH));
controller.execute(AemActions.DELETE_PAGE_VIA_SLING, new SlingPageData(HIDDEN_PAGE_PATH));
}
@AfterEach
public void deleteTestPage() throws ActionException {
controller.execute(AemActions.DELETE_PAGE_VIA_SLING, new SlingPageData(COMPONENT_PAGE_PATH));
controller.execute(AemActions.DELETE_PAGE_VIA_SLING, new SlingPageData(HIDDEN_PAGE_PATH));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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.google.inject.Inject;

import io.qameta.allure.Epic;
import io.qameta.allure.Feature;
Expand All @@ -35,6 +36,9 @@ public class ContentFragmentListComponentTest extends AbstractAemAuthorTest {
private TestPage page;
private ContentFragmentListComponent component;

@Inject
private SoftAssertions softly;

@BeforeEach
public void setup() throws ActionException {
controller.execute(AemActions.CREATE_PAGE_VIA_SLING, new SlingPageData(TEST_PAGE_PATH,
Expand Down Expand Up @@ -64,13 +68,12 @@ public void configureParentPath() throws ActionException {
new ResourceFileLocation(
"component-configs/core-components/content-fragment-list/parent-path.yaml")));
component = page.getContent(ContentFragmentListComponent.class, 1);
SoftAssertions softly = new SoftAssertions();
softly.assertThat(component.getArticleTexts().get(0))
.as("Check if the first article from the parent path is displayed")
.matches("^Accepted Currency(.*|\\n)*processing$");
.matches("^Cancellations(.*|\\n)*processing$");
softly.assertThat(component.getArticleTexts().get(3))
.as("Check if the last article from the parent path is displayed")
.matches("^Cancellations(.*|\\n)*processing$");
.matches("^Product Purchase Locations(.*|\\n)*processing$");
softly.assertAll();
}

Expand All @@ -95,7 +98,6 @@ public void configureElementsToDisplay() throws ActionException {
new ResourceFileLocation(
"component-configs/core-components/content-fragment-list/elements.yaml")));
component = page.getContent(ContentFragmentListComponent.class, 1);
SoftAssertions softly = new SoftAssertions();
softly.assertThat(component.getArticleTexts().get(0))
.as("Check if the element selection is configured properly for the first article")
.matches("^The Company Name(.*|\\n)*\"We.Retail\"\\?");
Expand Down
Loading

0 comments on commit 340d45c

Please sign in to comment.