Skip to content

Commit ef26ef4

Browse files
committed
misc updates
1 parent af19b3d commit ef26ef4

31 files changed

+443
-249
lines changed

Diff for: build.gradle

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dependencies {
2929

3030
testImplementation platform('org.junit:junit-bom:5.9.1')
3131
testImplementation 'org.junit.jupiter:junit-jupiter'
32+
testImplementation 'io.github.artsok:rerunner-jupiter:2.1.6'
3233
testImplementation 'org.slf4j:slf4j-simple:2.0.6'
3334
}
3435

@@ -40,3 +41,8 @@ test {
4041
includeTags group
4142
}
4243
}
44+
45+
tasks.register('playwright', JavaExec) {
46+
classpath = sourceSets.main.runtimeClasspath
47+
mainClass = 'com.microsoft.playwright.CLI'
48+
}

Diff for: src/main/java/io/github/tahanima/config/Configuration.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @author tahanima
99
*/
1010
@LoadPolicy(Config.LoadType.MERGE)
11-
@Sources({"system:properties", "classpath:general.properties", "classpath:allure.properties"})
11+
@Sources({"system:properties", "classpath:config.properties", "classpath:allure.properties"})
1212
public interface Configuration extends Config {
1313

1414
String browser();

Diff for: src/main/java/io/github/tahanima/data/BaseTestData.java renamed to src/main/java/io/github/tahanima/data/BaseData.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
@Getter
1212
@ToString
13-
public class BaseTestData {
13+
public class BaseData {
1414

1515
@Parsed(field = "Test Case ID", defaultNullRead = "")
1616
private String testCaseId;

Diff for: src/main/java/io/github/tahanima/data/login/LoginTestData.java renamed to src/main/java/io/github/tahanima/data/LoginData.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
package io.github.tahanima.data.login;
1+
package io.github.tahanima.data;
22

33
import com.univocity.parsers.annotations.Parsed;
44

5-
import io.github.tahanima.data.BaseTestData;
6-
75
import lombok.Getter;
86
import lombok.ToString;
97

@@ -12,10 +10,10 @@
1210
*/
1311
@Getter
1412
@ToString(callSuper = true)
15-
public class LoginTestData extends BaseTestData {
13+
public class LoginData extends BaseData {
1614

17-
@Parsed(field = "User Name", defaultNullRead = "")
18-
private String userName;
15+
@Parsed(field = "Username", defaultNullRead = "")
16+
private String username;
1917

2018
@Parsed(field = "Password", defaultNullRead = "")
2119
private String password;
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.github.tahanima.data;
2+
3+
import com.univocity.parsers.annotations.Parsed;
4+
5+
import lombok.Getter;
6+
import lombok.ToString;
7+
8+
/**
9+
* @author tahanima
10+
*/
11+
@Getter
12+
@ToString(callSuper = true)
13+
public final class ProductsData extends BaseData {
14+
15+
@Parsed(field = "Username", defaultNullRead = "")
16+
private String username;
17+
18+
@Parsed(field = "Password", defaultNullRead = "")
19+
private String password;
20+
21+
@Parsed(field = "URL", defaultNullRead = "")
22+
private String url;
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.github.tahanima.factory;
2+
3+
import com.microsoft.playwright.Page;
4+
5+
import io.github.tahanima.ui.page.BasePage;
6+
7+
/**
8+
* @author tahanima
9+
*/
10+
public final class BasePageFactory {
11+
12+
private BasePageFactory() {}
13+
14+
public static <T extends BasePage> T createInstance(final Page page, final Class<T> clazz) {
15+
try {
16+
BasePage instance = clazz.getDeclaredConstructor().newInstance();
17+
18+
instance.setAndConfigurePage(page);
19+
instance.initComponents();
20+
21+
return clazz.cast(instance);
22+
} catch (Exception e) {
23+
e.printStackTrace();
24+
}
25+
26+
throw new NullPointerException("Page class instantiation failed.");
27+
}
28+
}

Diff for: src/main/java/io/github/tahanima/util/BrowserFactory.java renamed to src/main/java/io/github/tahanima/factory/BrowserFactory.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.github.tahanima.util;
1+
package io.github.tahanima.factory;
22

33
import static io.github.tahanima.config.ConfigurationManager.config;
44

@@ -14,19 +14,19 @@ public enum BrowserFactory {
1414

1515
CHROMIUM {
1616
@Override
17-
public Browser createInstance(Playwright playwright) {
17+
public Browser createInstance(final Playwright playwright) {
1818
return playwright.chromium().launch(options());
1919
}
2020
},
2121
FIREFOX {
2222
@Override
23-
public Browser createInstance(Playwright playwright) {
23+
public Browser createInstance(final Playwright playwright) {
2424
return playwright.firefox().launch(options());
2525
}
2626
},
2727
WEBKIT {
2828
@Override
29-
public Browser createInstance(Playwright playwright) {
29+
public Browser createInstance(final Playwright playwright) {
3030
return playwright.webkit().launch(options());
3131
}
3232
};
@@ -37,5 +37,5 @@ public LaunchOptions options() {
3737
.setSlowMo(config().slowMotion());
3838
}
3939

40-
public abstract Browser createInstance(Playwright playwright);
40+
public abstract Browser createInstance(final Playwright playwright);
4141
}

Diff for: src/main/java/io/github/tahanima/page/BasePage.java

-22
This file was deleted.

Diff for: src/main/java/io/github/tahanima/page/BasePageFactory.java

-24
This file was deleted.

Diff for: src/main/java/io/github/tahanima/page/product/ProductsPage.java

-17
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.github.tahanima.ui.component;
2+
3+
import com.microsoft.playwright.Page;
4+
5+
/**
6+
* @author tahanima
7+
*/
8+
public abstract class BaseComponent {
9+
10+
protected Page page;
11+
12+
protected BaseComponent(final Page page) {
13+
this.page = page;
14+
}
15+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.github.tahanima.ui.component;
2+
3+
import com.microsoft.playwright.Page;
4+
5+
/**
6+
* @author tahanima
7+
*/
8+
public final class Header extends BaseComponent {
9+
10+
public Header(final Page page) {
11+
super(page);
12+
}
13+
14+
public void clickOnHamburgerIcon() {
15+
page.click("#react-burger-menu-btn");
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.github.tahanima.ui.component;
2+
3+
import com.microsoft.playwright.Page;
4+
5+
/**
6+
* @author tahanima
7+
*/
8+
public final class SideNavMenu extends BaseComponent {
9+
10+
public SideNavMenu(final Page page) {
11+
super(page);
12+
}
13+
14+
public void clickOnLogout() {
15+
page.click("#logout_sidebar_link");
16+
}
17+
}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.github.tahanima.ui.page;
2+
3+
import static io.github.tahanima.config.ConfigurationManager.config;
4+
5+
import com.microsoft.playwright.Page;
6+
7+
import io.qameta.allure.Step;
8+
9+
/**
10+
* @author tahanima
11+
*/
12+
public abstract class BasePage {
13+
14+
protected Page page;
15+
16+
public void setAndConfigurePage(final Page page) {
17+
this.page = page;
18+
19+
page.setDefaultTimeout(config().timeout());
20+
}
21+
22+
public void initComponents() {}
23+
24+
@Step
25+
public byte[] captureScreenshot() {
26+
return page.screenshot();
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
package io.github.tahanima.page.login;
1+
package io.github.tahanima.ui.page;
22

33
import static io.github.tahanima.config.ConfigurationManager.config;
44

55
import com.microsoft.playwright.Locator;
66

7-
import io.github.tahanima.page.BasePage;
7+
import io.github.tahanima.factory.BasePageFactory;
88
import io.qameta.allure.Step;
99

1010
/**
1111
* @author tahanima
1212
*/
13-
public class LoginPage extends BasePage {
13+
public final class LoginPage extends BasePage {
1414

1515
@Step("Navigate to the login page")
16-
public LoginPage navigateToUrl() {
16+
public LoginPage open() {
1717
page.navigate(config().baseUrl());
1818

1919
return this;
2020
}
2121

2222
@Step("Type <username> into 'Username' textbox")
23-
public LoginPage typeUsernameIntoTextBox(String username) {
23+
public LoginPage typeUsername(final String username) {
2424
page.fill("id=user-name", username);
2525

2626
return this;
2727
}
2828

2929
@Step("Type <password> into 'Password' textbox")
30-
public LoginPage typePasswordIntoTextBox(String password) {
30+
public LoginPage typePassword(final String password) {
3131
page.fill("id=password", password);
3232

3333
return this;
@@ -39,7 +39,18 @@ public Locator getErrorMessage() {
3939
}
4040

4141
@Step("Click on the 'Login' button")
42-
public void clickOnLoginButton() {
42+
public ProductsPage submitLogin() {
4343
page.click("id=login-button");
44+
45+
return BasePageFactory.createInstance(page, ProductsPage.class);
46+
}
47+
48+
@Step("Login attempt to Swag Labs")
49+
public ProductsPage loginAs(final String username, final String password) {
50+
open();
51+
typeUsername(username);
52+
typePassword(password);
53+
54+
return submitLogin();
4455
}
4556
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.github.tahanima.ui.page;
2+
3+
import com.microsoft.playwright.Locator;
4+
5+
import io.github.tahanima.factory.BasePageFactory;
6+
import io.github.tahanima.ui.component.Header;
7+
import io.github.tahanima.ui.component.SideNavMenu;
8+
import io.qameta.allure.Step;
9+
10+
/**
11+
* @author tahanima
12+
*/
13+
public final class ProductsPage extends BasePage {
14+
15+
private Header header;
16+
private SideNavMenu sideNavMenu;
17+
18+
@Override
19+
public void initComponents() {
20+
header = new Header(page);
21+
sideNavMenu = new SideNavMenu(page);
22+
}
23+
24+
@Step("Get title of the 'Products' page")
25+
public Locator getTitle() {
26+
return page.locator(".title");
27+
}
28+
29+
@Step("Click on 'Logout' button from side navigation menu")
30+
public LoginPage clickOnLogout() {
31+
header.clickOnHamburgerIcon();
32+
sideNavMenu.clickOnLogout();
33+
34+
return BasePageFactory.createInstance(page, LoginPage.class);
35+
}
36+
}

0 commit comments

Comments
 (0)