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

[💡 Feature]: Allow second parameter to getCSSProperty to target pseudo elements, e.g. '::after' #7709

Closed
1 task done
nikolajl opened this issue Nov 17, 2021 · 8 comments
Labels
good first pick a reasonable task to start getting familiar with the code base help wanted Issues that are free to take by anyone interested Idea 💡 A new feature idea

Comments

@nikolajl
Copy link

Is your feature request related to a problem?

I need to check a css style that is implemented as pseudo element ::after.

In the browser this is possible using window.getComputedStyle(element, '::after'). However, there is not an obvious way to do this in on the Element in WebdriverIO.

Under the hood, getCSSProperty() uses getComputedStyle, but only allows 1 parameter. Allowing a second parameter would be an obvious simple solution.

Describe the solution you'd like.

Add second parameter to getCSSProperty()

Example:

const contentAfter = await $('#selector').getCSSProperty('content', '::after')

Parameter would be added here.

export default async function getCSSProperty (

export default async function getCSSProperty (
    this: WebdriverIO.Element,
    cssProperty: string,
    pseudoElement?: string // or '::before' | '::after'
) {

and then passed on to this one:

return (window.getComputedStyle(elem) as any)[propertyName]

export default function getElementCSSValue (_: HTMLElement, elem: HTMLElement, propertyName: string, pseudoElement?: string ): string {
    return (window.getComputedStyle(elem, pseudoElement) as any)[propertyName]
}

Describe alternatives you've considered.

No response

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@nikolajl nikolajl added Idea 💡 A new feature idea Needs Triaging ⏳ No one has looked into the issue yet labels Nov 17, 2021
@christian-bromann
Copy link
Member

Thanks for proposing the idea @nikolajl! I think the structure you suggest works out, maybe we can be a bit more stricter about the pseudo element strings? So rather than defining it as string, we could list '::after' | '::before' | etc.

Any contributions that implements this suggestion are highly appreciated. Please take a look into our contribution guidelines and let us know if you have any questions. Cheers!

@christian-bromann christian-bromann added good first pick a reasonable task to start getting familiar with the code base help wanted Issues that are free to take by anyone interested and removed Needs Triaging ⏳ No one has looked into the issue yet labels Nov 17, 2021
@Andrewnt219
Copy link

Hi @christian-bromann, I want to help with this issue.

@christian-bromann
Copy link
Member

Awesome, let me know if you have any questions.

@Andrewnt219
Copy link

@christian-bromann the geElementCssValue gets its type from an ignored d.ts file. Even if I change the file, it doesn't affect the type anyway. I tried adding types to both the getElementCssValue in packages/devtools/src/commends but that didn't work either. How should I type the third parameter?

Screen Shot 2021-11-24 at 10 17 11 PM

Screen Shot 2021-11-24 at 10 23 40 PM

c2.png">

@christian-bromann
Copy link
Member

it doesn't affect the type anyway.

You can generate types via npm run generate:typings, see also https://github.com/webdriverio/webdriverio/blob/main/CONTRIBUTING.md#typescript-definitions

@Andrewnt219
Copy link

Andrewnt219 commented Nov 25, 2021

Thanks. I misunderstood that the script will change base on TypeScript, but I actually have to go inside the JSON file and update the type.

EDIT: I can't solve this, PR welcome.

Andrewnt219 added a commit to Andrewnt219/webdriverio that referenced this issue Nov 25, 2021
getCSSProperty utilizes browser getComputedStyle which allows
passing a second parameter to get the pseudo element instead of
the real element.

The type defined by getComputedStyle for pseudo elements is
string | null | undefined so I do the same. Constrain the type
to literal string can be hard to maintain.

Refs: webdriverio#7709
Andrewnt219 added a commit to Andrewnt219/webdriverio that referenced this issue Nov 25, 2021
getCSSProperty utilizes browser getComputedStyle which allows
passing a second parameter to get the pseudo element instead of
the real element.

The type defined by getComputedStyle for pseudo elements is
string | null | undefined so I do the same. Constrain the type
to literal string can be hard to maintain.

Refs: webdriverio#7709
christian-bromann added a commit that referenced this issue Nov 8, 2023
 (#11570)

* Enable to get css value of pseudo-element

* removing browser from getCSSProperty params

* moving getBrowserObject to getPseudoElementCSSValue

* Update packages/webdriverio/src/commands/element/getCSSProperty.ts

---------

Co-authored-by: Christian Bromann <git@bromann.dev>
@Pawel1894
Copy link
Contributor

@christian-bromann I guess this can be closed? 😄

@christian-bromann
Copy link
Member

Yes, thanks @Pawel1894 for working on this 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first pick a reasonable task to start getting familiar with the code base help wanted Issues that are free to take by anyone interested Idea 💡 A new feature idea
Projects
None yet
Development

No branches or pull requests

4 participants