Skip to content

Commit

Permalink
Refactored report layout comparison dialog test
Browse files Browse the repository at this point in the history
  • Loading branch information
martingrossmann committed Dec 3, 2024
1 parent e3c8207 commit 16cc42f
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.testerra.report.test.pages.report.methodReport;

import eu.tsystems.mms.tic.testframework.pageobjects.AbstractComponent;
import eu.tsystems.mms.tic.testframework.pageobjects.Check;
import eu.tsystems.mms.tic.testframework.pageobjects.Page;
import eu.tsystems.mms.tic.testframework.pageobjects.PreparedLocator;
Expand All @@ -10,59 +11,72 @@

import java.util.HashMap;

public class ComparisonDialogOverlay extends Page implements AssertProvider {
public class ComparisonDialogOverlay extends AbstractComponent<ComparisonDialogOverlay> implements AssertProvider {
@Check
private final UiElement contrastIcon = findIconInDialog("compare");
private final UiElement contrastIcon = find(By.xpath("//mdc-icon[text() = 'compare']"));
@Check
private final UiElement switchIcon = findIconInDialog("compare_arrows");
private final UiElement switchIcon = find(By.xpath("//mdc-icon[text() = 'compare_arrows']"));
@Check
private final UiElement leftSelection = find(By.xpath("//mdc-select[@label='Left']"));
@Check
private final UiElement rightSelection = find(By.xpath("//mdc-select[@label='Right']"));
@Check
private final UiElement slider= find(By.xpath("//div[contains(@class,'slider')]"));
private final UiElement selectedItemLeft = leftSelection.find(By.xpath("//span[contains(@class,'selected-text')]"));
private final UiElement selectedItemRight = rightSelection.find(By.xpath("//span[contains(@class,'selected-text')]"));
PreparedLocator itemLocator = LOCATE.prepare("//span[text()='%s']");
// private final UiElement selectedItemLeft = leftSelection.find(By.xpath("//span[contains(@class,'selected-text')]"));
// private final UiElement selectedItemRight = rightSelection.find(By.xpath("//span[contains(@class,'selected-text')]"));
// PreparedLocator itemLocator = LOCATE.prepare("//span[text()='%s']");

public ComparisonDialogOverlay(WebDriver webDriver) {
super(webDriver);
}
private final UiElement content = find(By.xpath("//div[contains(@class,'img-comp-container')]"));

PreparedLocator selectedScreenshotOption = LOCATE.prepare("//mdc-select[@label='%s']//span[contains(@class,'selected-text')]//span[text()='%s']");

private final UiElement closeIcon = find(By.xpath("//button//span[text()='clear']"));

private UiElement findIconInDialog(String icon){
return find(By.xpath(String.format("//mdc-icon[text()='%s']",icon)));
public ComparisonDialogOverlay(UiElement rootElement) {
super(rootElement);
}

public ReportDetailsTab closeDialog() {
UiElement closeBtn = find(By.xpath("//button//span[text()='clear']"));
closeBtn.click();
this.closeIcon.click();
return createPage(ReportDetailsTab.class);
}

public void checkSelectedAndContentFromStartingMatched(String state) {
HashMap<String, String> stateMapping = new HashMap<String, String>();
stateMapping.put("Actual", "Difference");
stateMapping.put("Difference", "Expected");
stateMapping.put("Expected", "Difference");
public void checkContent(final ReportDetailsTab.ScreenshotType leftType, final ReportDetailsTab.ScreenshotType rightType, final String imageName) {
UiElement leftSelectedOption = find(selectedScreenshotOption.with("Left", leftType.toString()));
UiElement rightSelectedOption = find(selectedScreenshotOption.with("Right", rightType.toString()));

HashMap<String, String> screenshotMapping = new HashMap<String, String>();
screenshotMapping.put("Actual", "actual_difference_referenceImage");
screenshotMapping.put("Difference", "difference_expected_referenceImage");
screenshotMapping.put("Expected", "expected_difference_referenceImage");
leftSelectedOption.assertThat().displayed(true);
rightSelectedOption.assertThat().displayed(true);

CONTROL.collectAssertions(()->{
UiElement defaultSelectedItemLeft = selectedItemLeft.find(itemLocator.with(state));
UiElement imgContent = find(By.xpath("//div[contains(@class,'img-comp-container')]"));
defaultSelectedItemLeft.expect().displayed(true);
String expectedRightState = stateMapping.get(state);
String screenshotReference = screenshotMapping.get(state);
ASSERT.assertNotNull(expectedRightState);

UiElement defaultSelectedItemRight = selectedItemRight.find(itemLocator.with(expectedRightState));
defaultSelectedItemRight.expect().displayed(true);
imgContent.expect().screenshot().pixelDistance(screenshotReference).isLowerThan(10);
final String referenceImageName = String.format("%s_%s_%s", imageName, leftType, rightType);
this.content.assertThat().screenshot().pixelDistance(referenceImageName).isLowerThan(1);
}

});
// public void checkSelectedAndContentFromStartingMatched(String state) {
// HashMap<String, String> stateMapping = new HashMap<String, String>();
// stateMapping.put("Actual", "Difference");
// stateMapping.put("Difference", "Expected");
// stateMapping.put("Expected", "Difference");
//
// HashMap<String, String> screenshotMapping = new HashMap<String, String>();
// screenshotMapping.put("Actual", "actual_difference_referenceImage");
// screenshotMapping.put("Difference", "difference_expected_referenceImage");
// screenshotMapping.put("Expected", "expected_difference_referenceImage");
//
// CONTROL.collectAssertions(()->{
// UiElement defaultSelectedItemLeft = selectedItemLeft.find(itemLocator.with(state));
// UiElement imgContent = find(By.xpath("//div[contains(@class,'img-comp-container')]"));
// defaultSelectedItemLeft.expect().displayed(true);
// String expectedRightState = stateMapping.get(state);
// String screenshotReference = screenshotMapping.get(state);
// ASSERT.assertNotNull(expectedRightState);
//
// UiElement defaultSelectedItemRight = selectedItemRight.find(itemLocator.with(expectedRightState));
// defaultSelectedItemRight.expect().displayed(true);
// imgContent.expect().screenshot().pixelDistance(screenshotReference).isLowerThan(10);
//
// });
//
// }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public class ReportDetailsTab extends AbstractReportMethodPage {
private final UiElement layoutComparison = find(By.xpath("//layout-comparison"));
PreparedLocator imgTitleLocator = LOCATE.prepare("//img[contains(@title,'%s')]");

// Root element of every overly component
private final UiElement dialogRoot = find(By.xpath("//div[@class = 'mdc-dialog__container']"));

public ReportDetailsTab(WebDriver driver) {
super(driver);
}
Expand Down Expand Up @@ -211,9 +214,15 @@ public boolean hasFailureAspectAScreenshotComparison(String failureMessage) {
return this.getFailureAspectElement(failureMessage).find(By.xpath("//layout-comparison")).waitFor().present(true);
}

public ComparisonDialogOverlay openComparisonDialogByClickingOnScreenShot(String imageTitle) {
UiElement image = layoutComparison.find(imgTitleLocator.with(imageTitle));
public ComparisonDialogOverlay openComparisonDialogByClickingOnScreenShot(final ScreenshotType screenshotType) {
UiElement image = layoutComparison.find(imgTitleLocator.with(screenshotType.toString()));
image.click();
return createPage(ComparisonDialogOverlay.class);
return createComponent(ComparisonDialogOverlay.class, this.dialogRoot);
}

public enum ScreenshotType {
Actual,
Difference,
Expected;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.testerra.report.test.pages.report.sideBarPages.ReportDashBoardPage;
import io.testerra.report.test.pages.report.sideBarPages.ReportTestsPage;
import org.testng.annotations.Test;
import io.testerra.report.test.pages.report.methodReport.ReportDetailsTab.ScreenshotType;

public class LayoutTest extends AbstractReportTest {

Expand Down Expand Up @@ -153,27 +154,30 @@ public void testT05_checkPassedLayoutTestAndFailedAssertion() {
}

@Test
public void testT06_checkLayoutDialog(){
public void testT06_checkLayoutDialog() {
String methodName = "layoutTest01_layoutTestFailing";
String className = "GenerateLayoutTestsTTReportTest";

String[] imageTitles = new String[]{
"Actual",
"Difference",
"Expected"
};
// String[] imageTitles = new String[]{
// "Actual",
// "Difference",
// "Expected"
// };

TestStep.begin("Navigate to details page");
ReportDashBoardPage reportDashBoardPage = this.gotoDashBoardOnAdditionalReport(WEB_DRIVER_MANAGER.getWebDriver());
ReportTestsPage reportTestsPage = reportDashBoardPage.gotoToReportPage(ReportSidebarPageType.TESTS, ReportTestsPage.class);
reportTestsPage.selectClassName(className);
ReportDetailsTab reportDetailsTab = reportTestsPage.navigateToDetailsTab(methodName);
TestStep.begin("Open Layout Dialog");
for(String title: imageTitles){
ComparisonDialogOverlay comparisonDialogOverlay = reportDetailsTab.openComparisonDialogByClickingOnScreenShot(title);
comparisonDialogOverlay.checkSelectedAndContentFromStartingMatched(title);
reportDetailsTab = comparisonDialogOverlay.closeDialog();
}

TestStep.begin("Open Layout Dialog from actual image");
// for(String title: imageTitles){
// ComparisonDialogOverlay comparisonDialogOverlay = reportDetailsTab.openComparisonDialogByClickingOnScreenShot(title);
ComparisonDialogOverlay comparisonDialogOverlay = reportDetailsTab.openComparisonDialogByClickingOnScreenShot(ScreenshotType.Actual);
comparisonDialogOverlay.checkContent(ScreenshotType.Actual, ScreenshotType.Difference, "layout_compare_dialog");
// comparisonDialogOverlay.checkSelectedAndContentFromStartingMatched(title);
reportDetailsTab = comparisonDialogOverlay.closeDialog();
// }
}

}
1 change: 0 additions & 1 deletion report-ng-tests/src/test/resources/test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ tt.browser.maximize=false
tt.display.resolution=1600x1024

#tt.element.timeout.seconds=3
tt.screencaster.active=false

#tt.selenium.server.host=localhost

Expand Down

0 comments on commit 16cc42f

Please sign in to comment.