diff --git a/docs/modules/plugins/pages/plugin-web-app.adoc b/docs/modules/plugins/pages/plugin-web-app.adoc index 3e153c2d8f..fe1f3b1b9a 100644 --- a/docs/modules/plugins/pages/plugin-web-app.adoc +++ b/docs/modules/plugins/pages/plugin-web-app.adoc @@ -794,6 +794,44 @@ When I set all cookies for current domain: |cookieAgreed |2 |/ | ---- +==== Set cookies without applying changes + +Adds the cookies provided in the input xref:ROOT:glossary.adoc#_examplestable[ExamplesTable], but does not apply the +changes in cookies. The current page must be refreshed or the navigation must be performed to apply the cookie changes. +It's allowed to add the cookies for the current domain only: make sure the web browser is opened at the expected domain. + +[source,gherkin] +---- +When I set all cookies for current domain without applying changes:$parameters +---- +* `$parameters` - The parameters of the cookies to set as xref:ROOT:glossary.adoc#_examplestable[ExamplesTable]: ++ +[cols="1,2", options="header"] +|=== + +|Column Name +|Description + +|`cookieName` +|the name of the cookie to set + +|`cookieValue` +|the value of the cookie to set + +|`path` +|the path of the cookie to set + +|=== + +.Set the cookie for the current domain +[source,gherkin] +---- +When I set all cookies for current domain without applying changes: +|cookieName |cookieValue |path | +|cookieAgreed |2 |/ | +When I refresh page +---- + ==== Get cookie value Finds the cookie by the name and saves its value to a variable. @@ -849,7 +887,7 @@ When I remove cookie with name `$cookieName` from current domain When I remove cookie with name `JSESSIONID` from current domain ---- -==== Remove cookie without apply +==== Remove cookie without applying changes Removes the certain cookie from the current domain, but does not apply the changes in cookies. The current page must be refreshed or the navigation must @@ -880,7 +918,7 @@ Removes all cookies from the current domain. The actions performed by the step: When I remove all cookies from current domain ---- -==== Remove all cookies without apply +==== Remove all cookies without applying changes Removes all cookies from the current domain, but does not apply the changes in cookies. The current page must be refreshed or the navigation must be performed diff --git a/vividus-plugin-web-app/src/main/java/org/vividus/steps/ui/web/CookieSteps.java b/vividus-plugin-web-app/src/main/java/org/vividus/steps/ui/web/CookieSteps.java index 6080939789..baf05efeb2 100644 --- a/vividus-plugin-web-app/src/main/java/org/vividus/steps/ui/web/CookieSteps.java +++ b/vividus-plugin-web-app/src/main/java/org/vividus/steps/ui/web/CookieSteps.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 the original author or authors. + * 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. @@ -182,6 +182,32 @@ public void thenCookieWithNameIsNotSet(String cookieName) */ @When("I set all cookies for current domain:$parameters") public void setAllCookies(ExamplesTable parameters) + { + setAllCookiesWithoutApply(parameters); + navigateActions.refresh(); + } + + /** + * Adds the cookies provided in the input ExamplesTable, but does not apply the changes in cookies. The current + * page must be refreshed or the navigation must be performed to apply the cookie changes. It's allowed to add + * the cookies for the current domain only: make sure the web browser is opened at the expected domain. + *
The cookie parameters to be defined in the ExamplesTable
+ *Usage example:
+ *
+ *
When I set all cookies for current domain:
+ *
|cookieName |cookieValue |path |
+ *
|cookieAgreed |2 |/ |
+ *
+ *
+ * @param parameters The parameters of the cookies to set as ExamplesTable
+ */
+ @When("I set all cookies for current domain without applying changes:$parameters")
+ public void setAllCookiesWithoutApply(ExamplesTable parameters)
{
String currentUrl = webDriverProvider.get().getCurrentUrl();
Validate.isTrue(null != currentUrl,
@@ -190,7 +216,6 @@ public void setAllCookies(ExamplesTable parameters)
{
cookieManager.addCookie(row.get("cookieName"), row.get("cookieValue"), row.get("path"), currentUrl);
});
- navigateActions.refresh();
}
/**
diff --git a/vividus-plugin-web-app/src/test/java/org/vividus/steps/ui/web/CookieStepsTests.java b/vividus-plugin-web-app/src/test/java/org/vividus/steps/ui/web/CookieStepsTests.java
index 6a75a4a7ec..0dbb05ea24 100644
--- a/vividus-plugin-web-app/src/test/java/org/vividus/steps/ui/web/CookieStepsTests.java
+++ b/vividus-plugin-web-app/src/test/java/org/vividus/steps/ui/web/CookieStepsTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019-2021 the original author or authors.
+ * 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.
@@ -29,6 +29,7 @@
import java.util.Map;
import java.util.Set;
+import java.util.function.Consumer;
import org.jbehave.core.model.ExamplesTable;
import org.junit.jupiter.api.Test;
@@ -136,15 +137,31 @@ void testThenCookieWithNameIsNotSet()
}
@Test
- void testSetAllCookies()
+ void shouldSetAllCookies()
{
- String testUrl = "https://www.vividus.org";
+ testSetAllCookies(cookieSteps::setAllCookies);
+ verify(navigateActions).refresh();
+ }
+
+ @Test
+ void shoutSetAllCookiesWithoutApplyingChanges()
+ {
+ testSetAllCookies(cookieSteps::setAllCookiesWithoutApply);
+ verifyNoInteractions(navigateActions);
+ }
+
+ private void testSetAllCookies(Consumer