From 2557864b5436bf34bccbd7e46c9037d5634af2b5 Mon Sep 17 00:00:00 2001 From: Uladzislau Arlouski Date: Thu, 13 Apr 2023 15:12:03 +0300 Subject: [PATCH] [plugin-web-app] Add step to close browser (#3825) --- .../modules/plugins/pages/plugin-web-app.adoc | 9 +++++++++ ...figurationSteps.java => BrowserSteps.java} | 18 +++++++++++++++--- .../main/resources/vividus-plugin/spring.xml | 2 +- ...StepsTests.java => BrowserStepsTests.java} | 19 ++++++++++++++----- .../story/integration/BrowserSteps.story | 12 ++++++++++++ 5 files changed, 51 insertions(+), 9 deletions(-) rename vividus-plugin-web-app/src/main/java/org/vividus/steps/ui/web/{BrowserConfigurationSteps.java => BrowserSteps.java} (78%) rename vividus-plugin-web-app/src/test/java/org/vividus/steps/ui/web/{BrowserConfigurationStepsTests.java => BrowserStepsTests.java} (72%) create mode 100644 vividus-tests/src/main/resources/story/integration/BrowserSteps.story diff --git a/docs/modules/plugins/pages/plugin-web-app.adoc b/docs/modules/plugins/pages/plugin-web-app.adoc index 1410b416c6..12ca6d6f04 100644 --- a/docs/modules/plugins/pages/plugin-web-app.adoc +++ b/docs/modules/plugins/pages/plugin-web-app.adoc @@ -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. diff --git a/vividus-plugin-web-app/src/main/java/org/vividus/steps/ui/web/BrowserConfigurationSteps.java b/vividus-plugin-web-app/src/main/java/org/vividus/steps/ui/web/BrowserSteps.java similarity index 78% rename from vividus-plugin-web-app/src/main/java/org/vividus/steps/ui/web/BrowserConfigurationSteps.java rename to vividus-plugin-web-app/src/main/java/org/vividus/steps/ui/web/BrowserSteps.java index 212eb0da78..087b3c9c35 100644 --- a/vividus-plugin-web-app/src/main/java/org/vividus/steps/ui/web/BrowserConfigurationSteps.java +++ b/vividus-plugin-web-app/src/main/java/org/vividus/steps/ui/web/BrowserSteps.java @@ -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. @@ -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; } /** @@ -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(); + } } diff --git a/vividus-plugin-web-app/src/main/resources/vividus-plugin/spring.xml b/vividus-plugin-web-app/src/main/resources/vividus-plugin/spring.xml index d8ea88f780..47de92637b 100644 --- a/vividus-plugin-web-app/src/main/resources/vividus-plugin/spring.xml +++ b/vividus-plugin-web-app/src/main/resources/vividus-plugin/spring.xml @@ -217,7 +217,7 @@ - + diff --git a/vividus-plugin-web-app/src/test/java/org/vividus/steps/ui/web/BrowserConfigurationStepsTests.java b/vividus-plugin-web-app/src/test/java/org/vividus/steps/ui/web/BrowserStepsTests.java similarity index 72% rename from vividus-plugin-web-app/src/test/java/org/vividus/steps/ui/web/BrowserConfigurationStepsTests.java rename to vividus-plugin-web-app/src/test/java/org/vividus/steps/ui/web/BrowserStepsTests.java index 3c10f19b81..44d49e17f0 100644 --- a/vividus-plugin-web-app/src/test/java/org/vividus/steps/ui/web/BrowserConfigurationStepsTests.java +++ b/vividus-plugin-web-app/src/test/java/org/vividus/steps/ui/web/BrowserStepsTests.java @@ -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. @@ -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(); + } } diff --git a/vividus-tests/src/main/resources/story/integration/BrowserSteps.story b/vividus-tests/src/main/resources/story/integration/BrowserSteps.story new file mode 100644 index 0000000000..601a44993c --- /dev/null +++ b/vividus-tests/src/main/resources/story/integration/BrowserSteps.story @@ -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`