Skip to content

Commit

Permalink
#5310 Fix some validators
Browse files Browse the repository at this point in the history
  • Loading branch information
pnatashap committed Apr 11, 2024
1 parent 77ee404 commit 572f0f8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.com.dataproviders.ColorPickersDataProviders;
import io.github.epam.TestsInit;
import org.hamcrest.Matchers;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -50,19 +51,20 @@ public void fullCanvasColorPickerTest(String colorValue,
double initialAlphaSliderStyle = fullCanvasColorPicker.alphaSlider().value();
fullCanvasColorPicker.setColor(colorValue);
fullCanvasColorPicker.has().dotColor(colorValue)
.and().hueSliderValueHaveChanged(initialHueSliderStyle);
.and().hueSliderValue(Matchers.not(initialHueSliderStyle));
fullCanvasColorPicker.setColor(transparentColorValue);
fullCanvasColorPicker.has().dotColor(transparentColorValue)
.and().alphaSliderValueHaveChanged(initialAlphaSliderStyle);
.and().alphaSliderValue(Matchers.not(initialAlphaSliderStyle));
}

// @todo #5310 Test is not stable, as initial state can differ from RGBA
@Test(description = "Test checks color picking from a non-canvas slider")
public void noCanvasColorPickerTest() {
noCanvasColorPicker.show();
noCanvasColorPicker.has().inputModel(RGBA);
noCanvasColorPicker.colorModelButton().click();
noCanvasColorPicker.changeEditStyleButton().click();
noCanvasColorPicker.has().inputModel(HSLA);
noCanvasColorPicker.colorModelButton().click();
noCanvasColorPicker.changeEditStyleButton().click();
noCanvasColorPicker.has().inputModel(HEX)
.and().hexInputFieldStringColorValue(INITIAL_HEX_STRING_COLOR);
}
Expand All @@ -78,10 +80,8 @@ public void elevationColorPickerTest() {
@Test(description = "Test checks color picker without input fields")
public void noInputColorPickerTest() {
noInputsColorPicker.show();
noInputsColorPicker.has().canvasStyle()
.and().canvasDotStyle()
.and().hueSliderValue()
.and().alphaSliderValue()
noInputsColorPicker.has().hueSliderValue(Matchers.notNullValue())
.and().alphaSliderValue(Matchers.notNullValue())
.and().dotColor(INITIAL_RGBA_STRING_COLOR);
}

Expand All @@ -101,45 +101,45 @@ public void modelColorPickerTest() {
modelColorPicker.show();
hexModelButton.click();
modelColorPicker.has().inputModel(RGB);
modelColorPicker.colorModelButton().click();
modelColorPicker.changeEditStyleButton().click();
modelColorPicker.has().inputModel(HSL);
modelColorPicker.colorModelButton().click();
modelColorPicker.changeEditStyleButton().click();
modelColorPicker.has().inputModel(HEX)
.and().hexInputFieldLength(NO_ALPHA_HEX_LENGTH);
modelColorPicker.colorModelButton().click();
modelColorPicker.changeEditStyleButton().click();

hexaModelButton.click();
modelColorPicker.has().inputModel(RGBA);
modelColorPicker.colorModelButton().click();
modelColorPicker.changeEditStyleButton().click();
modelColorPicker.has().inputModel(HSLA);
modelColorPicker.colorModelButton().click();
modelColorPicker.changeEditStyleButton().click();
modelColorPicker.has().inputModel(HEX)
.and().hexInputFieldLength(ALPHA_HEX_LENGTH);
modelColorPicker.colorModelButton().click();
modelColorPicker.changeEditStyleButton().click();

rgbaModelButton.click();
modelColorPicker.has().inputModel(RGBA);
modelColorPicker.colorModelButton().click();
modelColorPicker.changeEditStyleButton().click();
modelColorPicker.has().inputModel(HSLA);
modelColorPicker.colorModelButton().click();
modelColorPicker.changeEditStyleButton().click();
modelColorPicker.has().inputModel(HEX)
.and().hexInputFieldLength(ALPHA_HEX_LENGTH);
modelColorPicker.colorModelButton().click();
modelColorPicker.changeEditStyleButton().click();

hslaModelButton.click();
modelColorPicker.has().inputModel(RGBA);
modelColorPicker.colorModelButton().click();
modelColorPicker.changeEditStyleButton().click();
modelColorPicker.has().inputModel(HSLA);
modelColorPicker.colorModelButton().click();
modelColorPicker.changeEditStyleButton().click();
modelColorPicker.has().inputModel(HEX);
modelColorPicker.has().hexInputFieldLength(ALPHA_HEX_LENGTH);
modelColorPicker.colorModelButton().click();
modelColorPicker.changeEditStyleButton().click();

hsvaModelButton.click();
modelColorPicker.has().inputModel(RGBA);
modelColorPicker.colorModelButton().click();
modelColorPicker.changeEditStyleButton().click();
modelColorPicker.has().inputModel(HSLA);
modelColorPicker.colorModelButton().click();
modelColorPicker.changeEditStyleButton().click();
modelColorPicker.has().inputModel(HEX)
.and().hexInputFieldLength(ALPHA_HEX_LENGTH);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,31 @@
import com.epam.jdi.light.vuetify.elements.complex.ColorPicker;
import com.epam.jdi.light.vuetify.interfaces.asserts.ElevationAssert;
import com.epam.jdi.light.vuetify.interfaces.asserts.ThemeAssert;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.openqa.selenium.support.Color;

import static com.epam.jdi.light.asserts.core.SoftAssert.jdiAssert;

// @todo #5310 Add more assertion with Matcher inside (like alphaSliderValue), we can not see all required
public class ColorPickerAssert extends UIAssert<ColorPickerAssert, ColorPicker> implements
ElevationAssert<ColorPickerAssert, ColorPicker>, ThemeAssert<ColorPickerAssert, ColorPicker> {

@JDIAction(value = "Assert that '{name}' canvas has style", isAssert = true)
public ColorPickerAssert canvasStyle() {
jdiAssert(element().getCanvasStyle(), Matchers.is(Matchers.notNullValue()),
"ColorPicker has not canvas style");
return this;
}

@JDIAction(value = "Assert that '{name}' canvasDot has style", isAssert = true)
public ColorPickerAssert canvasDotStyle() {
jdiAssert(element().getCanvasDotStyle(), Matchers.is(Matchers.notNullValue()),
"ColorPicker has not dot style");
return this;
}

@JDIAction(value = "Assert that '{name}' input model is '{0}'", isAssert = true)
public ColorPickerAssert inputModel(String inputModel) {
String actualInputModel = element().getInputModel();
jdiAssert(actualInputModel, Matchers.is(inputModel));
return this;
}

@JDIAction(value = "Assert that '{name}' hueSlider has value", isAssert = true)
public ColorPickerAssert hueSliderValue() {
jdiAssert(element().hueSlider().value(), Matchers.is(Matchers.notNullValue()),
"ColorPicker has not slider value");
return this;
}

@JDIAction(value = "Assert that '{name}' alphaSlider has value", isAssert = true)
public ColorPickerAssert alphaSliderValue() {
jdiAssert(element().alphaSlider().value(), Matchers.is(Matchers.notNullValue()),
"ColorPicker has not slider value");
jdiAssert(element().getInputModel(), Matchers.is(inputModel));
return this;
}

// @todo #5048 Check this method naming and logic
@JDIAction(value = "Assert that '{name}' hueSlider value have changed", isAssert = true)
public ColorPickerAssert hueSliderValueHaveChanged(double initialValue) {
jdiAssert(element().hueSlider().value(), Matchers.not(initialValue), "Hue slider value wasn't changed");
@JDIAction(value = "Assert that '{name}' hueSlider matches {0}", isAssert = true)
public ColorPickerAssert hueSliderValue(Matcher<Object> value) {
jdiAssert(element().hueSlider().value(), value);
return this;
}

@JDIAction(value = "Assert that '{name}' alphaSlider value have changed", isAssert = true)
public ColorPickerAssert alphaSliderValueHaveChanged(double initialValue) {
jdiAssert(element().alphaSlider().value(), Matchers.not(initialValue),
"Alpha slider value wasn't changed");
@JDIAction(value = "Assert that '{name}' alphaSlider matches {0}", isAssert = true)
public ColorPickerAssert alphaSliderValue(Matcher<Object> value) {
jdiAssert(element().alphaSlider().value(), value);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
/**
* To see example of ColoPicker web element please visit https://v2.vuetifyjs.com/en/components/color-pickers/
*/

// @todo #5310 Simplify and refactor this element, too many hardcoded values. Check if all colors are possible to get
public class ColorPicker extends UIBaseElement<ColorPickerAssert> implements HasElevation, HasTheme {

public static final String STYLE = "style";
public static final String DIV = "div";
public static final String SPAN = "span";
public static final String RGBA = "RGBA";
public static final String RGB = "RGB";
public static final String HSLA = "HSLA";
Expand All @@ -39,13 +38,13 @@ public class ColorPicker extends UIBaseElement<ColorPickerAssert> implements Has
protected static final String HUE_SLIDER_LOCATOR = "div.v-color-picker__hue";
protected static final String ALPHA_SLIDER_LOCATOR = "div.v-color-picker__alpha";
protected static final String DOT_LOCATOR = "div.v-color-picker__dot div";
protected static final String INPUTS_MODEL_LOCATOR = "div.v-color-picker__edit div";
protected static final String INPUTS_MODEL_LOCATOR = ".v-color-picker__edit .v-color-picker__input";
protected static final String INPUT_FIRST_LOCATOR = "div.v-color-picker__edit div:nth-of-type(1)";
protected static final String INPUT_SECOND_LOCATOR = "div.v-color-picker__edit div:nth-of-type(2)";
protected static final String INPUT_THIRD_LOCATOR = "div.v-color-picker__edit div:nth-of-type(3)";
protected static final String INPUT_FOURTH_LOCATOR = "div.v-color-picker__edit div:nth-of-type(4)";
protected static final String INPUT_HEX_LOCATOR = "div.v-color-picker__input";
protected static final String BUTTON_LOCATOR = "button";
protected static final String EDIT_STYLE_BUTTON_LOCATOR = "button";
protected static final String SWATCHES_LOCATOR = ".v-color-picker__swatches .v-color-picker__color";

@Override
Expand Down Expand Up @@ -93,8 +92,9 @@ public TextField inputHEX() {
return new TextField().setCore(TextField.class, core().find(INPUT_HEX_LOCATOR));
}

public Button colorModelButton() {
return new Button().setCore(Button.class, core().find(BUTTON_LOCATOR));
@JDIAction("Get {name}'s button to change style for editor between RGBA/HEX/HSLA")
public Button changeEditStyleButton() {
return new Button().setCore(Button.class, core().find(EDIT_STYLE_BUTTON_LOCATOR));
}

public WebList swatches() {
Expand All @@ -115,22 +115,12 @@ public void setColor(String value) {
inputA().setText(alpha);
}

@JDIAction("Get canvas style from '{name}'")
public String getCanvasStyle() {
return getElementStyle(canvas());
}

@JDIAction("Get canvasDot style from '{name}'")
public String getCanvasDotStyle() {
return getElementStyle(canvasDot());
}

@JDIAction("Get input model from '{name}'")
public String getInputModel() {
StringBuilder inputModel = new StringBuilder();
WebList inputsList = core().finds(INPUTS_MODEL_LOCATOR);
for (UIElement inputField : inputsList) {
inputModel.append(inputField.find(SPAN).getText());
inputModel.append(inputField.getText());
}
return inputModel.toString();
}
Expand Down

0 comments on commit 572f0f8

Please sign in to comment.