120 lines
4.2 KiB
C#
120 lines
4.2 KiB
C#
|
using OpenQA.Selenium.Chrome;
|
|||
|
using OpenQA.Selenium.Support.UI;
|
|||
|
using OpenQA.Selenium;
|
|||
|
using SeleniumExtras.WaitHelpers;
|
|||
|
|
|||
|
namespace TestProject
|
|||
|
{
|
|||
|
[TestFixture]
|
|||
|
public class HomePageTests
|
|||
|
{
|
|||
|
private IWebDriver driver;
|
|||
|
|
|||
|
[SetUp]
|
|||
|
public void Setup()
|
|||
|
{
|
|||
|
ChromeOptions options = new ChromeOptions();
|
|||
|
driver = new ChromeDriver(options);
|
|||
|
driver.Manage().Window.Maximize();
|
|||
|
}
|
|||
|
|
|||
|
[TearDown]
|
|||
|
public void Teardown()
|
|||
|
{
|
|||
|
driver.Quit();
|
|||
|
driver.Dispose();
|
|||
|
}
|
|||
|
|
|||
|
[Test, Order(1)]
|
|||
|
public void TestAuth()
|
|||
|
{
|
|||
|
HomePage homePage = new HomePage(driver);
|
|||
|
homePage.Open();
|
|||
|
homePage.Auth("<22><><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
|
|||
|
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(100));
|
|||
|
var profileButton = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//button[contains(@class, 'button___BfISQ')]//div[contains(@class, 'text___lAaAj') and contains(text(), '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')]")));
|
|||
|
|
|||
|
Assert.That(profileButton.Displayed, Is.True);
|
|||
|
}
|
|||
|
|
|||
|
[Test, Order(2)]
|
|||
|
public void TestSearchProduct_positive()
|
|||
|
{
|
|||
|
HomePage homePage = new HomePage(driver);
|
|||
|
homePage.Open();
|
|||
|
homePage.SearchForProduct("<22><><EFBFBD><EFBFBD>");
|
|||
|
|
|||
|
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
|
|||
|
var firstProduct = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//div[contains(@class, 'name___asFfu')]")));
|
|||
|
|
|||
|
Assert.That(firstProduct.Displayed, Is.True);
|
|||
|
}
|
|||
|
|
|||
|
[Test, Order(3)]
|
|||
|
public void TestSearchProduct_negative()
|
|||
|
{
|
|||
|
HomePage homePage = new HomePage(driver);
|
|||
|
homePage.Open();
|
|||
|
homePage.SearchForProduct("<22><><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
|
|||
|
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
|
|||
|
var noResultsMessage = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//div[contains(text(), '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')]")));
|
|||
|
|
|||
|
Assert.That(noResultsMessage.Displayed, Is.True);
|
|||
|
}
|
|||
|
|
|||
|
[Test, Order(4)]
|
|||
|
public void TestSortByPriceAscending()
|
|||
|
{
|
|||
|
HomePage homePage = new HomePage(driver);
|
|||
|
homePage.Open();
|
|||
|
homePage.SearchForProduct("<22><><EFBFBD><EFBFBD>");
|
|||
|
|
|||
|
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
|
|||
|
homePage.SortByPriceAscending();
|
|||
|
|
|||
|
var firstProductPrice = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//a[contains(@href, '/s.origPrice.asc')]")));
|
|||
|
|
|||
|
Assert.That(firstProductPrice.Text.Contains("<22><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>"), Is.True);
|
|||
|
}
|
|||
|
|
|||
|
[Test, Order(5)]
|
|||
|
public void TestFilterByPrice()
|
|||
|
{
|
|||
|
HomePage homePage = new HomePage(driver);
|
|||
|
homePage.Open();
|
|||
|
homePage.SearchForProduct("<22><><EFBFBD><EFBFBD>");
|
|||
|
|
|||
|
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
|
|||
|
homePage.FilterByPrice(100, 200);
|
|||
|
|
|||
|
var priceRangeMessage = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//input[@name='min']")));
|
|||
|
|
|||
|
Assert.That(priceRangeMessage.Displayed, Is.True);
|
|||
|
}
|
|||
|
|
|||
|
[Test, Order(6)]
|
|||
|
public void TestAddToFavorites()
|
|||
|
{
|
|||
|
HomePage homePage = new HomePage(driver);
|
|||
|
homePage.Open();
|
|||
|
homePage.Auth("<22><><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
Thread.Sleep(5000);
|
|||
|
homePage.SearchForProduct("25 <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
|
|||
|
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
|
|||
|
|
|||
|
var heartButton = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//div[@class='actionButton___tq_Iy active___Rc9Go']//div[contains(@class, 'favoriteButton___z3oh3')]")));
|
|||
|
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", heartButton);
|
|||
|
|
|||
|
heartButton.Click();
|
|||
|
|
|||
|
var favoriteItem = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//div[contains(@class, 'product___F_mly withFavorite___BnFAs product___crBKK')]")));
|
|||
|
|
|||
|
Assert.That(favoriteItem.Displayed, Is.True);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|