|
30 | 30 | import org.openqa.selenium.Cookie; |
31 | 31 | import org.openqa.selenium.JavascriptExecutor; |
32 | 32 | import org.openqa.selenium.WindowType; |
| 33 | +import org.openqa.selenium.bidi.browsingcontext.BrowsingContext; |
| 34 | +import org.openqa.selenium.bidi.browsingcontext.CreateContextParameters; |
| 35 | +import org.openqa.selenium.bidi.module.Browser; |
33 | 36 | import org.openqa.selenium.bidi.module.Storage; |
34 | 37 | import org.openqa.selenium.bidi.network.BytesValue; |
35 | 38 | import org.openqa.selenium.testing.JupiterTestBase; |
@@ -121,8 +124,57 @@ public void canGetCookieInDefaultUserContext() { |
121 | 124 | } |
122 | 125 |
|
123 | 126 | @Test |
124 | | - // TODO: Once Browser module is added this test needs to be added |
125 | | - public void canGetCookieInAUserContext() {} |
| 127 | + @NotYetImplemented(EDGE) |
| 128 | + public void canGetCookieInAUserContext() { |
| 129 | + Browser browser = new Browser(driver); |
| 130 | + String userContext = browser.createUserContext(); |
| 131 | + String windowHandle = driver.getWindowHandle(); |
| 132 | + |
| 133 | + String key = generateUniqueKey(); |
| 134 | + String value = "set"; |
| 135 | + |
| 136 | + PartitionDescriptor descriptor = new StorageKeyPartitionDescriptor().userContext(userContext); |
| 137 | + |
| 138 | + SetCookieParameters parameters = |
| 139 | + new SetCookieParameters( |
| 140 | + new PartialCookie( |
| 141 | + key, new BytesValue(BytesValue.Type.STRING, value), appServer.getHostName()), |
| 142 | + descriptor); |
| 143 | + |
| 144 | + storage.setCookie(parameters); |
| 145 | + |
| 146 | + CookieFilter cookieFilter = new CookieFilter(); |
| 147 | + cookieFilter.name(key); |
| 148 | + cookieFilter.value(new BytesValue(BytesValue.Type.STRING, "set")); |
| 149 | + |
| 150 | + BrowsingContext context = |
| 151 | + new BrowsingContext( |
| 152 | + driver, new CreateContextParameters(WindowType.TAB).userContext(userContext)); |
| 153 | + |
| 154 | + driver.switchTo().window(context.getId()); |
| 155 | + |
| 156 | + GetCookiesParameters params = new GetCookiesParameters(cookieFilter, descriptor); |
| 157 | + |
| 158 | + GetCookiesResult result = storage.getCookies(params); |
| 159 | + |
| 160 | + assertThat(result.getCookies().get(0).getValue().getValue()).isEqualTo(value); |
| 161 | + PartitionKey partitionKey = result.getPartitionKey(); |
| 162 | + |
| 163 | + assertThat(partitionKey.getUserContext()).isNotNull(); |
| 164 | + assertThat(partitionKey.getUserContext()).isEqualTo(userContext); |
| 165 | + |
| 166 | + driver.switchTo().window(windowHandle); |
| 167 | + |
| 168 | + PartitionDescriptor browsingContextPartitionDescriptor = |
| 169 | + new BrowsingContextPartitionDescriptor(windowHandle); |
| 170 | + |
| 171 | + GetCookiesParameters params1 = |
| 172 | + new GetCookiesParameters(cookieFilter, browsingContextPartitionDescriptor); |
| 173 | + |
| 174 | + GetCookiesResult result1 = storage.getCookies(params1); |
| 175 | + |
| 176 | + assertThat(result1.getCookies().size()).isEqualTo(0); |
| 177 | + } |
126 | 178 |
|
127 | 179 | @Test |
128 | 180 | @NotYetImplemented(EDGE) |
|
0 commit comments