From 59b82ad9ca1a52d377a97116fadda36b19630fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Sat, 15 Feb 2025 19:42:01 +0400 Subject: [PATCH] Process.. --- Testing/TestProject/BasePage.cs | 45 ++++++++++ Testing/TestProject/HomePage.cs | 81 +++++++++++++++++ Testing/TestProject/TestProject.csproj | 27 ++++++ Testing/TestProject/UnitTest.cs | 120 +++++++++++++++++++++++++ Testing/Testing.sln | 25 ++++++ 5 files changed, 298 insertions(+) create mode 100644 Testing/TestProject/BasePage.cs create mode 100644 Testing/TestProject/HomePage.cs create mode 100644 Testing/TestProject/TestProject.csproj create mode 100644 Testing/TestProject/UnitTest.cs create mode 100644 Testing/Testing.sln diff --git a/Testing/TestProject/BasePage.cs b/Testing/TestProject/BasePage.cs new file mode 100644 index 0000000..3317aeb --- /dev/null +++ b/Testing/TestProject/BasePage.cs @@ -0,0 +1,45 @@ +using OpenQA.Selenium.Support.UI; +using OpenQA.Selenium; +using SeleniumExtras.WaitHelpers; + +namespace TestProject +{ + public class BasePage + { + protected IWebDriver driver; + + public BasePage(IWebDriver driver) + { + this.driver = driver; + } + + public IWebElement FindElement(By locator) + { + return driver.FindElement(locator); + } + + public void Type(By locator, string text) + { + WaitUntilElementIsVisible(locator); + FindElement(locator).Clear(); + FindElement(locator).SendKeys(text); + } + + public void Click(By locator) + { + WaitUntilElementIsVisible(locator); + FindElement(locator).Click(); + } + + public void WaitUntilElementIsVisible(By locator, int time = 100) + { + WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(time)); + wait.Until(ExpectedConditions.ElementIsVisible(locator)); + } + + public void OpenUrl(string url) + { + driver.Navigate().GoToUrl(url); + } + } +} diff --git a/Testing/TestProject/HomePage.cs b/Testing/TestProject/HomePage.cs new file mode 100644 index 0000000..469e5db --- /dev/null +++ b/Testing/TestProject/HomePage.cs @@ -0,0 +1,81 @@ +using OpenQA.Selenium; + +namespace TestProject +{ + public class HomePage : BasePage + { + private By AuthLink = By.XPath("//a[@href='/ru/entrance']"); + private By showMoreButton = By.XPath("//button[contains(@class, 'button___xFkMg') and contains(., 'Показать еще варианты')]"); + private By emailAuthButton = By.XPath("//div[contains(@class, 'normal___w8_y9')]//a[contains(@href, '/ru/entrance/signin')]"); + private By emailInput = By.XPath("//input[@name='email']"); + private By passwordInput = By.XPath("//input[@name='password']"); + private By submitButton = By.XPath("//button[@type='submit']//div[contains(@class, 'caption___L78vz') and contains(., 'Войти')]"); + + private By searchInput = By.ClassName("input___OsSf0"); + private By searchButton = By.ClassName("submitButton___iZDz3"); + + private By sortButton = By.XPath("//button[contains(@class, 'content___hcPVc') and contains(., 'Cортировка')]"); + private By sortByPriceAscending = By.XPath("//a[contains(@href, '/s.origPrice.asc')]"); + + private By filterButton = By.XPath("//button[contains(@class, 'content___hcPVc') and contains(., 'Цена')]"); + private By minPriceInput = By.XPath("//input[@name='min']"); + private By maxPriceInput = By.XPath("//input[@name='max']"); + private By applyFilterButton = By.XPath("//button[contains(@class, 'button___HN4kv') and contains(., 'Применить')]"); + + private By productLink = By.XPath("//a[contains(@href, '/ru/products/645ba6bfc5f80701f93cead6')]"); + private By addToCartButton = By.XPath("//button[.//span[contains(text(), 'Ð’ корзину')]]"); + private By cartButton = By.XPath("//a[@href='/ru/cart']"); + + private By heartButton = By.XPath("//div[@class='actionButton___tq_Iy active___Rc9Go']//div[contains(@class, 'favoriteButton___z3oh3')]"); + private By profileButton = By.XPath("//button[contains(@class, 'button___BfISQ')]//div[contains(@class, 'text___lAaAj') and contains(text(), 'Профиль')]"); + private By favoritesLink = By.XPath("//a[contains(@class, 'item___tZDUe clickable___Yuycq largeText___H5mAO') and contains(text(), 'Мое избранное')]"); + + public HomePage(IWebDriver driver) : base(driver) { } + + public void Auth(string email, string password) + { + Click(AuthLink); + Click(showMoreButton); + Click(emailAuthButton); + Type(emailInput, email); + Type(passwordInput, password); + Click(submitButton); + } + + public void Open() + { + OpenUrl("https://www.joom.ru/"); + } + + public void SearchForProduct(string productName) + { + Type(searchInput, productName); + Click(searchButton); + } + + public void SortByPriceAscending() + { + Click(sortButton); + + Click(sortByPriceAscending); + } + + public void FilterByPrice(int minPrice, int maxPrice) + { + Click(filterButton); + + Type(minPriceInput, minPrice.ToString()); + + Type(maxPriceInput, maxPrice.ToString()); + + Click(applyFilterButton); + } + + public void AddToFavorites() + { + Click(heartButton); + Click(profileButton); + Click(favoritesLink); + } + } +} diff --git a/Testing/TestProject/TestProject.csproj b/Testing/TestProject/TestProject.csproj new file mode 100644 index 0000000..578887d --- /dev/null +++ b/Testing/TestProject/TestProject.csproj @@ -0,0 +1,27 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + + + + + diff --git a/Testing/TestProject/UnitTest.cs b/Testing/TestProject/UnitTest.cs new file mode 100644 index 0000000..bbb46a5 --- /dev/null +++ b/Testing/TestProject/UnitTest.cs @@ -0,0 +1,120 @@ +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("ÏÎ×ÒÀ", "ÏÀÐÎËÜ"); + + 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(), 'Ïðîôèëü')]"))); + + Assert.That(profileButton.Displayed, Is.True); + } + + [Test, Order(2)] + public void TestSearchProduct_positive() + { + HomePage homePage = new HomePage(driver); + homePage.Open(); + homePage.SearchForProduct("÷àñû"); + + 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("àáâãä"); + + WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); + var noResultsMessage = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//div[contains(text(), 'Íè÷åãî íå íàéäåíî')]"))); + + Assert.That(noResultsMessage.Displayed, Is.True); + } + + [Test, Order(4)] + public void TestSortByPriceAscending() + { + HomePage homePage = new HomePage(driver); + homePage.Open(); + homePage.SearchForProduct("÷àñû"); + + 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("Ïî âîçðàñòàþùåé öåíå"), Is.True); + } + + [Test, Order(5)] + public void TestFilterByPrice() + { + HomePage homePage = new HomePage(driver); + homePage.Open(); + homePage.SearchForProduct("÷àñû"); + + 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("ÏÎ×ÒÀ", "ÏÀÐÎËÜ"); + Thread.Sleep(5000); + homePage.SearchForProduct("25 èãë èç íåðæàâåþùåé ñòàëè ñ áîëüøèì óøêîì äëÿ âûøèâàíèÿ"); + + 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); + } + + + } +} \ No newline at end of file diff --git a/Testing/Testing.sln b/Testing/Testing.sln new file mode 100644 index 0000000..b283e46 --- /dev/null +++ b/Testing/Testing.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.35122.118 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestProject", "TestProject\TestProject.csproj", "{C7A43A5A-5BA8-424B-A65D-2BAECE562BE2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C7A43A5A-5BA8-424B-A65D-2BAECE562BE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C7A43A5A-5BA8-424B-A65D-2BAECE562BE2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C7A43A5A-5BA8-424B-A65D-2BAECE562BE2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C7A43A5A-5BA8-424B-A65D-2BAECE562BE2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3376F0E6-C924-407A-BF66-359FAC01061B} + EndGlobalSection +EndGlobal