Skip to content

Commit 8429f5e

Browse files
committed
added video recording support
1 parent 25f239b commit 8429f5e

File tree

7 files changed

+87
-29
lines changed

7 files changed

+87
-29
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ out
1414
*.ipr
1515
*.iws
1616
*.iml
17-
atlassian-ide-plugin.xml
17+
atlassian-ide-plugin.xml
18+
19+
src/test/resources/testvideo/

build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ repositories {
1313
dependencies {
1414
implementation 'org.aeonbits.owner:owner:1.0.12'
1515
implementation 'com.univocity:univocity-parsers:2.9.1'
16-
implementation 'com.microsoft.playwright:playwright:1.41.2'
16+
implementation 'com.microsoft.playwright:playwright:1.42.0'
1717
implementation 'org.apache.commons:commons-lang3:3.14.0'
1818
implementation 'org.slf4j:slf4j-api:2.0.12'
19-
implementation 'io.qameta.allure:allure-junit-platform:2.24.0'
19+
implementation 'io.qameta.allure:allure-junit-platform:2.26.0'
2020
implementation 'com.github.automatedowl:allure-environment-writer:1.0.0'
2121

22-
compileOnly 'org.projectlombok:lombok:1.18.30'
23-
annotationProcessor 'org.projectlombok:lombok:1.18.30'
24-
testCompileOnly 'org.projectlombok:lombok:1.18.30'
25-
testAnnotationProcessor 'org.projectlombok:lombok:1.18.30'
22+
compileOnly 'org.projectlombok:lombok:1.18.32'
23+
annotationProcessor 'org.projectlombok:lombok:1.18.32'
24+
testCompileOnly 'org.projectlombok:lombok:1.18.32'
25+
testAnnotationProcessor 'org.projectlombok:lombok:1.18.32'
2626

2727
testImplementation platform('org.junit:junit-bom:5.10.2')
2828
testImplementation 'org.junit.jupiter:junit-jupiter'

src/main/java/io/github/tahanima/config/Configuration.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,26 @@
1111
@Sources({"system:properties", "classpath:config.properties", "classpath:allure.properties"})
1212
public interface Configuration extends Config {
1313

14-
String browser();
14+
@Key("allure.results.directory")
15+
String allureResultsDir();
1516

1617
@Key("base.url")
1718
String baseUrl();
1819

20+
@Key("base.test.data.path")
21+
String baseTestDataPath();
22+
23+
@Key("base.test.video.path")
24+
String baseTestVideoPath();
25+
26+
String browser();
27+
1928
boolean headless();
2029

2130
@Key("slow.motion")
2231
int slowMotion();
2332

2433
int timeout();
2534

26-
@Key("base.test.data.path")
27-
String baseTestDataPath();
28-
29-
@Key("allure.results.directory")
30-
String allureResultsDir();
35+
boolean video();
3136
}

src/main/java/io/github/tahanima/factory/BrowserFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* @author tahanima
1212
*/
1313
public enum BrowserFactory {
14+
1415
CHROMIUM {
1516
@Override
1617
public Browser createInstance(final Playwright playwright) {

src/test/java/io/github/tahanima/e2e/LoginTest.java

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
44

5+
import static io.github.tahanima.config.ConfigurationManager.config;
6+
7+
import com.microsoft.playwright.Browser;
8+
59
import io.github.artsok.ParameterizedRepeatedIfExceptionsTest;
610
import io.github.tahanima.annotation.DataSource;
711
import io.github.tahanima.annotation.Smoke;
@@ -13,20 +17,40 @@
1317

1418
import org.junit.jupiter.api.AfterEach;
1519
import org.junit.jupiter.api.BeforeEach;
20+
import org.junit.jupiter.api.TestInfo;
21+
22+
import java.nio.file.Paths;
1623

1724
/**
1825
* @author tahanima
1926
*/
2027
@Feature("Login Test")
2128
public class LoginTest extends BaseTest {
2229

23-
private static final String PATH = "login.csv";
30+
private static final String CSV_PATH = "login.csv";
31+
private static final String VIDEO_PATH = "login/";
2432

2533
@BeforeEach
26-
public void createBrowserContextAndPageAndLoginPageInstances() {
27-
browserContext = browser.newContext();
28-
page = browserContext.newPage();
34+
public void createBrowserContextAndPageAndLoginPageInstances(TestInfo testInfo) {
35+
String testMethodName =
36+
(testInfo.getTestMethod().isPresent())
37+
? testInfo.getTestMethod().get().getName()
38+
: "";
39+
40+
if (config().video()) {
41+
browserContext =
42+
browser.newContext(
43+
new Browser.NewContextOptions()
44+
.setRecordVideoDir(
45+
Paths.get(
46+
config().baseTestVideoPath()
47+
+ VIDEO_PATH
48+
+ testMethodName)));
49+
} else {
50+
browserContext = browser.newContext();
51+
}
2952

53+
page = browserContext.newPage();
3054
loginPage = createInstance(LoginPage.class);
3155
}
3256

@@ -46,7 +70,7 @@ public void closeBrowserContextSession() {
4670
@Description(
4771
"Test that verifies user gets redirected to 'Products' page after submitting correct login credentials")
4872
@ParameterizedRepeatedIfExceptionsTest
49-
@DataSource(id = "TC-1", fileName = PATH, clazz = LoginDto.class)
73+
@DataSource(id = "TC-1", fileName = CSV_PATH, clazz = LoginDto.class)
5074
public void testCorrectLoginCredentials(final LoginDto data) {
5175
ProductsPage productsPage = loginPage.loginAs(data.getUsername(), data.getPassword());
5276

@@ -59,7 +83,7 @@ public void testCorrectLoginCredentials(final LoginDto data) {
5983
@Description(
6084
"Test that verifies user gets error message after submitting incorrect login credentials")
6185
@ParameterizedRepeatedIfExceptionsTest
62-
@DataSource(id = "TC-2", fileName = PATH, clazz = LoginDto.class)
86+
@DataSource(id = "TC-2", fileName = CSV_PATH, clazz = LoginDto.class)
6387
public void testIncorrectLoginCredentials(final LoginDto data) {
6488
loginPage.loginAs(data.getUsername(), data.getPassword());
6589

@@ -72,7 +96,7 @@ public void testIncorrectLoginCredentials(final LoginDto data) {
7296
@Description(
7397
"Test that verifies user gets error message after submitting login credentials where the username is blank")
7498
@ParameterizedRepeatedIfExceptionsTest
75-
@DataSource(id = "TC-3", fileName = PATH, clazz = LoginDto.class)
99+
@DataSource(id = "TC-3", fileName = CSV_PATH, clazz = LoginDto.class)
76100
public void testBlankUserName(final LoginDto data) {
77101
loginPage.open().typePassword(data.getPassword()).submitLogin();
78102

@@ -85,7 +109,7 @@ public void testBlankUserName(final LoginDto data) {
85109
@Description(
86110
"Test that verifies user gets error message after submitting login credentials where the password is blank")
87111
@ParameterizedRepeatedIfExceptionsTest
88-
@DataSource(id = "TC-4", fileName = PATH, clazz = LoginDto.class)
112+
@DataSource(id = "TC-4", fileName = CSV_PATH, clazz = LoginDto.class)
89113
public void testBlankPassword(final LoginDto data) {
90114
loginPage.open().typeUsername(data.getUsername()).submitLogin();
91115

@@ -98,7 +122,7 @@ public void testBlankPassword(final LoginDto data) {
98122
@Description(
99123
"Test that verifies user gets error message after submitting login credentials for locked out user")
100124
@ParameterizedRepeatedIfExceptionsTest
101-
@DataSource(id = "TC-5", fileName = PATH, clazz = LoginDto.class)
125+
@DataSource(id = "TC-5", fileName = CSV_PATH, clazz = LoginDto.class)
102126
public void testLockedOutUser(final LoginDto data) {
103127
loginPage.loginAs(data.getUsername(), data.getPassword());
104128

src/test/java/io/github/tahanima/e2e/ProductsTest.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
44

5+
import static io.github.tahanima.config.ConfigurationManager.config;
6+
7+
import com.microsoft.playwright.Browser;
8+
59
import io.github.artsok.ParameterizedRepeatedIfExceptionsTest;
610
import io.github.tahanima.annotation.DataSource;
711
import io.github.tahanima.annotation.Smoke;
@@ -11,20 +15,40 @@
1115

1216
import org.junit.jupiter.api.AfterEach;
1317
import org.junit.jupiter.api.BeforeEach;
18+
import org.junit.jupiter.api.TestInfo;
19+
20+
import java.nio.file.Paths;
1421

1522
/**
1623
* @author tahanima
1724
*/
1825
@Feature("Products Test")
1926
public class ProductsTest extends BaseTest {
2027

21-
private static final String PATH = "products.csv";
28+
private static final String CSV_PATH = "products.csv";
29+
private static final String VIDEO_PATH = "products/";
2230

2331
@BeforeEach
24-
public void createBrowserContextAndPageAndLoginPageInstances() {
25-
browserContext = browser.newContext();
26-
page = browserContext.newPage();
32+
public void createBrowserContextAndPageAndLoginPageInstances(TestInfo testInfo) {
33+
String testMethodName =
34+
(testInfo.getTestMethod().isPresent())
35+
? testInfo.getTestMethod().get().getName()
36+
: "";
37+
38+
if (config().video()) {
39+
browserContext =
40+
browser.newContext(
41+
new Browser.NewContextOptions()
42+
.setRecordVideoDir(
43+
Paths.get(
44+
config().baseTestVideoPath()
45+
+ VIDEO_PATH
46+
+ testMethodName)));
47+
} else {
48+
browserContext = browser.newContext();
49+
}
2750

51+
page = browserContext.newPage();
2852
loginPage = createInstance(LoginPage.class);
2953
}
3054

@@ -43,7 +67,7 @@ public void closeBrowserContextSession() {
4367
@Owner("Tahanima Chowdhury")
4468
@Description("Test that verifies user gets redirected to 'Login' page after logging out")
4569
@ParameterizedRepeatedIfExceptionsTest
46-
@DataSource(id = "TC-1", fileName = PATH, clazz = ProductsDto.class)
70+
@DataSource(id = "TC-1", fileName = CSV_PATH, clazz = ProductsDto.class)
4771
public void testSuccessfulLogout(final ProductsDto data) {
4872
loginPage.loginAs(data.getUsername(), data.getPassword()).clickOnLogout();
4973

src/test/resources/config.properties

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
base.url=https://www.saucedemo.com/
2+
base.test.data.path=src/test/resources/testdata/
3+
base.test.video.path=src/test/resources/testvideo/
14
browser=chromium
25
headless=true
36
slow.motion=50
47
timeout=10000
5-
base.url=https://www.saucedemo.com/
6-
base.test.data.path=src/test/resources/testdata/
8+
video=true

0 commit comments

Comments
 (0)