public abstract class AbstractMainPage protected static string titleXP

  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
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
public abstract class AbstractMainPage
{
protected static string titleXPath = "//h1";
protected static string languageSelectXPath = "//select[@name='culture']";
protected static IWebDriver driver;
protected IWebElement headerElement;
protected IWebElement languageSelectElement;
public AbstractMainPage(IWebDriver driverArg)
{
driver = driverArg;
Init();
}
public AbstractMainPage()
{
Init();
}
private void Init()
{
headerElement = driver.FindElement(By.XPath(titleXPath));
}
public string PageHeader
{
get
{
return headerElement.Text;
}
}
}
public class MainPage : AbstractMainPage
{
private const string candidateSelfServiceURL = "http://sp13clean2:4441/";
private const string login = "AutoTest";
private static string logInButtonXPath = "//a[text()='Log in']";
private static string registerButtonXPath = "//a[text()='Register']";
private IWebElement logInButtonElement;
private IWebElement registerButtonElement;
public static MainPage Open(IWebDriver driverArg)
{
driverArg.Url = candidateSelfServiceURL;
MainPage mainPage = new MainPage(driverArg)
{
logInButtonElement = driver.FindElement(By.XPath(logInButtonXPath)),
registerButtonElement = driver.FindElement(By.XPath(registerButtonXPath))
};
return new MainPage(driverArg);
}
internal static MainPage Init(IWebDriver driverArg)
{
//TODO: catch alert
return new MainPage(driverArg);
throw new NotImplementedException();
}
protected MainPage(IWebDriver driverArg) : base(driverArg)
{
}
public LogInPage LogInButtonClick()
{
logInButtonElement.Click();
LogInPage logInPage = LogInPage.Init();
return logInPage;
}
}
public class LogInPage : AbstractMainPage
{
private static string eMailInputId = "Email";
private static string passwordInputId = "Password";
private static string logInButtonXPath = "//button[@type='submit']";
private static string rememberMeCheckBoxId = "RememberMe";
private static string labelXpath = "//h4";
private static readonly string labelText = "Use a local account to log in.";
private IWebElement labelElement;
private IWebElement eMailInputElement;
private IWebElement passwordInputElement;
private IWebElement logInButtonElement;
private IWebElement rememberMeCheckBoxElement;
private LogInPage() : base()
{
labelElement = driver.FindElement(By.XPath(labelXpath));
eMailInputElement = driver.FindElement(By.Id(eMailInputId));
passwordInputElement = driver.FindElement(By.Id(passwordInputId));
logInButtonElement = driver.FindElement(By.XPath(logInButtonXPath));
rememberMeCheckBoxElement = driver.FindElement(By.Id(rememberMeCheckBoxId));
}
public static LogInPage Init()
{
return new LogInPage();
}
public string Email
{
set
{
eMailInputElement.Clear();
eMailInputElement.SendKeys(value);
}
get
{
return eMailInputElement.Text;
}
}
public string Password
{
set
{
passwordInputElement.Clear();
passwordInputElement.SendKeys(value);
}
get
{
return passwordInputElement.Text;
}
}
public MainPage LogInSubmit()
{
logInButtonElement.Click();
MainPage mainPage = MainPage.Init(driver);
return mainPage;
}
}