-
Notifications
You must be signed in to change notification settings - Fork 0
/
Login_page.txt
85 lines (63 loc) · 1.96 KB
/
Login_page.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import utility.BaseUtil;
public class Login_page extends BaseUtil{
/**
*
* Page Object Model(POM)- is an object oriented programming function
*
* Pros of POM
* -maintanability
* -readability
* -reusability
*
* -Pages
* -login page
* -home page
* -order page
*
* -Tests
* -login tests
* -homepage tests
* -order test
*/
WebDriver driver;
// then create a constructor
private BaseUtil base;
public Login_page(BaseUtil base) {
this.base = base;
}
public Login_page(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}
// WebElement for Login page(page objects)
// @FindBy(id="user-name")
// WebElement usernameField;
// @FindBy(name="password")
// WebElement passwordField;
// @FindBy(xpath="//input[@id='login-button']")
// WebElement loginButton;
By usernameField = By.id("user-name");
By passwordField = By.name("password");
By loginButton = By.xpath("//input[@id='login-button']");
// then create a method(always give your method a good name)
public void enterUsername(String username) {
base.driver.findElement(usernameField).sendKeys(username);
}
public void enterPassword(String password) {
base.driver.findElement(passwordField).sendKeys(password);
}
public void clickOnLoginButton() {
base.driver.findElement(loginButton).click();
}
public void loginTowebsite (String username, String password) {
base.driver.findElement(usernameField).sendKeys(username);
base.driver.findElement(passwordField).sendKeys(password);
base.driver.findElement(loginButton).click();
}
}