-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
8 changed files
with
153 additions
and
20 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
niffler-e-2-e-tests/src/test/java/guru/qa/niffler/condition/Color.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package guru.qa.niffler.condition; | ||
|
||
import lombok.AllArgsConstructor; | ||
|
||
@AllArgsConstructor | ||
public enum Color { | ||
yellow("rgba(255, 183, 3, 1)"), green("rgba(53, 173, 123, 1)"); | ||
|
||
public final String rgb; | ||
} |
83 changes: 83 additions & 0 deletions
83
niffler-e-2-e-tests/src/test/java/guru/qa/niffler/condition/StatConditions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package guru.qa.niffler.condition; | ||
|
||
import com.codeborne.selenide.CheckResult; | ||
import com.codeborne.selenide.Driver; | ||
import com.codeborne.selenide.WebElementCondition; | ||
import com.codeborne.selenide.WebElementsCondition; | ||
import org.apache.commons.lang3.ArrayUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.openqa.selenium.WebElement; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.ParametersAreNonnullByDefault; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static com.codeborne.selenide.CheckResult.accepted; | ||
import static com.codeborne.selenide.CheckResult.rejected; | ||
|
||
@ParametersAreNonnullByDefault | ||
public class StatConditions { | ||
|
||
@Nonnull | ||
public static WebElementCondition color(Color expectedColor) { | ||
return new WebElementCondition("color " + expectedColor.rgb) { | ||
@NotNull | ||
@Override | ||
public CheckResult check(Driver driver, WebElement element) { | ||
final String rgba = element.getCssValue("background-color"); | ||
return new CheckResult( | ||
expectedColor.rgb.equals(rgba), | ||
rgba | ||
); | ||
} | ||
}; | ||
} | ||
|
||
@Nonnull | ||
public static WebElementsCondition color(@Nonnull Color... expectedColors) { | ||
return new WebElementsCondition() { | ||
|
||
private final String expectedRgba = Arrays.stream(expectedColors).map(c -> c.rgb).toList().toString(); | ||
|
||
@NotNull | ||
@Override | ||
public CheckResult check(Driver driver, List<WebElement> elements) { | ||
if (ArrayUtils.isEmpty(expectedColors)) { | ||
throw new IllegalArgumentException("No expected colors given"); | ||
} | ||
if (expectedColors.length != elements.size()) { | ||
final String message = String.format("List size mismatch (expected: %s, actual: %s)", expectedColors.length, elements.size()); | ||
return rejected(message, elements); | ||
} | ||
|
||
boolean passed = true; | ||
final List<String> actualRgbaList = new ArrayList<>(); | ||
for (int i = 0; i < elements.size(); i++) { | ||
final WebElement elementToCheck = elements.get(i); | ||
final Color colorToCheck = expectedColors[i]; | ||
final String rgba = elementToCheck.getCssValue("background-color"); | ||
actualRgbaList.add(rgba); | ||
if (passed) { | ||
passed = colorToCheck.rgb.equals(rgba); | ||
} | ||
} | ||
|
||
if (!passed) { | ||
final String actualRgba = actualRgbaList.toString(); | ||
final String message = String.format( | ||
"List colors mismatch (expected: %s, actual: %s)", expectedRgba, actualRgba | ||
); | ||
return rejected(message, actualRgba); | ||
} | ||
return accepted(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return expectedRgba; | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
niffler-e-2-e-tests/src/test/java/guru/qa/niffler/page/component/StatComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,37 @@ | ||
package guru.qa.niffler.page.component; | ||
|
||
import com.codeborne.selenide.ElementsCollection; | ||
import com.codeborne.selenide.SelenideElement; | ||
import guru.qa.niffler.condition.Color; | ||
import io.qameta.allure.Step; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.imageio.ImageIO; | ||
import java.awt.image.BufferedImage; | ||
import java.io.IOException; | ||
|
||
import static com.codeborne.selenide.Selenide.$; | ||
import static guru.qa.niffler.condition.StatConditions.color; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
public class StatComponent extends BaseComponent<StatComponent> { | ||
public StatComponent() { | ||
super($("#stat")); | ||
} | ||
|
||
private final ElementsCollection bubbles = self.$("#legend-container").$$("li"); | ||
private final SelenideElement chart = $("canvas[role='img']"); | ||
|
||
@Step("Get screenshot of stat chart") | ||
@Nonnull | ||
public BufferedImage chartScreenshot() throws IOException { | ||
return ImageIO.read(requireNonNull(chart.screenshot())); | ||
} | ||
|
||
@Step("Check that stat bubbles contains colors {expectedColors}") | ||
@Nonnull | ||
public StatComponent checkBubbles(Color... expectedColors) { | ||
bubbles.should(color(expectedColors)); | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters