Commit d22657f8 authored by hasan  khaddour's avatar hasan khaddour

lab 23 code

parent 0f0d5971
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System;
namespace Dummy.SeleniumTests.SigninTets.Pages
{
public class SigninPage
{
private IWebDriver _driver;
private WebDriverWait _wait;
//Locators ( UI Elements)
private By usernameField = By.Id("email");
private By passwordField = By.Id("password");
private By loginButton = By.Id("login-btn");
public SigninPage(IWebDriver driver)
{
_driver = driver;
_wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(10));
}
public void EnterUserName(string username)
{
var usernameF = _wait.Until(d => d.FindElement(usernameField));
usernameF.SendKeys(username);
}
public void EnterPassword(string pass)
{
var passwordF = _wait.Until(d => d.FindElement(passwordField));
passwordF.SendKeys(pass);
}
public void Submit()
{
var submitButton = _wait.Until(d => d.FindElement(loginButton));
submitButton.Click();
}
}
}
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System;
namespace Dummy.SeleniumTests.SigninTets.Pages
{
public class StorePage
{
private IWebDriver _driver;
private WebDriverWait _wait;
//Locators ( UI Elements)
private By totalCost = By.Id("cart_total_price");
private By gst = By.Id("cart_total_sales_tax");
public String firstItemFee = "//*[@id=\"store_cart_products\"]/tbody/tr[1]/td[3]";
public String secondItemFee = "//*[@id=\"store_cart_products\"]/tbody/tr[2]/td[3]";
private String itemQuantity = "quantity-";
private String itemAddButton = "add_service_";
public int FirstItemCode()
{
return 41;
}
public int SecondItemCode()
{
return 33;
}
public StorePage(IWebDriver driver)
{
_driver = driver;
_wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(10));
}
public void SetItemQuantity(int quantity,int code )
{
var selectList =_wait.Until(d => d.FindElement(By.Id(itemQuantity + code)));
selectList.SendKeys(""+quantity);
}
public void SetFirstItemQuantity(int quantity)
{
SetItemQuantity(quantity,SecondItemCode());
}
public void SetSecondItemQuantity(int quantity)
{
SetItemQuantity(quantity, FirstItemCode());
}
public void AddItem(int code)
{
var addButton= _wait.Until(d => d.FindElement(By.Id(itemAddButton + code)));
addButton.Click();
}
public int calculateFee(string feeXPath,int quantity)
{
int fee= GetFee(feeXPath);
return (quantity * (fee))/10;
}
public string GetGSt()
{
var gstAmount= _wait.Until(d => d.FindElement(gst));
return gstAmount.Text;
}
public int GetFee(String feeXPath )
{
var fee = _wait.Until(d => d.FindElement(By.XPath(feeXPath)));
return Int32.Parse(fee.Text.Split("$")[2]) ;
}
public string GetTotal()
{
var totalAmount = _wait.Until(d => d.FindElement(totalCost));
return totalAmount.Text;
}
}
}
using Dummy.SeleniumTests.SigninTets.Pages;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dummy.SeleniumTests.SigninTets.Tests
{
public class SigninTest
{
public SigninPage _siginPage;
private IWebDriver _driver;
//
public String HostName = "https://whenwise.agileway.net/sign-in";
[SetUp]
public void SetUp()
{
_driver = new ChromeDriver();
_driver.Navigate().GoToUrl(HostName);
_siginPage = new SigninPage(_driver);
}
[Test]
public void TestValidLogin()
{
_siginPage.EnterUserName("james@client.com");
_siginPage.EnterPassword("test01");
_siginPage.Submit();
Assert.IsTrue(_driver.Title.Contains("WhenWise"));
_driver.Quit();
}
[TearDown]
public void TearDown()
{
}
}
}
using Dummy.SeleniumTests.SigninTets.Pages;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
namespace Dummy.SeleniumTests.SigninTets.Tests
{
public class StoreTest
{
public StorePage _storePage;
public SigninPage _siginPage;
private IWebDriver _driver;
//
public String HostName = "https://whenwise.agileway.net/biz/wise-pool/store";
public String LoginHostName = "https://whenwise.agileway.net/sign-in";
[SetUp]
public void SetUp()
{
_driver = new ChromeDriver();
_driver.Navigate().GoToUrl(LoginHostName);
_siginPage = new SigninPage(_driver);
_siginPage.EnterUserName("james@client.com");
_siginPage.EnterPassword("test01");
_siginPage.Submit();
_driver.Navigate().GoToUrl(HostName);
_storePage = new StorePage(_driver);
}
[Test]
public void TestCartStore()
{
int qty = 10;
int fcode=_storePage.FirstItemCode();
_storePage.SetItemQuantity(qty,fcode);
_storePage.AddItem(fcode);
int tfee = _storePage.calculateFee(_storePage.firstItemFee, 10);
int itemPrice = _storePage.GetFee(_storePage.firstItemFee);
string actualTotal = _storePage.GetTotal();
string actualGST = _storePage.GetGSt();
Assert.IsTrue(actualGST.Equals("A$"+tfee+".00"));
Assert.IsTrue(actualTotal.Equals("A$"+tfee+qty*itemPrice+".00"));
}
[TearDown]
public void TearDown()
{
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment