-
-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[plugin-web-app-playwright] Implement Cookie Steps code logic for Playwright #5127
[plugin-web-app-playwright] Implement Cookie Steps code logic for Playwright #5127
Conversation
yauhenhapan
commented
Jun 14, 2024
- implement code logic for Playwright's cookie
- write corresponding tests
- write documentation
8847e38
to
54d6034
Compare
938a635
to
1bb6f04
Compare
1bb6f04
to
6de531b
Compare
import org.slf4j.LoggerFactory; | ||
import org.vividus.ui.web.playwright.BrowserContextProvider; | ||
|
||
public class CookieHelper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public class CookieHelper | |
public class CookieManager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it make sense to implement ICookieManager
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- the name was changed to
CookieManager
- implemented
ICookieManager
==== Set cookies | ||
|
||
Adds the cookies provided in the input xref:ROOT:glossary.adoc#_examplestable[ExamplesTable]. It's allowed to add the | ||
cookies for the current domain only: make sure the web browser is opened at the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it true for Playwright?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checked that Playwright stores all together, so I removed the sentence It's allowed to add the cookies for the current domain only:...
.setPath(path) | ||
.setDomain(domain); | ||
LOGGER.debug("Adding cookie: {}", cookie); | ||
addCookies(Collections.singletonList(cookie)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addCookies(Collections.singletonList(cookie)); | |
addCookies(List.of(cookie)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored, thanks
String host = URI.create(url).getHost(); | ||
String domain = host.contains(DOMAIN_PARTS_SEPARATOR) && !InetAddresses.isInetAddress(host) | ||
? DOMAIN_PARTS_SEPARATOR + getTopDomain(host) | ||
: host; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please avoid copy-pasting the logic, it's rather recommended to use common logic to common place and re-use in both plugins
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved this common logic in DomainManager
class in vividus-extension-web-app
package
|
||
public Cookie getCookie(String name) | ||
{ | ||
for (Cookie cookie : getBrowserContext().cookies()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use Java Streams API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored, thanks
private static final String COOKIE_VALUE = "cookieValue"; | ||
private static final String DOMAIN = "https://www.domain.com"; | ||
|
||
@InjectMocks private CookieHelper cookieHelper; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should go after all fields of type @Mock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, thanks
|
||
@InjectMocks private CookieHelper cookieHelper; | ||
@Mock private BrowserContextProvider browserContextProvider; | ||
@Captor private ArgumentCaptor<BrowserContext.ClearCookiesOptions> clearCookiesOptionsCaptor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's used once and thus it can be inlined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored, thanks
@InjectMocks private CookieHelper cookieHelper; | ||
@Mock private BrowserContextProvider browserContextProvider; | ||
@Captor private ArgumentCaptor<BrowserContext.ClearCookiesOptions> clearCookiesOptionsCaptor; | ||
@Captor private ArgumentCaptor<List<Cookie>> cookieCaptor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's used once and thus it can be inlined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored, thanks
@Mock private CookieHelper cookieHelper; | ||
@Mock private VariableContext variableContext; | ||
@Mock private ISoftAssert softAssert; | ||
@InjectMocks private CookieSteps cookieSteps; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should go after all fields of type @Mock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not needed, I believe it is equal to the same story used for Selenium-based steps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i removed this file since we had discussed it's unnecessary right now
2816c96
to
8426539
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5127 +/- ##
============================================
- Coverage 97.43% 97.43% -0.01%
- Complexity 6747 6999 +252
============================================
Files 933 936 +3
Lines 19520 19580 +60
Branches 1298 1299 +1
============================================
+ Hits 19020 19078 +58
- Misses 391 392 +1
- Partials 109 110 +1 ☔ View full report in Codecov by Sentry. |
import com.google.common.net.InetAddresses; | ||
import com.google.common.net.InternetDomainName; | ||
|
||
public final class DomainManager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public final class DomainManager | |
public final class InetAddressUtils |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed, thanks
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.vividus.ui.web.action.DomainManager; | ||
|
||
public class DomainManagerTests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public class DomainManagerTests | |
class DomainManagerTests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed, thanks
"http://127.0.0.1:8080, 127.0.0.1", | ||
"http://localhost:8080, localhost" | ||
}) | ||
void shouldAddCookie(String urlAsString, String domain) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please update method name to reflect the actual test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, thanks
* limitations under the License. | ||
*/ | ||
|
||
package org.vividus.ui.web.playwright.action; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to vividus-extension-web-app
and reuse in both vividus-plugin-web-app
and vividus-plugin-web-app-plyawright
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
|
||
@Override | ||
public String getValue(Cookie cookie) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is it needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed this method
import org.vividus.ui.web.playwright.BrowserContextProvider; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class CookieManagerTests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public class CookieManagerTests | |
class CookieManagerTests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed, thanks
import org.vividus.variable.VariableScope; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class CookieStepsTests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public class CookieStepsTests | |
class CookieStepsTests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed, thanks
8426539
to
a6b66d6
Compare
|
||
T getCookie(String cookieName); | ||
|
||
S getCookies(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S getCookies(); | |
Collection<T> getCookies(); |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks
|
||
package org.vividus.ui.web.action; | ||
|
||
public interface IBaseCookieManager<T, S> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public interface IBaseCookieManager<T, S> | |
public interface CookieManager<T, S> |
(feel free to rename current classes to PlaywrightCookieManager
and WebDriverCookieManager
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, thanks
Cookie getCookie(String cookieName); | ||
|
||
Set<Cookie> getCookies(); | ||
|
||
CookieStore getCookiesAsHttpCookieStore(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's implement this method for playwright cookie manager as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
1ba9122
to
8a760f5
Compare
|
||
public interface ICookieManager | ||
public interface ICookieManager<T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public interface ICookieManager<T> | |
public interface CookieManager<T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed, thanks
8a760f5
to
43fb77f
Compare