Skip to content

Commit 52dfe30

Browse files
Feature/monkey tests (#429)
* github actions, playwriht version update * fix on working directory in github actions * fix * video off * Monkey Tests introduces * fix on Allure story
1 parent 61c58f2 commit 52dfe30

9 files changed

Lines changed: 476 additions & 261 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Test execution
2+
3+
on:
4+
push:
5+
paths:
6+
- mrchecker-playwright-framework/**
7+
8+
jobs:
9+
test:
10+
timeout-minutes: 30
11+
runs-on: ubuntu-latest
12+
container:
13+
image: mcr.microsoft.com/playwright/java:v1.44.0-jammy
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Set up JDK and Maven
19+
uses: actions/setup-java@v2
20+
with:
21+
java-version: '21'
22+
distribution: 'zulu'
23+
maven-version: '3.8.1'
24+
25+
- name: Install git
26+
run: apt-get -y update && apt-get install -y git-lfs
27+
28+
- name: Install tests
29+
run: mvn install -DskipTests --no-transfer-progress
30+
working-directory: ./mrchecker-playwright-framework
31+
32+
- name: Run tests
33+
run: mvn test -Dheadless=true
34+
working-directory: ./mrchecker-playwright-framework
35+
36+
- name: Generate Allure report
37+
run: mvn allure:report
38+
working-directory: ./mrchecker-playwright-framework
39+
40+
- name: Publish test report
41+
uses: peaceiris/actions-gh-pages@v4
42+
if: always()
43+
with:
44+
github_token: ${{ secrets.GITHUB_TOKEN }}
45+
publish_branch: allure-report
46+
publish_dir: ./mrchecker-playwright-framework/target/allure-report
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
page.navigate("https://demoqa.com/login");
2+
page.locator("span").filter(new Locator.FilterOptions().setHasText("Forms")).locator("div").first().click();
3+
page.getByRole(AriaRole.LISTITEM).click();
4+
page.getByPlaceholder("First Name").click();
5+
page.getByPlaceholder("First Name").fill("Name");
6+
page.getByPlaceholder("Last Name").click();
7+
page.getByPlaceholder("Last Name").fill("LastName");
8+
page.getByPlaceholder("name@example.com").click();
9+
page.getByPlaceholder("name@example.com").fill("my@google.pl");
10+
page.getByText("Male", new Page.GetByTextOptions().setExact(true)).click();
11+
page.getByText("Female").click();
12+
page.getByText("Other").click();
13+
page.getByPlaceholder("Mobile Number").click();
14+
page.getByPlaceholder("Mobile Number").fill("1234567");
15+
page.locator("#dateOfBirthInput").click();
16+
page.getByLabel("Choose Sunday, April 14th,").click();
17+
page.locator(".subjects-auto-complete__value-container").click();
18+
page.locator("#subjectsInput").fill("Math");
19+
page.locator("div").filter(new Locator.FilterOptions().setHasText(Pattern.compile("^Math$"))).nth(1).click();
20+
page.locator(".subjects-auto-complete__value-container").click();
21+
page.locator("#subjectsInput").fill("a");
22+
Page page1 = page.waitForPopup(() -> {
23+
page.frameLocator("iframe[name=\"google_ads_iframe_\\/21849154601\\,22343295815\\/Ad\\.Plus-Anchor_0\"]").locator("html").click();
24+
});
25+
page.locator(".subjects-auto-complete__value-container").click();
26+
page.locator("#subjectsInput").fill("a");
27+
page.getByText("Maths", new Page.GetByTextOptions().setExact(true)).click();
28+
page.getByText("Sports").click();
29+
page.getByText("Reading").click();
30+
page.getByText("Music").click();
31+
page.getByPlaceholder("Current Address").click();
32+
page.getByPlaceholder("Current Address").fill("ala ma kota");
33+
page.locator("#state svg").click();
34+
page.getByText("Uttar Pradesh", new Page.GetByTextOptions().setExact(true)).click();
35+
page.locator("#city svg").click();
36+
page.getByText("Agra", new Page.GetByTextOptions().setExact(true)).click();
37+
page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Submit")).click();
38+
page.getByPlaceholder("Mobile Number").click();
39+
page.getByPlaceholder("Mobile Number").fill("1234567890");

mrchecker-playwright-framework/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<thread.count>3</thread.count>
3535
<env>ENV1</env>
3636
<!-- PLAYWRIGHT -->
37-
<playwright.verion>1.42.0</playwright.verion>
37+
<playwright.verion>1.44.0</playwright.verion>
3838

3939
<!-- JUNIT -->
4040
<junit.version>5.10.1</junit.version>

mrchecker-playwright-framework/src/main/java/com/capgemini/framework/actions/ActionGui.java

Lines changed: 164 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,30 @@
22

33
import com.capgemini.framework.logger.AllureStepLogger;
44
import com.capgemini.framework.logger.Logger;
5+
import com.microsoft.playwright.Dialog;
6+
import com.microsoft.playwright.ElementHandle;
57
import com.microsoft.playwright.Locator;
68
import com.microsoft.playwright.Page;
79
import com.microsoft.playwright.options.LoadState;
10+
import com.microsoft.playwright.options.WaitForSelectorState;
811
import io.qameta.allure.Step;
12+
import org.assertj.core.api.Assertions;
13+
import org.assertj.core.api.Fail;
914

15+
import java.util.List;
16+
import java.util.function.Consumer;
17+
18+
import static com.capgemini.framework.playwright.PlaywrightFactory.getBrowserContext;
1019
import static com.capgemini.framework.playwright.PlaywrightFactory.getPage;
20+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
21+
import static org.junit.jupiter.api.Assertions.fail;
1122

1223
public final class ActionGui {
1324
@Step("Fill text field \"{fieldName}\" with \"{inputValue}\"")
1425
public static void fillTextBox(String fieldName, String inputValue, Locator locator) {
1526
locator.click();
1627
locator.fill(inputValue);
28+
AllureStepLogger.info(inputValue + " in textbox " + fieldName + " is typed");
1729
}
1830

1931
public static void fillTextBox(String fieldName, String inputValue, String selector) {
@@ -23,6 +35,7 @@ public static void fillTextBox(String fieldName, String inputValue, String selec
2335
@Step("Set radiobutton \"{fieldName}\"")
2436
public static void setRadioButton(String fieldName, Locator locator) {
2537
locator.click();
38+
AllureStepLogger.info(fieldName + " is selected");
2639
}
2740

2841
public static void setRadioButton(String fieldName, String selector) {
@@ -31,29 +44,111 @@ public static void setRadioButton(String fieldName, String selector) {
3144

3245
@Step("Click \"{fieldName}\"")
3346
public static void click(String fieldName, Locator locator) {
34-
locator.click();
47+
if(!locator.isVisible()){
48+
Fail.fail(fieldName + " is not visible and cannot be clicked.");
49+
}
50+
if(!locator.isEnabled()){
51+
Fail.fail(fieldName + " is not enabled and cannot be clicked.");
52+
}
53+
try {
54+
locator.click(new Locator.ClickOptions().setTimeout(20000));
55+
} catch (Exception e) {
56+
Logger.logError("Error while clicking on " + fieldName + ": " + e.getMessage());
57+
Fail.fail(fieldName + " cannot be clicked.");
58+
}
59+
AllureStepLogger.info(fieldName + " is clicked");
60+
}
61+
62+
public static void click(String fieldName, Locator locator, double timeout) {
63+
if(!locator.isVisible()){
64+
Fail.fail(fieldName + " is not visible and cannot be clicked.");
65+
}
66+
if(!locator.isEnabled()){
67+
Fail.fail(fieldName + " is not enabled and cannot be clicked.");
68+
}
69+
try {
70+
locator.click(new Locator.ClickOptions().setTimeout(timeout));
71+
} catch (Exception e) {
72+
Logger.logError("Error while clicking on " + fieldName + ": " + e.getMessage());
73+
Fail.fail(fieldName + " cannot be clicked. " + e.getMessage());
74+
}
75+
AllureStepLogger.info(fieldName + " is clicked");
76+
}
77+
78+
public static void click(String fieldName, Locator locator, boolean waitForPageLoadingToFinish) {
79+
click(fieldName, locator);
80+
if (waitForPageLoadingToFinish) {
81+
ActionGui.waitForPageLoadingFinish();
82+
}
3583
}
3684

3785
public static void pressEnter(Locator locator) {
3886
locator.press("Enter");
3987
}
40-
88+
@Step("Select value \"{value}\" in Dropdown \"{fieldName}\"")
89+
public static void selectDropdownValue(String value, String fieldName, Locator locator) {
90+
locator.click();
91+
locator.selectOption(value);
92+
AllureStepLogger.info(value + " in Dropdown " + fieldName + " is selected");
93+
}
4194
@Step("Verify {fieldName} is visible")
4295
public static void verifyElementVisible(String fieldName, Locator locator) {
43-
locator.isVisible();
96+
Assertions.assertThat(locator.isVisible()).as(fieldName + " visible").withFailMessage(fieldName + " is not visible").isTrue();
4497
}
4598

4699
public static void verifyElementVisible(String fieldName, String selector) {
47100
verifyElementVisible(fieldName, getPage().locator(selector));
48101
}
49-
102+
@Step("Wait for {fieldName} to disappear")
103+
public static void waitForElementToDisappear(String fieldName, Locator locator) {
104+
locator.waitFor(new Locator.WaitForOptions().setState(WaitForSelectorState.HIDDEN));
105+
}
106+
50107
@Step("Open page {url}")
51108
public static void navigate(String url, int pageLoadingTimeout) {
52109
getPage().navigate(url, new Page.NavigateOptions().setTimeout(pageLoadingTimeout));
53110
getPage().onLoad(p -> AllureStepLogger.info("Page loaded!"));
54111
}
55-
112+
@Step("Check {fieldName} checkbox")
113+
public static void checkCheckBox(String fieldName, Locator locator) {
114+
locator.check();
115+
AllureStepLogger.info(fieldName + " checkbox is checked");
116+
}
56117

118+
public static void clickIfVisible(String fieldName, Locator locator, boolean b) {
119+
if (locator.isVisible()) {
120+
click(fieldName, locator, b);
121+
}
122+
}
123+
124+
@Step("Check Banner has text {bannerText}")
125+
public static void checkBannerText(String bannerText, Locator locator) {
126+
AllureStepLogger.info("Banner text is: " + locator.textContent());
127+
assertThat(locator.textContent()).withFailMessage("Text on banner is " + locator.textContent() + " but it should be " + bannerText)
128+
.contains(bannerText);
129+
}
130+
131+
@Step("Get Banner text")
132+
public static String getBannerText() {
133+
Locator banner;
134+
try{ banner = getPage().locator("div[class*='PageControllerStatusLine']");}
135+
catch(Exception e){
136+
return "";
137+
};
138+
AllureStepLogger.info("Banner text is: " + banner.textContent());
139+
return banner.textContent();
140+
}
141+
@Step("Check that {element} has text {expectedText}")
142+
public static void verifyElementHasText(String element, String expectedText, Locator locator) {
143+
AllureStepLogger.info(element + " text is: " + locator.textContent());
144+
assertThat(locator.textContent()).withFailMessage("Text is " + locator.textContent() + " but it should be " + expectedText)
145+
.contains(expectedText);
146+
}
147+
148+
public static boolean isElementPresent(Locator locator) {
149+
return locator.isVisible();
150+
}
151+
57152
public void waitForPageToLoad() {
58153
getPage().waitForLoadState(LoadState.NETWORKIDLE);
59154
}
@@ -72,4 +167,68 @@ public static void waitMilliseconds(Integer milliseconds) {
72167
}
73168
}
74169

170+
@Step("Wait for page loading to finish")
171+
public static void waitForPageLoadingFinish(){
172+
String loadingAnimation = "div[id^='RadAjaxLoadingPanel']";
173+
waitForElementToDisappear("Loading animation", getPage().locator(loadingAnimation).first());
174+
//second version: getPage().waitForSelector(loadingAnimation).waitForElementState(ElementState.HIDDEN);
175+
}
176+
177+
178+
@Step("Check on column name {columnName} for first row text {searchText}")
179+
public static boolean isTextPresentInFirstRow(String columnName, String searchText) {
180+
int columnIndex = getColumnIndex(columnName);
181+
List<ElementHandle> rows = getPage().querySelectorAll("table tr");
182+
if (!rows.isEmpty()) {
183+
ElementHandle firstRow = rows.get(0);
184+
String cellText = firstRow.querySelectorAll("td span").get(columnIndex).textContent();
185+
return cellText.contains(searchText);
186+
} else {
187+
return false;
188+
}
189+
}
190+
191+
@Step("Find index for column name {columnName}")
192+
private static int getColumnIndex(String columnName) {
193+
List<ElementHandle> headers = getPage().querySelectorAll("table th a span");
194+
for (int i = 0; i < headers.size(); i++) {
195+
String headerText = headers.get(i).textContent();
196+
if (headerText.equals(columnName)) {
197+
return i;
198+
}
199+
}
200+
return -1;
201+
}
202+
203+
@Step("Create a dialog handler that will check message text and press OK/Cancel")
204+
public static void checkPopupMessageTextAndPressOKCancel(boolean pressOK, String messageText) {
205+
Consumer<Dialog> handler = dialog -> {
206+
Logger.logInfo("Popup message: " + dialog.message());
207+
Logger.logInfo("Popup message will be OK: " + pressOK);
208+
// Which option you want to click
209+
if (dialog.message().contains(messageText)) {
210+
if (pressOK) {
211+
// Click on button "OK"
212+
dialog.accept();
213+
Logger.logInfo("Clicked on 'OK'");
214+
} else {
215+
// Click on button "Cancel"
216+
dialog.dismiss();
217+
Logger.logInfo("Clicked on 'Cancel'");
218+
}
219+
}else {
220+
fail("Popup message is not as expected " + dialog.message() + " but it should be " + messageText);
221+
}
222+
};
223+
getPage().onDialog(handler);
224+
getPage().offDialog(handler);
225+
}
226+
@Step("Check that {fieldName} has text {expectedText}")
227+
public static void checkText(String fieldName, String expectedText, Locator locator) {
228+
assertThat(locator.textContent())
229+
.as(fieldName)
230+
.isEqualTo(expectedText);
231+
}
232+
233+
75234
}

0 commit comments

Comments
 (0)