Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public class APIRequestContextTests {
}
```

`@UseRestConfig` annotation can be used either at the class level, method level, or parameter level.
`@UseBrowserConfig` annotation can be used either at the class level, method level.
`@UseRestConfig` annotation can be used either at the class level, method leve, or parameter level.

## Running tests in parallel

Expand Down Expand Up @@ -125,6 +126,8 @@ configs and create tests.
You can override the config for a particular test method by adding the `@UseBrowserConfig` annotation over a test
method:

### Overriding config

```java

@UseBrowserConfig(DefaultConfig.class)
Expand All @@ -142,6 +145,22 @@ public class InjectBrowserTests {
}
```

### Testing multiple APIs in one test

```java
@Test
public void useDifferentConfigsInTheSameTest(@UseRestConfig(
SpecificRestConfig.class) APIRequestContext specificRequest, @UseRestConfig(
OverrideRestConfig.class) APIRequestContext overrideRequest) {

assertThat(specificRequest).isNotNull();
assertThat(overrideRequest).isNotNull();
assertThat(specificRequest.get("/foo").url()).contains("google.com/foo");
assertThat(overrideRequest.get("/foo").url()).contains("bing.com/foo");
}
```


## Requirements

* Java 8+
Expand All @@ -153,4 +172,4 @@ public class InjectBrowserTests {
To migrate to v2.x from v1.x, there are a couple of changes that you need to make:

1. Change `PlaywrightConfig` to `PlaywrightBrowserConfig`.
2. Change `@InjectPlaywright` to `@UserBrowserConfig`.
2. Change `@InjectPlaywright` to `@UseBrowserConfig`.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.uchagani</groupId>
<artifactId>junit-playwright</artifactId>
<version>2.0</version>
<version>2.1</version>

<name>junit-playwright</name>
<description>junit-playwright allows you to easily run Playwright-Java tests in parallel</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,12 @@ private static Playwright getPlaywright(ExtensionContext extensionContext) {
}

public static APIRequestContext getAPIRequestContext(ParameterContext parameterContext, ExtensionContext extensionContext) {
APIRequestContext apiRequestContext = getObjectFromStore(extensionContext, id, APIRequestContext.class);
if (apiRequestContext == null) {
RestConfig restConfig = getRestConfig(parameterContext, extensionContext);
Playwright playwright = getPlaywright(extensionContext);
apiRequestContext = createAPIRequestContext(playwright, restConfig);
saveAPIRequestContextInStore(extensionContext, apiRequestContext);
}
return apiRequestContext;
RestConfig restConfig = getRestConfig(parameterContext, extensionContext);
Playwright playwright = getPlaywright(extensionContext);
return createAPIRequestContext(playwright, restConfig);
}

@SuppressWarnings("unused")
public static void saveAPIRequestContextInStore(ExtensionContext extensionContext, APIRequestContext apiRequestContext) {
saveObjectInStore(extensionContext, id, apiRequestContext);
}
Expand Down
10 changes: 6 additions & 4 deletions src/test/java/io/github/uchagani/jp/APIRequestContextTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ public void shouldInjectAPIRequestContextDefinedAtMethodLevel(APIRequestContext
}

@Test
@UseRestConfig(OverrideRestConfig.class) //this should not be used but is here just to ensure it isn't used
public void shouldInjectAPIRequestContextDefinedAtParameterLevel(@UseRestConfig(
SpecificRestConfig.class) APIRequestContext request) {
assertThat(request).isNotNull();
assertThat(request.get("/foo").url()).contains("google.com/foo");
SpecificRestConfig.class) APIRequestContext specificRequest, @UseRestConfig(
OverrideRestConfig.class) APIRequestContext overrideRequest) {
assertThat(specificRequest).isNotNull();
assertThat(overrideRequest).isNotNull();
assertThat(specificRequest.get("/foo").url()).contains("google.com/foo");
assertThat(overrideRequest.get("/foo").url()).contains("bing.com/foo");
}
}