Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add step to verify element CSS properties #5586

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vkepin
Copy link
Contributor

@vkepin vkepin commented Dec 10, 2024

No description provided.

@vkepin vkepin force-pushed the check_css_step branch 2 times, most recently from 8ca7cdb to e6ac923 Compare December 10, 2024 19:30
@vkepin vkepin marked this pull request as ready for review December 10, 2024 19:30
@vkepin vkepin requested a review from a team as a code owner December 10, 2024 19:30
@vkepin vkepin force-pushed the check_css_step branch 2 times, most recently from 489be47 to c36fc43 Compare December 10, 2024 19:50
Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.70%. Comparing base (7b21f68) to head (d6156f1).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5586      +/-   ##
============================================
- Coverage     97.70%   97.70%   -0.01%     
- Complexity     7126     7395     +269     
============================================
  Files           987      992       +5     
  Lines         20669    20750      +81     
  Branches       1353     1353              
============================================
+ Hits          20195    20274      +79     
- Misses          363      364       +1     
- Partials        111      112       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


[source,gherkin]
----
Then context element has CSS properties:$parameters
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Then context element has CSS properties:$parameters
Then context element has CSS properties matching rules:$parameters

----

* `$parameters` - The xref:ROOT:glossary.adoc#_examplestable[ExamplesTable] containing the following columns:
** [subs=+quotes]`*cssName*` - A name of the CSS property.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
** [subs=+quotes]`*cssName*` - A name of the CSS property.
** [subs=+quotes]`*cssProperty*` - A name of the CSS property.

<meta charset="utf-8">
<title>CSS properties validation results table</title>
<link rel="stylesheet" href="../../styles.css"/>
<link rel="stylesheet" href="../../webjars/bootstrap/3.4.1/css/bootstrap.min.css"/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

please use bootstrap 5 (it's also available in webjars)

* @param parameters The parameters of the expected CSS properties to set as ExamplesTable
*/
@Then("context element has CSS properties:$parameters")
public void doesElementHasCssProperties(ExamplesTable parameters)
Copy link
Collaborator

Choose a reason for hiding this comment

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

does it make sense to use POJO instead of ExamplesTable?

@@ -0,0 +1,34 @@
Description: Integration tests for ElementSteps class.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Description: Integration tests for ElementSteps class.
Description: Integration tests for features working with CSS properties.

*
* @param parameters The parameters of the expected CSS properties to set as ExamplesTable
*/
@Then("context element has CSS properties:$parameters")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also it makes sense to move this step ElementCssSteps class (to keep consistency with Selenium plugin)

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

[source,gherkin]
----
When I change context to element located by `id(block)`
Then context element has CSS properties:
Copy link
Member

Choose a reason for hiding this comment

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

as practice shows steps that consume locator are more flexible, e.g. Then element located by ... has CSS properties..., if you need to check against context then you can just pass xpath(.) locator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to discuss

Copy link
Collaborator

Choose a reason for hiding this comment

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

doubtful at the current moment

* @param parameters The parameters of the expected CSS properties to set as ExamplesTable
*/
@Then("context element has CSS properties:$parameters")
public void doesElementHasCssProperties(ExamplesTable parameters)
Copy link
Member

Choose a reason for hiding this comment

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

does have :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ToDo

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

StringComparisonRule comparisonRule = params.valueAs("comparisonRule", StringComparisonRule.class);

String actualCssValue = getCssValue(elementCss, cssName);
boolean passed = softAssert.assertThat(String.format(ELEMENT_CSS_CONTAINING_VALUE, cssName, expectedValue),
Copy link
Member

Choose a reason for hiding this comment

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

ELEMENT_CSS_CONTAINING_VALUE, its not only containing as you use comparison rule

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ToDo

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

Map<String, String> values = params.values();
String cssName = values.get("cssName");
String expectedValue = values.get("expectedValue");
StringComparisonRule comparisonRule = params.valueAs("comparisonRule", StringComparisonRule.class);
Copy link
Member

Choose a reason for hiding this comment

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

does it make sense to map params directly to pojo having css name, exp val and comp rule?

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


import org.vividus.steps.StringComparisonRule;

public class CssValidationResult extends CssValidationParameters
Copy link
Collaborator

Choose a reason for hiding this comment

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

use composition over inheritance

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


[source,gherkin]
----
Then context element does have CSS properties matching rules:$parameters
Copy link
Collaborator

Choose a reason for hiding this comment

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

why does have but not has?

<table class="table table-hover table-bordered table-condensed fixedHeader">
<thead>
<tr>
<th>Css Property</th>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<th>Css Property</th>
<th>CSS Property</th>

<th>Actual Value</th>
<th>Comparison Rule</th>
<th>Expected</th>
<th>Result</th>
Copy link
Collaborator

Choose a reason for hiding this comment

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

the title for this column can be omitted and it makes sense to make this column first

public void doesElementHasCssProperties(List<CssValidationParameters> parameters)
{
String getAllCssScript =
org.vividus.util.ResourceUtils.loadResource("org/vividus/ui/web/get-element-computed-css-func.js");
Copy link
Collaborator

Choose a reason for hiding this comment

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

just use import instead of fully-qualified name

Comment on lines 117 to 118
boolean passed = softAssert.assertThat(String.format("Element has CSS property '%s' %s value '%s'",
cssName, comparisonRule, expectedValue),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
boolean passed = softAssert.assertThat(String.format("Element has CSS property '%s' %s value '%s'",
cssName, comparisonRule, expectedValue),
boolean passed = softAssert.assertThat(String.format("CSS property '%s' value",
cssName),

Comment on lines 209 to 207
private List<CssValidationResult> validateElementCss(List<CssValidationParameters> parameters,
Map<String, String> elementCss)
{
List<CssValidationResult> cssResults = new ArrayList<>();
parameters.forEach(param ->
{
String cssName = param.getCssProperty();
String expectedValue = param.getExpectedValue();
StringComparisonRule comparisonRule = param.getComparisonRule();

String actualCssValue = getCssValue(elementCss, cssName);
boolean passed = softAssert.assertThat(String.format("Element has CSS property '%s' %s value '%s'",
cssName, comparisonRule, expectedValue),
actualCssValue, comparisonRule.createMatcher(expectedValue));
cssResults.add(new CssValidationResult(param, expectedValue, passed));
});
return cssResults;
}

private String getCssValue(Map<String, String> cssMap, String cssName)
{
return Optional.ofNullable(cssMap.get(cssName)).orElseGet(() -> {
String cssValueAsCamelCase = CaseUtils.toCamelCase(StringUtils.removeStart(cssName, '-'), false, '-');
return cssMap.get(cssValueAsCamelCase);
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

it makes sense to introduce CssValidations class, move this logic to it and re-use in both places

Meta:
@epic vividus-plugin-web-app

Scenario: Deprecated step verification Then the context element has the CSS property '$cssName'='$cssValue'
Copy link
Collaborator

Choose a reason for hiding this comment

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

please mark scenarios running on Playwright successfully with meta @playwrightSupported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants