-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(soft-assertions): Implement soft assertions for playwright-java (#…
- Loading branch information
Showing
18 changed files
with
986 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
playwright/src/main/java/com/microsoft/playwright/assertions/SoftAssertions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.microsoft.playwright.assertions; | ||
|
||
import com.microsoft.playwright.impl.SoftAssertionsImpl; | ||
import com.microsoft.playwright.APIResponse; | ||
import com.microsoft.playwright.Locator; | ||
import com.microsoft.playwright.Page; | ||
|
||
/** | ||
* The {@code SoftAssertions} class provides assertion methods that can be used to make multiple assertions without failing | ||
* the test immediately. | ||
* <pre>{@code | ||
* ... | ||
* import com.microsoft.playwright.assertions.SoftAssertions; | ||
* | ||
* public class TestPage { | ||
* ... | ||
* @Test | ||
* void hasUrlTextPass() { | ||
* SoftAssertions softly = SoftAssertions.create(); | ||
* page.getByText("Sign in").click(); | ||
* softly.assertThat(page).hasURL(Pattern.compile(".*\/login")); | ||
* softly.assertAll(); | ||
* } | ||
* } | ||
* }</pre> | ||
*/ | ||
public interface SoftAssertions { | ||
/** | ||
* Creates a {@code SoftAssertions} object. | ||
* | ||
* <p> **Usage** | ||
* <pre>{@code | ||
* SoftAssertions softly = SoftAssertions.create(); | ||
* }</pre> | ||
* | ||
* @since v1.38 | ||
*/ | ||
static SoftAssertions create() { | ||
return new SoftAssertionsImpl(); | ||
} | ||
/** | ||
* Creates a {@code LocatorAssertions} object for the given {@code Locator}. | ||
* | ||
* <p> **Usage** | ||
* <pre>{@code | ||
* SoftAssertions softly = SoftAssertions.create(); | ||
* ... | ||
* softly.assertThat(locator).isVisible(); | ||
* }</pre> | ||
* | ||
* @param locator {@code Locator} object to use for assertions. | ||
* @since v1.38 | ||
*/ | ||
LocatorAssertions assertThat(Locator locator); | ||
/** | ||
* Creates a {@code PageAssertions} object for the given {@code Page}. | ||
* | ||
* <p> **Usage** | ||
* <pre>{@code | ||
* SoftAssertions softly = SoftAssertions.create(); | ||
* ... | ||
* softly.assertThat(page).hasTitle("News"); | ||
* }</pre> | ||
* | ||
* @param page {@code Page} object to use for assertions. | ||
* @since v1.38 | ||
*/ | ||
PageAssertions assertThat(Page page); | ||
/** | ||
* Creates a {@code APIResponseAssertions} object for the given {@code APIResponse}. | ||
* | ||
* <p> **Usage** | ||
* <pre>{@code | ||
* SoftAssertions softly = SoftAssertions.create(); | ||
* ... | ||
* softly.assertThat(response).isOK(); | ||
* }</pre> | ||
* | ||
* @param response {@code APIResponse} object to use for assertions. | ||
* @since v1.38 | ||
*/ | ||
APIResponseAssertions assertThat(APIResponse response); | ||
/** | ||
* Runs all the assertions have been executed for this {@code SoftAssertions} object. If any assertions fail, this method | ||
* throws an AssertionFailedError with the details of all the failed assertions. | ||
* | ||
* <p> **Usage** | ||
* <pre>{@code | ||
* SoftAssertions softly = SoftAssertions.create(); | ||
* ... | ||
* softly.assertAll(); | ||
* }</pre> | ||
* | ||
* @since v1.38 | ||
*/ | ||
void assertAll(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
playwright/src/main/java/com/microsoft/playwright/impl/APIResponseAssertionsImplProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.microsoft.playwright.impl; | ||
|
||
import com.microsoft.playwright.APIResponse; | ||
import com.microsoft.playwright.assertions.APIResponseAssertions; | ||
|
||
import java.util.List; | ||
|
||
public class APIResponseAssertionsImplProxy extends SoftAssertionsBase implements APIResponseAssertions { | ||
private final APIResponseAssertionsImpl apiResponseAssertionsImpl; | ||
|
||
APIResponseAssertionsImplProxy(APIResponse response, List<Throwable> results) { | ||
this(results, new APIResponseAssertionsImpl(response)); | ||
} | ||
|
||
private APIResponseAssertionsImplProxy(List<Throwable> results, APIResponseAssertionsImpl apiResponseAssertionsImpl) { | ||
super(results); | ||
this.apiResponseAssertionsImpl = apiResponseAssertionsImpl; | ||
} | ||
|
||
@Override | ||
public APIResponseAssertions not() { | ||
return new APIResponseAssertionsImplProxy(super.results, apiResponseAssertionsImpl.not()); | ||
} | ||
|
||
@Override | ||
public void isOK() { | ||
assertAndCaptureResult(apiResponseAssertionsImpl::isOK); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
playwright/src/main/java/com/microsoft/playwright/impl/LocatorAssertionsImplProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
package com.microsoft.playwright.impl; | ||
|
||
import com.microsoft.playwright.Locator; | ||
import com.microsoft.playwright.assertions.LocatorAssertions; | ||
|
||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
|
||
public class LocatorAssertionsImplProxy extends SoftAssertionsBase implements LocatorAssertions { | ||
private final LocatorAssertionsImpl locatorAssertionsImpl; | ||
|
||
LocatorAssertionsImplProxy(Locator locator, List<Throwable> results) { | ||
this(results, new LocatorAssertionsImpl(locator)); | ||
} | ||
|
||
private LocatorAssertionsImplProxy(List<Throwable> results, LocatorAssertionsImpl locatorAssertionsImpl) { | ||
super(results); | ||
this.locatorAssertionsImpl = locatorAssertionsImpl; | ||
} | ||
|
||
@Override | ||
public LocatorAssertions not() { | ||
return new LocatorAssertionsImplProxy(super.results, locatorAssertionsImpl.not()); | ||
} | ||
|
||
@Override | ||
public void isAttached(IsAttachedOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.isAttached(options)); | ||
} | ||
|
||
@Override | ||
public void isChecked(IsCheckedOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.isChecked(options)); | ||
} | ||
|
||
@Override | ||
public void isDisabled(IsDisabledOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.isDisabled(options)); | ||
} | ||
|
||
@Override | ||
public void isEditable(IsEditableOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.isEditable(options)); | ||
} | ||
|
||
@Override | ||
public void isEmpty(IsEmptyOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.isEmpty(options)); | ||
} | ||
|
||
@Override | ||
public void isEnabled(IsEnabledOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.isEnabled(options)); | ||
} | ||
|
||
@Override | ||
public void isFocused(IsFocusedOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.isFocused(options)); | ||
} | ||
|
||
@Override | ||
public void isHidden(IsHiddenOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.isHidden(options)); | ||
} | ||
|
||
@Override | ||
public void isInViewport(IsInViewportOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.isInViewport(options)); | ||
} | ||
|
||
@Override | ||
public void isVisible(IsVisibleOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.isVisible(options)); | ||
} | ||
|
||
@Override | ||
public void containsText(String expected, ContainsTextOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.containsText(expected, options)); | ||
} | ||
|
||
@Override | ||
public void containsText(Pattern expected, ContainsTextOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.containsText(expected, options)); | ||
} | ||
|
||
@Override | ||
public void containsText(String[] expected, ContainsTextOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.containsText(expected, options)); | ||
} | ||
|
||
@Override | ||
public void containsText(Pattern[] expected, ContainsTextOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.containsText(expected, options)); | ||
} | ||
|
||
@Override | ||
public void hasAttribute(String name, String value, HasAttributeOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasAttribute(name, value, options)); | ||
} | ||
|
||
@Override | ||
public void hasAttribute(String name, Pattern value, HasAttributeOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasAttribute(name, value, options)); | ||
} | ||
|
||
@Override | ||
public void hasClass(String expected, HasClassOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasClass(expected, options)); | ||
} | ||
|
||
@Override | ||
public void hasClass(Pattern expected, HasClassOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasClass(expected, options)); | ||
} | ||
|
||
@Override | ||
public void hasClass(String[] expected, HasClassOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasClass(expected, options)); | ||
} | ||
|
||
@Override | ||
public void hasClass(Pattern[] expected, HasClassOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasClass(expected, options)); | ||
} | ||
|
||
@Override | ||
public void hasCount(int count, HasCountOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasCount(count, options)); | ||
} | ||
|
||
@Override | ||
public void hasCSS(String name, String value, HasCSSOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasCSS(name, value, options)); | ||
} | ||
|
||
@Override | ||
public void hasCSS(String name, Pattern value, HasCSSOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasCSS(name, value, options)); | ||
} | ||
|
||
@Override | ||
public void hasId(String id, HasIdOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasId(id, options)); | ||
} | ||
|
||
@Override | ||
public void hasId(Pattern id, HasIdOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasId(id, options)); | ||
} | ||
|
||
@Override | ||
public void hasJSProperty(String name, Object value, HasJSPropertyOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasJSProperty(name, value, options)); | ||
} | ||
|
||
@Override | ||
public void hasText(String expected, HasTextOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasText(expected, options)); | ||
} | ||
|
||
@Override | ||
public void hasText(Pattern expected, HasTextOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasText(expected, options)); | ||
} | ||
|
||
@Override | ||
public void hasText(String[] expected, HasTextOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasText(expected, options)); | ||
} | ||
|
||
@Override | ||
public void hasText(Pattern[] expected, HasTextOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasText(expected, options)); | ||
} | ||
|
||
@Override | ||
public void hasValue(String value, HasValueOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasValue(value, options)); | ||
} | ||
|
||
@Override | ||
public void hasValue(Pattern value, HasValueOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasValue(value, options)); | ||
} | ||
|
||
@Override | ||
public void hasValues(String[] values, HasValuesOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasValues(values, options)); | ||
} | ||
|
||
@Override | ||
public void hasValues(Pattern[] values, HasValuesOptions options) { | ||
assertAndCaptureResult(() -> locatorAssertionsImpl.hasValues(values, options)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.