Skip to content

Commit

Permalink
[plugin-web-app] Add step to close browser (#3825)
Browse files Browse the repository at this point in the history
  • Loading branch information
uarlouski authored Apr 13, 2023
1 parent 40d270b commit 2557864
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 9 deletions.
9 changes: 9 additions & 0 deletions docs/modules/plugins/pages/plugin-web-app.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ include::plugins:partial$plugin-web-app-profiles.adoc[]

include::plugins:partial$plugin-web-app-steps.adoc[]

=== Close browser

Closes the browser.

[source,gherkin]
----
When I close browser
----

=== Wait for window and switch

Waits for the windows with desired title and switches to it.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 the original author or authors.
* Copyright 2019-2023 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.
Expand All @@ -17,16 +17,19 @@
package org.vividus.steps.ui.web;

import org.jbehave.core.annotations.When;
import org.vividus.selenium.IWebDriverProvider;
import org.vividus.selenium.WebDriverStartContext;
import org.vividus.selenium.WebDriverStartParameters;

public class BrowserConfigurationSteps
public class BrowserSteps
{
private final WebDriverStartContext webDriverStartContext;
private final IWebDriverProvider webDriverProvider;

public BrowserConfigurationSteps(WebDriverStartContext webDriverStartContext)
public BrowserSteps(WebDriverStartContext webDriverStartContext, IWebDriverProvider webDriverProvider)
{
this.webDriverStartContext = webDriverStartContext;
this.webDriverProvider = webDriverProvider;
}

/**
Expand All @@ -48,4 +51,13 @@ public void setWebDriverCliArguments(String argsString)
{
webDriverStartContext.put(WebDriverStartParameters.COMMAND_LINE_ARGUMENTS, argsString);
}

/**
* Closes the browser
*/
@When("I close browser")
public void closeBrowser()
{
webDriverProvider.end();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@

<bean id="actionsSequenceSteps" class="org.vividus.steps.ui.web.ActionsSequenceSteps" />

<bean id="browserSteps" class="org.vividus.steps.ui.web.BrowserConfigurationSteps" />
<bean id="browserSteps" class="org.vividus.steps.ui.web.BrowserSteps" />

<bean id="webUiVividusSetupSteps" class="org.vividus.steps.WebUiVividusSetupSteps">
<property name="windowsStrategy" value="${selenium.windows-strategy}" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 the original author or authors.
* Copyright 2019-2023 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.
Expand All @@ -23,22 +23,31 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.vividus.selenium.IWebDriverProvider;
import org.vividus.selenium.WebDriverStartContext;
import org.vividus.selenium.WebDriverStartParameters;

@ExtendWith(MockitoExtension.class)
class BrowserConfigurationStepsTests
class BrowserStepsTests
{
private static final String COMMAND_LINE_ARGS = "args";

@Mock private WebDriverStartContext webDriverStartContext;
@InjectMocks private BrowserConfigurationSteps browserConfigurationSteps;
@Mock private IWebDriverProvider webDriverProvider;
@InjectMocks private BrowserSteps browserSteps;

@Test
void testSetWebDriverCliArguments()
void shouldSetWebDriverCliArguments()
{
browserConfigurationSteps.setWebDriverCliArguments(COMMAND_LINE_ARGS);
browserSteps.setWebDriverCliArguments(COMMAND_LINE_ARGS);
verify(webDriverStartContext).put(
WebDriverStartParameters.COMMAND_LINE_ARGUMENTS, COMMAND_LINE_ARGS);
}

@Test
void shouldCloseBrowser()
{
browserSteps.closeBrowser();
verify(webDriverProvider).end();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Meta:
@epic vividus-plugin-web-app

Scenario: Step verification "When I close browser"
Given I am on main application page
Given I initialize scenario variable `item-key` with value `#{generate(regexify '[a-z]{10}')}`
Given I initialize scenario variable `item-value` with value `#{generate(regexify '[a-z]{10}')}`
When I set local storage item with key `${item-key}` and value `${item-value}`
When I close browser
Given I am on main application page
When I save local storage item with key `${item-key}` to scenario variable `value-on-new-browser`
Then `${value-on-new-browser:null}` is equal to `null`

0 comments on commit 2557864

Please sign in to comment.