Process..

This commit is contained in:
Вячеслав Иванов 2025-02-15 19:42:01 +04:00
parent 684cffa840
commit 59b82ad9ca
5 changed files with 298 additions and 0 deletions

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Selenium.Support" Version="4.28.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.28.0" />
<PackageReference Include="SeleniumExtras.WaitHelpers" Version="1.0.2" />
</ItemGroup>
<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>
</Project>

View File

@ -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);
}
}
}

25
Testing/Testing.sln Normal file
View File

@ -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