-
Notifications
You must be signed in to change notification settings - Fork 209
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
SoftAssertions Implementation #1340
Conversation
Hi @uchagani, sorry for long delay. Your approach looks sensible and we can accept your implementation of soft assertions into this repo. A few notes about the implementation:
Starting with PageAssertions is a good idea, let's worked out it first and then proceed with the locator assertions. |
|
||
@Override | ||
public PageAssertions not() { | ||
return new PageAssertionsImplProxy(super.results, (PageAssertionsImpl) pageAssertions.not()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just change the return type of PageAssertionsImpl.not() to PageAssertionsImpl.
import java.util.List; | ||
import java.util.regex.Pattern; | ||
|
||
class PageAssertionsProxy extends SoftAssertionsBase implements PageAssertions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this class is subsumed by PageAssertionsImplProxy and can be deleted.
import java.util.List; | ||
|
||
class SoftAssertionsImpl implements SoftAssertions { | ||
final List<Throwable> results; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use RuntimeException
here and in PageAssertionsImplProxy and SoftAssertionsBase. We don't want to catch any Errors
anyway and only catch unchecked exceptions in SoftAssertionsBase anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yury-s, we catch AssertionFailedError
which is an Error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, didn't know that. Then Throwable
is justified.
@yury-s I created a
How do i get it playwright to run with my new additions? |
Do you have the change uploaded somewhere? It might be that you need to update some of the generator scripts, I can try running it locally and help you. Update: yeah, it looks like you need to update the generator around |
@yury-s here is my branch with the markdown (https://github.com/uchagani/playwright/tree/java-soft-assertions). I'll take a look at your suggestion about changing |
@yury-s so i added a |
I usually just follow the instructions and that's enough. Note that the new page will not show up in the sidebar automatically, you need to manually edit https://github.com/microsoft/playwright.dev/blob/main/java/sidebars.js, but you should be able to navigate to the page by typing its url. I can try to apply your patch locally later today if it still doesn't work. |
Ah ok I didn't know it wouldn't show up in the sidebar and I had to navigate to it. I'll try that in a bit. |
@yury-s so i can't navigate to it either. I think i'm doing something wrong because when I add it to the sidebar under assertions, none of the assertion sidebar items show up. |
Here is my playwright.dev branch: https://github.com/uchagani/playwright.dev/tree/java-soft-assertions |
By default it shows stable docs which don't contain the new page. You need to navigate to I ran your patches locally and I can see the page. |
that worked! thanks! |
@yury-s PRs created for both the main playwright repo and playwright.dev. Is there anything else I need to do before the new API interface will be available for this PR? |
@yury-s how does the api generator know to make a method static? |
https://github.com/microsoft/playwright-java/blob/main/tools/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java#L685 found it. i guess we'll have to add something here too to handle the static |
I'll commit this right-away to unblock you. Feel free to address any comments in a follow-up PR. |
Oops, wrong PR, I meant the one upstream, sorry 😄 |
This PR adds the `SoftAssertions` API for Java. Related PR: microsoft/playwright-java#1340 Note: microsoft/playwright.dev#1135 needs to be merged in order for the markdown in this PR to be rendered without errors
This reverts commit 632fba5.
This PR adds the `SoftAssertions` API for Java. Related PR: microsoft/playwright-java#1340 Note: microsoft/playwright.dev#1135 needs to be merged in order for the markdown in this PR to be rendered without errors
Feedback requested:
I took a stab at implementing soft assertions (issue #819). Before I continue, I'd love to get some feedback on if this is an acceptable approach.
I have implemented
PageAssertions
so far. Please take a look atTestSoftPageAssertions.java
for what the usage would be. I used most of the existing test cases to exercise the method via soft assertions.I believe this approach takes the least intrusive route (No existing playwright code was modified).