Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
Lesson49
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Пасько Виталий
Lesson49
Commits
0728f409
Commit
0728f409
authored
Oct 18, 2022
by
Пасько Виталий
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил несколько тестов.
parent
2e424701
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
148 additions
and
13 deletions
+148
-13
BasicSteps.cs
PhoneStore.Tests/Helpers/BasicSteps.cs
+59
-0
PhoneStore.Tests.csproj
PhoneStore.Tests/PhoneStore.Tests.csproj
+2
-0
AuthTests.cs
PhoneStore.Tests/Selenium/AuthTests.cs
+52
-0
MainPageTests.cs
PhoneStore.Tests/Selenium/MainPageTests.cs
+24
-0
PhoneControllerTests.cs
PhoneStore.Tests/Unit/PhoneControllerTests.cs
+1
-3
Login.cshtml
PhoneStore/Views/Account/Login.cshtml
+3
-3
Register.cshtml
PhoneStore/Views/Account/Register.cshtml
+6
-6
Index.cshtml
PhoneStore/Views/Phones/Index.cshtml
+1
-1
No files found.
PhoneStore.Tests/Helpers/BasicSteps.cs
0 → 100644
View file @
0728f409
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
PhoneStore.Tests/PhoneStore.Tests.csproj
View file @
0728f409
...
...
@@ -10,6 +10,8 @@
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.17" />
<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.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
...
...
PhoneStore.Tests/Selenium/AuthTests.cs
0 → 100644
View file @
0728f409
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
PhoneStore.Tests/Selenium/MainPageTests.cs
0 → 100644
View file @
0728f409
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
PhoneStore.Tests/PhoneControllerTests.cs
→
PhoneStore.Tests/
Unit/
PhoneControllerTests.cs
View file @
0728f409
using
System
;
using
System.Net.Http
;
using
System.Text
;
using
System.Text.Json
;
using
System.Threading.Tasks
;
using
FluentAssertions
;
using
Microsoft.Extensions.DependencyInjection
;
using
PhoneStore.Enums
;
using
PhoneStore.Models
;
using
PhoneStore.Tests.Helpers
;
using
PhoneStore.ViewModels.PhoneViewModels
;
using
Xunit
;
using
StatusCodes
=
Microsoft
.
AspNetCore
.
Http
.
StatusCodes
;
namespace
PhoneStore.Tests
namespace
PhoneStore.Tests
.Unit
{
public
class
PhoneControllerTests
{
...
...
PhoneStore/Views/Account/Login.cshtml
View file @
0728f409
...
...
@@ -11,12 +11,12 @@
<div asp-validation-summary="ModelOnly"></div>
<div>
<label asp-for="Email"></label><br />
<input asp-for="Email" />
<input
id="email"
asp-for="Email" />
<span asp-validation-for="Email"></span>
</div>
<div>
<label asp-for="Password"></label><br />
<input asp-for="Password" />
<input
id="password"
asp-for="Password" />
<span asp-validation-for="Password"></span>
</div>
<div>
...
...
@@ -24,6 +24,6 @@
<input asp-for="RememberMe" />
</div>
<div>
<button type="submit" class="btn btn-outline-warning">Войти</button>
<button
id="submit"
type="submit" class="btn btn-outline-warning">Войти</button>
</div>
</form>
PhoneStore/Views/Account/Register.cshtml
View file @
0728f409
...
...
@@ -9,31 +9,31 @@
<div asp-validation-summary="ModelOnly"></div>
<div>
<label asp-for="Email"></label><br />
<input asp-for="Email" />
<input
id="email"
asp-for="Email" />
<span asp-validation-for="Email"></span>
</div>
<div>
<label asp-for="Name"></label><br />
<input asp-for="Name" />
<input
id="name"
asp-for="Name" />
<span asp-validation-for="Name"></span>
</div>
<div>
<label asp-for="Age"></label><br />
<input asp-for="Age" />
<input
id="age"
asp-for="Age" />
<span asp-validation-for="Age"></span>
</div>
<div>
<label asp-for="Password"></label><br />
<input asp-for="Password" />
<input
id="password"
asp-for="Password" />
<span asp-validation-for="Password"></span>
</div>
<div>
<label asp-for="PasswordConfirm"></label><br />
<input asp-for="PasswordConfirm" />
<input
id="passwordConfirm"
asp-for="PasswordConfirm" />
<span asp-validation-for="PasswordConfirm"></span>
</div>
<div>
<button type="submit" class="btn btn-outline-warning">Регистрация</button>
<button
id="submit"
type="submit" class="btn btn-outline-warning">Регистрация</button>
</div>
</form>
PhoneStore/Views/Phones/Index.cshtml
View file @
0728f409
...
...
@@ -48,7 +48,7 @@ else
Выполнить...
</button>
<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-controller="Baskets">
В корзину
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment