private IWebDriver ChromeDriver()
{
//Get the name of the directory of the location of the executable;
var outPutDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
//Return a new ChromeDriver with the path to the ChromeDriver that we have now: the binary;
return new ChromeDriver(outPutDirectory);
}
(2)Download chromedriver.exe, add it and modify its property to "Copy if newer".
(3)Add a new class named "LoginPage", and in this class define driver because we are going to use this driver to open this page.
public LoginPage(IWebDriver driver)
{
Driver = driver;
}
public IWebDriver Driver { get; }
(4)Build it and it passes, but currently it does nothing, so we need to pass parameters in LoginPage() method in LoginPage.cs so that we can open this page:
Then build it. Now we can open the page that we are going to test.
Step two: Writing Test_1: to validate that users are able to login successfully using the correct info.
First we need to write the skeleton of the Test_1;
Write it in plain english from users/a tester's perspective.
we will pass a "userinfo" as parameter into InputUserInfoAndLogin() because we've already have that knowledge that we can set a class to store our user's properties: EmaliAddress and Password.
Of course, it complains, now we proceed to refactor it.
(1)Creat a method called InputUserInfoAndLogin() and pass "TestUser User" as its parameter. TesterUser is a class that stores two properties as we said before.
(2)TestUser complains so we create TestUser.class file.
(3)Add two properties in TestUser.cs:EmailAddress PassWord;
public string EmailAddress { get; set; }
public string PassWord { get; set; }
(4)Modify InputUserInfoAndLogin() in Loginpage.cs,set the properties of three elements that we are going to locate on LoginPage:
public IWebElement EmailAddress => Driver.FindElement(By.XPath("//*[@type='text']"));
public IWebElement PassWord => Driver.FindElement(By.XPath("//*[@type='password']"));
public IWebElement LoginButton => Driver.FindElement(By.XPath("//*[@class=''mat-raised-button mat-button-base mat-warn'']"));
Then use these 3 properties in InputUserInfoAndLogin().
Step Three: Writing Test_0_noInput: to validate given no input the page will give alert in each field.
(1) Write skeleton of this Test_0_noInput():
var driver = ChromeDriver();
LoginPage loginPage = new LoginPage(driver);
loginPage.Open();
Thread.Sleep(1000);
loginPage.NoInput();
Assert.IsTrue(loginPage.AlertforEmailAddress.Text.Contains("You Must Enter A Value."));
Assert.IsTrue(loginPage.AlertforPassword.Text.Contains("You Must Enter A Value."));
Assert.IsFalse(loginPage.LoginButton.Enabled);
(2) Create NoInput() in LoginPage.cs:
internal void NoInput()
{
Actions actionsObj = new Actions(Driver);
//Move the cursor From the user account to password field
actionsObj.Click(EmailAddress).Perform();
actionsObj.Click(PassWord).Perform();
actionsObj.Click(EmailAddress).Perform();
}
(3) Create AlertforEmailAddress and AlertforPassword for Assertion on LoginPage.cs:
public IWebElement AlertforEmailAddress => Driver.FindElement(By.XPath("//**id='mat-error-0']"));
public IWebElement AlertforPassword => Driver.FindElement(By.XPath("//**[@id='mat-error-1']"));
After days of self-learning online. I started the automation framework two days ago.
Step One: Prestep for LoginTests(to validate login functionality)
Setup ChromeDriver and open the website that we are going to test.
Pass driver into LoginPage() then create LoginPage.cs.
Download ChromeDriver.exe, add it into our solution and set the property to be "Copy if newer"
Set driver in LoginPage.cs:
Create a new UnitTest Project.
Correct each complaining step by step:
(1)Add ChromeDriver() in Test_1.cs and header files.
build it, but it does nothing, only open chrome browser, so we need to set open():
Build it.
(2)Download chromedriver.exe, add it and modify its property to "Copy if newer".
(3)Add a new class named "LoginPage", and in this class define driver because we are going to use this driver to open this page.
(4)Build it and it passes, but currently it does nothing, so we need to pass parameters in LoginPage() method in LoginPage.cs so that we can open this page:
Then we define open(), lets do like this:
Then build it. Now we can open the page that we are going to test.
Step two: Writing Test_1: to validate that users are able to login successfully using the correct info.
First we need to write the skeleton of the Test_1; Write it in plain english from users/a tester's perspective.
we will pass a "userinfo" as parameter into InputUserInfoAndLogin() because we've already have that knowledge that we can set a class to store our user's properties: EmaliAddress and Password.
Of course, it complains, now we proceed to refactor it.
(1)Creat a method called InputUserInfoAndLogin() and pass "TestUser User" as its parameter. TesterUser is a class that stores two properties as we said before.
(2)TestUser complains so we create TestUser.class file.
(3)Add two properties in TestUser.cs:EmailAddress PassWord;
(4)Modify InputUserInfoAndLogin() in Loginpage.cs,set the properties of three elements that we are going to locate on LoginPage:
Then use these 3 properties in InputUserInfoAndLogin().
Step Three: Writing Test_0_noInput: to validate given no input the page will give alert in each field.
(1) Write skeleton of this Test_0_noInput():
(2) Create NoInput() in LoginPage.cs:
(3) Create AlertforEmailAddress and AlertforPassword for Assertion on LoginPage.cs: