Skip to content

Commit 2ea03b3

Browse files
add ChangeDataFormat.feature
1 parent 9a20e8f commit 2ea03b3

File tree

3 files changed

+72
-34
lines changed

3 files changed

+72
-34
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,56 @@
11
package pageobject;
22

3+
import org.openqa.selenium.JavascriptExecutor;
34
import org.openqa.selenium.WebElement;
45
import org.openqa.selenium.support.FindBy;
56

67
public class UserProfilePageObject extends BasePageObject {
78

8-
@FindBy(xpath = "//*[@id = 'mw-input-wppassword']")
9-
protected WebElement changePasswordButton;
9+
@FindBy(xpath = "//*[@type='submit']")
10+
protected WebElement submitButton;
1011

11-
@FindBy(xpath = "//*[@name='password']")
12-
protected WebElement passwordElement;
12+
@FindBy(id = "mw-prefsection-rendering-dateformat")
13+
protected WebElement dateFormatElement;
1314

14-
@FindBy(xpath = "//*[@name='retype']")
15-
protected WebElement retypePasswordElement;
15+
@FindBy(id = "ooui-php-497")
16+
protected WebElement appearanceButton;
1617

17-
@FindBy(xpath = "//*[@type='submit']")
18-
protected WebElement changeCredentialButton;
18+
@FindBy(xpath = "//*[@class='mw-notification-content']")
19+
protected WebElement notificationElement;
20+
21+
@FindBy(xpath = "//label[@for='ooui-php-84']")
22+
protected WebElement oldDataFormatElement;
23+
24+
@FindBy(xpath = "//label[@for='ooui-php-85']")
25+
protected WebElement newDataFormatElement;
1926

2027
public UserProfilePageObject(DriverHolder driverHolder) {
2128
super(driverHolder.getDriver());
2229
}
2330

24-
public void setUserNewPassword(String userPassword) {
25-
waitForVisibility(passwordElement);
26-
passwordElement.clear();
27-
passwordElement.sendKeys(userPassword);
31+
public void clickAppearanceButton() {
32+
waitForVisibility(appearanceButton).click();
33+
}
34+
35+
public void chooseNewDataFormat() {
36+
waitForVisibility(newDataFormatElement).click();
37+
}
38+
39+
public boolean isNotificationDisplayed() {
40+
return waitForVisibility(notificationElement).isDisplayed();
2841
}
2942

30-
public void retypeUserPassword(String userPassword) {
31-
waitForVisibility(retypePasswordElement);
32-
retypePasswordElement.clear();
33-
retypePasswordElement.sendKeys(userPassword);
43+
public void clickSubmitButton() {
44+
waitForVisibility(submitButton).click();
3445
}
3546

36-
public void clickChangePasswordButton() {
37-
waitForVisibility(changePasswordButton);
38-
changePasswordButton.click();
47+
public void scrollToDataFormat() {
48+
JavascriptExecutor jsExecutor = (JavascriptExecutor) getDriver();
49+
jsExecutor.executeScript("arguments[0].scrollIntoView(true);", dateFormatElement);
3950
}
4051

41-
public void clickChangeCredentialButton() {
42-
waitForVisibility(changeCredentialButton);
43-
changeCredentialButton.click();
52+
public void chooseOldDataFormat() {
53+
waitForVisibility(oldDataFormatElement).click();
4454
}
4555

4656
}

src/test/java/steps/UserProfilePageStepDefinition.java

+29-12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pageobject.UserProfilePageObject;
66

77
import static org.junit.Assert.assertEquals;
8+
import static org.junit.Assert.assertTrue;
89

910
public class UserProfilePageStepDefinition {
1011
private final UserProfilePageObject userProfilePageObject;
@@ -13,25 +14,41 @@ public UserProfilePageStepDefinition(UserProfilePageObject userProfilePageObject
1314
this.userProfilePageObject = userProfilePageObject;
1415
}
1516

16-
@And("the user selects the option to change password")
17-
public void theUserSelectsTheOptionToChangePassword() {
18-
userProfilePageObject.clickChangePasswordButton();
17+
@Then("the user should be on the Preferences page")
18+
public void theUserShouldBeOnThePreferencesPage() {
19+
String expectedURL = "https://en.wikipedia.org/wiki/Special:Preferences";
20+
assertEquals("This is not a Preferences page", expectedURL, userProfilePageObject.getCurrentUrl());
1921
}
2022

21-
@And("set newPassword and retype newPassword")
22-
public void setNewPasswordAndRetypeNewPassword() {
23-
userProfilePageObject.setUserNewPassword("qwerty12a");
24-
userProfilePageObject.retypeUserPassword("qwerty12a");
23+
@And("the user navigates to the Appearance page")
24+
public void theUserNavigatesToTheAppearancePage() {
25+
userProfilePageObject.clickAppearanceButton();
26+
}
27+
28+
@And("the user choose new date format")
29+
public void theUserChooseNewDateFormat() {
30+
userProfilePageObject.chooseNewDataFormat();
2531
}
2632

2733
@And("saves the changes")
2834
public void savesTheChanges() {
29-
userProfilePageObject.clickChangeCredentialButton();
35+
userProfilePageObject.clickSubmitButton();
3036
}
3137

32-
@Then("the user should be on the Preferences page")
33-
public void theUserShouldBeOnThePreferencesPage() {
34-
String expectedURL = "https://en.wikipedia.org/wiki/Special:Preferences";
35-
assertEquals("This is not a Preferences page", expectedURL, userProfilePageObject.getCurrentUrl());
38+
@Then("the user should see a notification that the changes are saved")
39+
public void theUserShouldSeeANotificationThatTheChangesAreSaved() {
40+
assertTrue("Notification 'Your preferences have been saved.' is not displayed", userProfilePageObject.isNotificationDisplayed());
41+
}
42+
43+
@And("the user scrolls down to the Date format")
44+
public void theUserScrollsDownToTheDateFormat() {
45+
userProfilePageObject.scrollToDataFormat();
46+
}
47+
48+
@And("the user should choose and save old date format")
49+
public void theUserShouldChooseAndSaveOldDateFormat() {
50+
userProfilePageObject.scrollToDataFormat();
51+
userProfilePageObject.chooseOldDataFormat();
52+
userProfilePageObject.clickSubmitButton();
3653
}
3754
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Feature: Change date format in Wikipedia Account
2+
3+
Scenario: User can change their date format in Wikipedia account
4+
Given the user is logged in to their account
5+
When the user opens the account preference
6+
And the user navigates to the Appearance page
7+
And the user scrolls down to the Date format
8+
And the user choose new date format
9+
And saves the changes
10+
Then the user should see a notification that the changes are saved
11+
And the user should choose and save old date format

0 commit comments

Comments
 (0)