Skip to content

Commit

Permalink
Release/v2.1 (#17)
Browse files Browse the repository at this point in the history
* get main in sync with develop (#10) (#11)

* Update to v2 (#13)

* Simplify parameter resolvers and add APIRequestContext

* Add tests for APITestContext. add ability to declare rest config at parameter level

* Store APIContext after creating

* Update readme

* update pom to 2.0

* Bump to 2.1-SNAPSHOT

* Don't save APIRequestContext in store so multiple ones can be used to… (#16)

* Don't save APIRequestContext in store so multiple ones can be used to test different APIs together

* Update docs

* Bump version
  • Loading branch information
uchagani authored Apr 11, 2022
1 parent fbe96c4 commit f59686a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
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");
}
}

0 comments on commit f59686a

Please sign in to comment.