-
-
Notifications
You must be signed in to change notification settings - Fork 2
Page
lzinga edited this page Apr 11, 2021
·
1 revision
To create a page you must create a class which implements IPage
and apply the
PageAttribute
to it. You can view an example of a page below or within the example project
included in the solution.
[Page("Login", "https://github.com/login")]
public class LoginPage : IPage
{
[FindWhere(Where.Name, "login")]
public IHtmlElement Username { get; set; }
[FindWhere(Where.Name, "password")]
public IHtmlElement Password { get; set; }
[FindWhere(Where.Name, "commit")]
public IHtmlElement Submit { get; set; }
// When the page is called to execute this is the process
// that will be executed.
public void Execute(IBrowser browser)
{
Username.SendKeys("<your username>");
Password.SendKeys("<your password>");
Submit.Click();
}
// When the page is complete this must return true before it
// continues to the next page (if executing many)
public bool Validate(IBrowser browser)
{
// Before moving to the next page, wait for the profile image to appear.
return browser.TryWaitFor(Where.Css,
"body > div.position-relative.js-header-wrapper > header > div.Header-item.position-relative.mr-0.d-none.d-md-flex > details > summary > img",
out IHtmlElement _);
}
}
PageAttribute
- Used to specify the pages metadata.
-
Name
: The friendly name of the page that will be loaded. -
Url
: The URL that will be navigated too when this page is executed. -
pageLoadTimeout
: The individual load time for this page, does not affect other pages.. (Defaults to PageCollectionOptions)
WaitForElementAttribute
- Applies to the Page class to wait for the specified element before executing. (Uses page timeout if specified)
-
Where
: The defining type of how the selection will be found. -
Value
: The query used for selecting the element. (For Example - XPath, CSS, Class, etc)
FindWhereAttribute
- Applies to Page properties to load the html element on page load.
When writing automation for a page things can get messy pretty quickly if the website has you jump around a lot. You can chain commands like in the example below.
browser.FindElement(Where.XPath, "//*[@id='sp_formfield_search']")
.SendKeys("TicketVM01")
.Wait(1000)
.ThenFindElement(Where.XPath, "//*[@id='Add']/div/span/div/div/div[2]/input[2]")
.Click();