-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[plugin-web-app-playwright] Add step to close browser
- Loading branch information
Showing
9 changed files
with
169 additions
and
4 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
20 changes: 20 additions & 0 deletions
20
docs/modules/plugins/partials/common-web-app-browser-steps.adoc
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,20 @@ | ||
=== Close browser | ||
|
||
Closes the browser. | ||
|
||
[source,gherkin] | ||
---- | ||
When I close browser | ||
---- | ||
|
||
.Browser restart | ||
[source,gherkin] | ||
---- | ||
Given I am on page with URL `https://vividus-test-site-a92k.onrender.com` | ||
Then number of elements found by `xpath(//img)` is = `1` | ||
When I execute javascript `document.querySelector('[name="vividus-logo"]').remove()` | ||
Then number of elements found by `xpath(//img)` is = `0` | ||
When I close browser | ||
Given I am on page with URL `https://vividus-test-site-a92k.onrender.com` | ||
Then number of elements found by `xpath(//img)` is = `1` | ||
---- |
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
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
44 changes: 44 additions & 0 deletions
44
...in-web-app-playwright/src/main/java/org/vividus/ui/web/playwright/steps/BrowserSteps.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,44 @@ | ||
/* | ||
* Copyright 2019-2024 the original author or authors. | ||
* | ||
* 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 | ||
* | ||
* https://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 org.vividus.ui.web.playwright.steps; | ||
|
||
import org.jbehave.core.annotations.When; | ||
import org.vividus.ui.web.playwright.BrowserContextProvider; | ||
import org.vividus.ui.web.playwright.UiContext; | ||
|
||
public class BrowserSteps | ||
{ | ||
private final BrowserContextProvider browserContextProvider; | ||
private final UiContext uiContext; | ||
|
||
public BrowserSteps(BrowserContextProvider browserContextProvider, UiContext uiContext) | ||
{ | ||
this.browserContextProvider = browserContextProvider; | ||
this.uiContext = uiContext; | ||
} | ||
|
||
/** | ||
* Closes the browser | ||
*/ | ||
@When("I close browser") | ||
public void closeBrowser() | ||
{ | ||
browserContextProvider.closeBrowserContext(); | ||
browserContextProvider.closeBrowserInstance(); | ||
uiContext.removePlaywrightContext(); | ||
} | ||
} |
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
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
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
43 changes: 43 additions & 0 deletions
43
...b-app-playwright/src/test/java/org/vividus/ui/web/playwright/steps/BrowserStepsTests.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,43 @@ | ||
/* | ||
* Copyright 2019-2024 the original author or authors. | ||
* | ||
* 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 | ||
* | ||
* https://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 org.vividus.ui.web.playwright.steps; | ||
|
||
import static org.mockito.Mockito.verify; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.vividus.ui.web.playwright.BrowserContextProvider; | ||
import org.vividus.ui.web.playwright.UiContext; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class BrowserStepsTests | ||
{ | ||
@Mock private BrowserContextProvider browserContextProvider; | ||
@Mock private UiContext uiContext; | ||
|
||
@Test | ||
void shouldCloseBrowser() | ||
{ | ||
BrowserSteps steps = new BrowserSteps(browserContextProvider, uiContext); | ||
steps.closeBrowser(); | ||
verify(browserContextProvider).closeBrowserContext(); | ||
verify(browserContextProvider).closeBrowserInstance(); | ||
verify(uiContext).removePlaywrightContext(); | ||
} | ||
} |