Добавил несколько тестов.

parent 2e424701
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace PhoneStore.Tests.Helpers
{
public class BasicSteps : IDisposable
{
private readonly IWebDriver _driver;
private const string MainUrl = "http://localhost:5000";
private const string LoginUrl = MainUrl + "/Account/Login";
private const string RegisterUrl = MainUrl + "/Account/Register";
public BasicSteps()
{
_driver = new ChromeDriver();
}
public void Dispose()
{
_driver.Quit();
_driver.Close();
}
public bool IsElementFound(string text)
{
var element = _driver.FindElement(By.XPath($"//*[contains(text(), '{text}')]"));
return element != null;
}
public void GoToUrl(string url)
{
_driver.Navigate().GoToUrl(url);
}
public void GoToMainPage()
{
GoToUrl(MainUrl);
}
public void GoToLoginPage()
{
GoToUrl(LoginUrl);
}
public void GoToRegisterPage()
{
GoToUrl(RegisterUrl);
}
public void ClickButtonById(string id)
{
_driver.FindElement(By.Id(id)).Click();
}
public void FillFormField(string fieldId, string text)
{
var field = _driver.FindElement(By.Id(fieldId));
field.SendKeys(text);
}
}
}
\ No newline at end of file
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
<PackageReference Include="FluentAssertions" Version="5.10.3" /> <PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.17" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.17" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.5.1" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="106.0.5249.6100" />
<PackageReference Include="xunit" Version="2.4.1" /> <PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
......
using FluentAssertions;
using PhoneStore.Tests.Helpers;
using Xunit;
namespace PhoneStore.Tests.Selenium
{
public class AuthTests
{
private readonly BasicSteps _basicSteps;
public AuthTests()
{
_basicSteps = new BasicSteps();
}
[Fact]
public void LoginWrongModelData_Returns_ErrorMessage()
{
_basicSteps.GoToLoginPage();
_basicSteps.IsElementFound("Вход в приложение").Should().BeTrue();
_basicSteps.FillFormField("email", "admin@admin.com");
_basicSteps.FillFormField("password", "test");
_basicSteps.ClickButtonById("submit");
_basicSteps.IsElementFound("Неправильный логин и (или) пароль").Should().BeTrue();
}
[Fact]
public void Login_Returns_Page_With_Smartphone_List()
{
_basicSteps.GoToLoginPage();
_basicSteps.IsElementFound("Вход в приложение").Should().BeTrue();
_basicSteps.FillFormField("email", "admin@admin.com");
_basicSteps.FillFormField("password", "Admin1234@");
_basicSteps.ClickButtonById("submit");
_basicSteps.IsElementFound("Смартфоны - PhoneStore").Should().BeTrue();
}
[Fact]
public void Registration_Returns_Page_With_Smartphone_List()
{
_basicSteps.GoToRegisterPage();
_basicSteps.IsElementFound("Регистрация нового пользователя").Should().BeTrue();
_basicSteps.FillFormField("email", "test@test.com");
_basicSteps.FillFormField("age", "45");
_basicSteps.FillFormField("name", "Test");
_basicSteps.FillFormField("password", "Admin1234@");
_basicSteps.FillFormField("passwordConfirm", "Admin1234@");
_basicSteps.ClickButtonById("submit");
_basicSteps.IsElementFound("Смартфоны - PhoneStore").Should().BeTrue();
}
}
}
\ No newline at end of file
using FluentAssertions;
using PhoneStore.Tests.Helpers;
using Xunit;
namespace PhoneStore.Tests.Selenium
{
public class MainPageTests
{
private readonly BasicSteps _basicSteps;
public MainPageTests()
{
_basicSteps = new BasicSteps();
}
[Fact]
public void CheckMainPageTitle()
{
_basicSteps.GoToMainPage();
_basicSteps.IsElementFound("Смартфоны - PhoneStore").Should().BeTrue();
_basicSteps.IsElementFound("Список устройств").Should().BeTrue();
}
}
}
\ No newline at end of file
using System;
using System.Net.Http; using System.Net.Http;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Threading.Tasks; using System.Threading.Tasks;
using FluentAssertions; using FluentAssertions;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using PhoneStore.Enums;
using PhoneStore.Models; using PhoneStore.Models;
using PhoneStore.Tests.Helpers; using PhoneStore.Tests.Helpers;
using PhoneStore.ViewModels.PhoneViewModels; using PhoneStore.ViewModels.PhoneViewModels;
using Xunit; using Xunit;
using StatusCodes = Microsoft.AspNetCore.Http.StatusCodes; using StatusCodes = Microsoft.AspNetCore.Http.StatusCodes;
namespace PhoneStore.Tests namespace PhoneStore.Tests.Unit
{ {
public class PhoneControllerTests public class PhoneControllerTests
{ {
......
...@@ -11,12 +11,12 @@ ...@@ -11,12 +11,12 @@
<div asp-validation-summary="ModelOnly"></div> <div asp-validation-summary="ModelOnly"></div>
<div> <div>
<label asp-for="Email"></label><br /> <label asp-for="Email"></label><br />
<input asp-for="Email" /> <input id="email" asp-for="Email" />
<span asp-validation-for="Email"></span> <span asp-validation-for="Email"></span>
</div> </div>
<div> <div>
<label asp-for="Password"></label><br /> <label asp-for="Password"></label><br />
<input asp-for="Password" /> <input id="password" asp-for="Password" />
<span asp-validation-for="Password"></span> <span asp-validation-for="Password"></span>
</div> </div>
<div> <div>
...@@ -24,6 +24,6 @@ ...@@ -24,6 +24,6 @@
<input asp-for="RememberMe" /> <input asp-for="RememberMe" />
</div> </div>
<div> <div>
<button type="submit" class="btn btn-outline-warning">Войти</button> <button id="submit" type="submit" class="btn btn-outline-warning">Войти</button>
</div> </div>
</form> </form>
...@@ -9,31 +9,31 @@ ...@@ -9,31 +9,31 @@
<div asp-validation-summary="ModelOnly"></div> <div asp-validation-summary="ModelOnly"></div>
<div> <div>
<label asp-for="Email"></label><br /> <label asp-for="Email"></label><br />
<input asp-for="Email" /> <input id="email" asp-for="Email" />
<span asp-validation-for="Email"></span> <span asp-validation-for="Email"></span>
</div> </div>
<div> <div>
<label asp-for="Name"></label><br /> <label asp-for="Name"></label><br />
<input asp-for="Name" /> <input id="name" asp-for="Name" />
<span asp-validation-for="Name"></span> <span asp-validation-for="Name"></span>
</div> </div>
<div> <div>
<label asp-for="Age"></label><br /> <label asp-for="Age"></label><br />
<input asp-for="Age" /> <input id="age" asp-for="Age" />
<span asp-validation-for="Age"></span> <span asp-validation-for="Age"></span>
</div> </div>
<div> <div>
<label asp-for="Password"></label><br /> <label asp-for="Password"></label><br />
<input asp-for="Password" /> <input id="password" asp-for="Password" />
<span asp-validation-for="Password"></span> <span asp-validation-for="Password"></span>
</div> </div>
<div> <div>
<label asp-for="PasswordConfirm"></label><br /> <label asp-for="PasswordConfirm"></label><br />
<input asp-for="PasswordConfirm" /> <input id="passwordConfirm" asp-for="PasswordConfirm" />
<span asp-validation-for="PasswordConfirm"></span> <span asp-validation-for="PasswordConfirm"></span>
</div> </div>
<div> <div>
<button type="submit" class="btn btn-outline-warning">Регистрация</button> <button id="submit" type="submit" class="btn btn-outline-warning">Регистрация</button>
</div> </div>
</form> </form>
...@@ -48,7 +48,7 @@ else ...@@ -48,7 +48,7 @@ else
Выполнить... Выполнить...
</button> </button>
<div class="dropdown-menu" aria-labelledby="dropdownMenu2"> <div class="dropdown-menu" aria-labelledby="dropdownMenu2">
<a class="dropdown-item" asp-route-id="@phone.Id" <a id="test" class="dropdown-item" asp-route-id="@phone.Id"
asp-action="Add" asp-action="Add"
asp-controller="Baskets"> asp-controller="Baskets">
В корзину В корзину
......
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