Skip to content

Commit f2cf047

Browse files
committed
update
1 parent 78d16f7 commit f2cf047

File tree

22 files changed

+289
-228
lines changed

22 files changed

+289
-228
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ out
1616
*.iml
1717
atlassian-ide-plugin.xml
1818

19-
report
19+
testoutput

build.gradle

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,24 @@ dependencies {
2020
implementation 'com.univocity:univocity-parsers:2.9.1'
2121
implementation 'com.aventstack:extentreports:5.0.9'
2222
implementation 'com.microsoft.playwright:playwright:1.31.0'
23+
implementation 'org.apache.commons:commons-lang3:3.12.0'
24+
implementation 'org.apache.commons:commons-text:1.10.0'
2325
implementation 'org.slf4j:slf4j-api:2.0.6'
2426

25-
testCompileOnly 'org.projectlombok:lombok:1.18.26'
26-
testAnnotationProcessor 'org.projectlombok:lombok:1.18.26'
27+
compileOnly 'org.projectlombok:lombok:1.18.26'
28+
annotationProcessor 'org.projectlombok:lombok:1.18.26'
2729

2830
testImplementation 'org.testng:testng:7.7.1'
2931
testImplementation 'org.slf4j:slf4j-simple:2.0.6'
3032
}
3133

3234
test {
3335
systemProperties = System.getProperties() as Map<String, ?>
34-
def groups = System.getProperty('groups', 'regression')
35-
def thread = System.getProperty('thread', '5')
36+
def group = System.getProperty('group', 'regression')
37+
def thread = System.getProperty('thread', '100')
3638

3739
useTestNG() {
38-
includeGroups groups
40+
includeGroups group
3941
parallel 'classes'
4042
threadCount thread as int
4143
}

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
rootProject.name = 'playwright-test-automation-boilerplate'
1+
rootProject.name = 'playwright-java-test-automation-architecture'
22

src/test/java/io/github/tahanima/config/ConfigurationManager.java renamed to src/main/java/io/github/tahanima/config/ConfigurationManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ private ConfigurationManager() {}
1414
* @return an instance of Configuration class from an internal cache
1515
* @see <a href="http://owner.aeonbits.org/docs/singleton">reference</a>
1616
*/
17-
public static Configuration configuration() {
17+
public static Configuration config() {
1818
return ConfigCache.getOrCreate(Configuration.class);
1919
}
2020
}

src/test/java/io/github/tahanima/data/BaseData.java renamed to src/main/java/io/github/tahanima/data/BaseTestData.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.tahanima.data;
22

33
import com.univocity.parsers.annotations.Parsed;
4+
45
import lombok.Getter;
56
import lombok.ToString;
67

@@ -11,7 +12,7 @@
1112
*/
1213
@Getter
1314
@ToString
14-
public class BaseData {
15+
public class BaseTestData {
1516
@Parsed(field = "Test Case ID", defaultNullRead = "")
1617
private String testCaseId;
1718

src/test/java/io/github/tahanima/data/login/LoginData.java renamed to src/main/java/io/github/tahanima/data/login/LoginTestData.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package io.github.tahanima.data.login;
22

33
import com.univocity.parsers.annotations.Parsed;
4-
import io.github.tahanima.data.BaseData;
4+
5+
import io.github.tahanima.data.BaseTestData;
6+
57
import lombok.Getter;
68
import lombok.ToString;
79

@@ -12,7 +14,7 @@
1214
*/
1315
@Getter
1416
@ToString(callSuper = true)
15-
public class LoginData extends BaseData {
17+
public class LoginTestData extends BaseTestData {
1618
@Parsed(field = "User Name", defaultNullRead = "")
1719
private String userName;
1820

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.github.tahanima.page;
2+
3+
import static io.github.tahanima.config.ConfigurationManager.config;
4+
5+
import com.microsoft.playwright.Page;
6+
7+
import java.nio.file.Path;
8+
9+
/**
10+
* @author tahanima
11+
*/
12+
public class BasePage {
13+
protected Page page;
14+
15+
public void setAndConfigurePage(Page page) {
16+
this.page = page;
17+
page.setDefaultTimeout(config().timeout());
18+
}
19+
20+
private String getScreenshotFilePath(String path) {
21+
return config().baseScreenshotPath() + path;
22+
}
23+
24+
public void captureScreenshot(String fileName) {
25+
page.screenshot(
26+
new Page.ScreenshotOptions()
27+
.setPath(Path.of(String.format("%s.png", getScreenshotFilePath(fileName))))
28+
.setFullPage(true));
29+
}
30+
}

src/test/java/io/github/tahanima/pages/BasePageFactory.java renamed to src/main/java/io/github/tahanima/page/BasePageFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.github.tahanima.pages;
1+
package io.github.tahanima.page;
22

33
import com.microsoft.playwright.Page;
44

Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
1-
package io.github.tahanima.pages.login;
1+
package io.github.tahanima.page.login;
2+
3+
import static io.github.tahanima.config.ConfigurationManager.config;
24

35
import com.microsoft.playwright.Locator;
4-
import io.github.tahanima.pages.BasePage;
56

6-
import static io.github.tahanima.config.ConfigurationManager.configuration;
7+
import io.github.tahanima.page.BasePage;
78

89
/**
910
* This class captures the relevant UI components and functionalities of the login page.
1011
*
1112
* @author tahanima
1213
*/
1314
public class LoginPage extends BasePage {
14-
public LoginPage goTo() {
15-
page.navigate(configuration().baseUrl());
15+
public LoginPage navigateToUrl() {
16+
page.navigate(config().baseUrl());
1617

1718
return this;
1819
}
1920

20-
public LoginPage enterUsername(String username) {
21+
public LoginPage fillUsernameInTextBox(String username) {
2122
page.fill("id=user-name", username);
2223

2324
return this;
2425
}
2526

26-
public LoginPage enterPassword(String password) {
27+
public LoginPage fillPasswordInTextBox(String password) {
2728
page.fill("id=password", password);
2829

2930
return this;
3031
}
3132

32-
public Locator getErrorMessageLocator() {
33+
public Locator getErrorMessage() {
3334
return page.locator(".error-message-container h3");
3435
}
3536

36-
public void clickLogin() {
37+
public void clickOnLoginButton() {
3738
page.click("id=login-button");
3839
}
3940
}

src/test/java/io/github/tahanima/pages/product/ProductsPage.java renamed to src/main/java/io/github/tahanima/page/product/ProductsPage.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package io.github.tahanima.pages.product;
1+
package io.github.tahanima.page.product;
22

33
import com.microsoft.playwright.Locator;
4-
import io.github.tahanima.pages.BasePage;
4+
5+
import io.github.tahanima.page.BasePage;
56

67
/**
78
* This class captures only those features needed to support test functionalities of the login page.

src/test/java/io/github/tahanima/utils/ExtentReportManager.java renamed to src/main/java/io/github/tahanima/report/ExtentReportManager.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
package io.github.tahanima.utils;
1+
package io.github.tahanima.report;
2+
3+
import static io.github.tahanima.config.ConfigurationManager.config;
24

35
import com.aventstack.extentreports.ExtentReports;
46
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
57

8+
import org.apache.commons.lang3.StringUtils;
9+
610
import java.text.SimpleDateFormat;
711
import java.util.Date;
812

9-
import static io.github.tahanima.config.ConfigurationManager.configuration;
10-
1113
/**
1214
* @author tahanima
1315
*/
@@ -16,19 +18,24 @@ private ExtentReportManager() {}
1618

1719
public static ExtentReports createReport() {
1820
String currentDate = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss").format(new Date());
19-
2021
String fileName =
21-
String.format(
22-
"%sTestReport_%s.html", configuration().baseReportPath(), currentDate);
22+
String.format("%sE2ETestReport_%s.html", config().baseReportPath(), currentDate);
2323

2424
ExtentReports extentReport = new ExtentReports();
2525
ExtentSparkReporter spark = new ExtentSparkReporter(fileName);
26-
extentReport.attachReporter(spark);
2726

27+
spark.config().setTimeStampFormat("dd MMM yyyy HH:mm:ss z");
28+
spark.config().setTimelineEnabled(false);
29+
30+
extentReport.attachReporter(spark);
2831
extentReport.setSystemInfo("Platform", System.getProperty("os.name"));
2932
extentReport.setSystemInfo("Version", System.getProperty("os.version"));
30-
extentReport.setSystemInfo("Browser", configuration().browser());
31-
extentReport.setSystemInfo("Base URL", configuration().baseUrl());
33+
extentReport.setSystemInfo("Browser", StringUtils.capitalize(config().browser()));
34+
extentReport.setSystemInfo("Context URL", config().baseUrl());
35+
extentReport.setSystemInfo(
36+
"Test Group",
37+
StringUtils.capitalize(
38+
StringUtils.defaultString(System.getProperty("groups"), "regression")));
3239

3340
return extentReport;
3441
}

src/test/java/io/github/tahanima/browser/BrowserFactory.java renamed to src/main/java/io/github/tahanima/util/BrowserFactory.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package io.github.tahanima.browser;
1+
package io.github.tahanima.util;
2+
3+
import static io.github.tahanima.config.ConfigurationManager.config;
24

35
import com.microsoft.playwright.Browser;
46
import com.microsoft.playwright.BrowserType;
57
import com.microsoft.playwright.BrowserType.LaunchOptions;
68
import com.microsoft.playwright.Playwright;
79

8-
import static io.github.tahanima.config.ConfigurationManager.configuration;
9-
1010
/**
1111
* @author tahanima
1212
*/
@@ -26,8 +26,8 @@ public Browser initialize(Playwright playwright) {
2626

2727
public LaunchOptions options() {
2828
return new BrowserType.LaunchOptions()
29-
.setHeadless(configuration().headless())
30-
.setSlowMo(configuration().slowMotion());
29+
.setHeadless(config().headless())
30+
.setSlowMo(config().slowMotion());
3131
}
3232

3333
public abstract Browser initialize(Playwright playwright);
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
package io.github.tahanima.browser;
1+
package io.github.tahanima.util;
2+
3+
import static io.github.tahanima.config.ConfigurationManager.config;
24

35
import com.microsoft.playwright.Browser;
46
import com.microsoft.playwright.Playwright;
57

6-
import static io.github.tahanima.config.ConfigurationManager.configuration;
7-
88
/**
99
* @author tahanima
1010
*/
1111
public final class BrowserManager {
1212
private BrowserManager() {}
1313

1414
public static Browser browser(Playwright playwright) {
15-
return BrowserFactory.valueOf(configuration().browser().toUpperCase())
15+
return BrowserFactory.valueOf(config().browser().toUpperCase())
1616
.initialize(playwright);
1717
}
1818
}

src/test/resources/config.properties renamed to src/main/resources/config.properties

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ browser=chromium
33
headless=true
44
slow.motion=50
55
timeout=10000
6-
76
# saucedemo base url
87
base.url=https://www.saucedemo.com/
9-
108
# base path for test data
11-
base.test.data.path=src/test/resources/testData/
12-
9+
base.test.data.path=src/test/resources/testdata/
1310
# base path for report
14-
base.report.path=report/
15-
11+
base.report.path=testoutput/report/
1612
# base path for screenshot
17-
base.screenshot.path=screenshot/
13+
base.screenshot.path=testoutput/screenshot/

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package io.github.tahanima.e2e;
22

3+
import static io.github.tahanima.config.ConfigurationManager.config;
4+
35
import com.microsoft.playwright.Browser;
46
import com.microsoft.playwright.BrowserContext;
57
import com.microsoft.playwright.Page;
68
import com.microsoft.playwright.Playwright;
7-
import io.github.tahanima.browser.BrowserManager;
8-
import io.github.tahanima.pages.BasePage;
9-
import io.github.tahanima.pages.BasePageFactory;
10-
import io.github.tahanima.utils.TestListener;
9+
10+
import io.github.tahanima.page.BasePage;
11+
import io.github.tahanima.page.BasePageFactory;
12+
import io.github.tahanima.util.BrowserManager;
13+
import io.github.tahanima.util.TestListener;
14+
1115
import org.testng.annotations.AfterClass;
1216
import org.testng.annotations.BeforeClass;
1317
import org.testng.annotations.Listeners;
@@ -22,6 +26,14 @@ public class BaseE2ETest {
2226
protected BrowserContext browserContext;
2327
protected Page page;
2428

29+
protected String getTestDataFilePath(String path) {
30+
return config().baseTestDataPath() + path;
31+
}
32+
33+
protected String getScreenshotFilePath(String path) {
34+
return config().baseScreenshotPath() + path;
35+
}
36+
2537
protected <T extends BasePage> T createInstance(Class<T> basePage) {
2638
return BasePageFactory.createInstance(page, basePage);
2739
}

0 commit comments

Comments
 (0)