Skip to content

Commit

Permalink
Merge pull request #20 from ShellyDCMS/add-get-style-attr
Browse files Browse the repository at this point in the history
add get.elementsStyleAttribute
  • Loading branch information
ShellyDCMS committed Sep 23, 2023
2 parents 5613fe7 + 724aeac commit 36a0edd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@shellygo/cypress-test-utils",
"description": "Test Automation Utilities",
"version": "1.0.32",
"version": "1.0.3",
"author": "Shelly Goldblit",
"private": false,
"license": "MIT",
Expand Down
8 changes: 8 additions & 0 deletions src/cypress-helper-spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ describe("cypress helper tests", () => {
);
});

it("should get style", () => {
expect(
get
.elementsStyleAttribute("button", "background-color")
.should("eq", "rgb(255, 0, 0)")
);
});

it("should get image source", () => {
expect(get.elementsAttribute("image", "src").should("eq", "w3schools.jpg"));
});
Expand Down
14 changes: 14 additions & 0 deletions src/cypress-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,20 @@ export class CypressHelper {
*/
currentLocation: (): Cypress.Chainable<string> => cy.url(),

/**
* Returns element's style attribute
*
* @param selector : string
* @param attribute : string
* @param [index = 0]
* @returns {Cypress.Chainable<string>}
*/
elementsStyleAttribute: (
selector: string,
attribute: string,
index: number = 0
) => this.get.elementByTestId(selector, index).invoke("css", attribute),

/**
* Returns element's computed style, including pseudo elements
*
Expand Down

0 comments on commit 36a0edd

Please sign in to comment.