-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
del_2/ui-testing/Bekk.Oppdrift.SeleniumExample/Bekk.Oppdrift.SeleniumExample.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bekk.Oppdrift.SeleniumExample", "Bekk.Oppdrift.SeleniumExample\Bekk.Oppdrift.SeleniumExample.csproj", "{B4CEAAD5-D2F8-4FD8-836B-70B6847A0F77}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{B4CEAAD5-D2F8-4FD8-836B-70B6847A0F77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{B4CEAAD5-D2F8-4FD8-836B-70B6847A0F77}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{B4CEAAD5-D2F8-4FD8-836B-70B6847A0F77}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{B4CEAAD5-D2F8-4FD8-836B-70B6847A0F77}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
30 changes: 30 additions & 0 deletions
30
...pdrift.SeleniumExample/Bekk.Oppdrift.SeleniumExample/Bekk.Oppdrift.SeleniumExample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<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="Microsoft.NET.Test.Sdk" Version="17.6.0"/> | ||
<PackageReference Include="Selenium.Mozilla.Firefox.Webdriver" Version="0.6.0.1" /> | ||
<PackageReference Include="Selenium.Support" Version="4.20.0" /> | ||
<PackageReference Include="Selenium.WebDriver" Version="4.20.0" /> | ||
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="124.0.6367.15500" /> | ||
<PackageReference Include="Selenium.WebDriver.IEDriver" Version="4.14.0" /> | ||
<PackageReference Include="xunit" Version="2.4.2"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
</Project> |
42 changes: 42 additions & 0 deletions
42
.../ui-testing/Bekk.Oppdrift.SeleniumExample/Bekk.Oppdrift.SeleniumExample/WebDriverTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using OpenQA.Selenium; | ||
using OpenQA.Selenium.Chrome; | ||
using OpenQA.Selenium.Firefox; | ||
using OpenQA.Selenium.Support.UI; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Bekk.Oppdrift.SeleniumExample; | ||
|
||
public class WebDriverTests(ITestOutputHelper @out) | ||
{ | ||
[Fact] | ||
public void TestBekkWebPage_UsingChrome() | ||
{ | ||
using var driver = new ChromeDriver(); | ||
driver.Navigate().GoToUrl("https://www.bekk.no"); | ||
var paragraphs = driver.FindElements(By.CssSelector("p")); | ||
foreach (var paragraph in paragraphs) | ||
{ | ||
@out.WriteLine(paragraph.Text.Trim()); | ||
} | ||
driver.Quit(); | ||
} | ||
|
||
[Fact] | ||
public void SearchWikipedia_UsingFirefox() | ||
{ | ||
using var driver = new FirefoxDriver(); | ||
driver.Navigate().GoToUrl("https://www.wikipedia.org/"); | ||
var langSelector = new SelectElement(driver.FindElement(By.Id("searchLanguage"))); | ||
langSelector.SelectByValue("no"); | ||
var query = driver.FindElement(By.Id("searchInput")); | ||
query.SendKeys("Bekk Consulting"); | ||
query.Submit(); | ||
var content = new WebDriverWait(driver, TimeSpan.FromSeconds(2)) | ||
.Until(d => d.FindElement(By.Id("bodyContent"))); | ||
foreach (var txt in content.FindElements(By.TagName("p")).Select(p => p.Text)) | ||
{ | ||
@out.WriteLine(txt); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Selenium testeksempler | ||
=== | ||
|
||
Noen veldig enkle eksempler på hvordan [Selenium Web Driver](https://www.selenium.dev/) kan brukes i en dotnet-test. | ||
|
||
Browserne som brukes (Chrome og Firefox) må være installert på maskinen. | ||
|
||
Testene ligger i [WebDriverTests.cs](./Bekk.Oppdrift.SeleniumExample/WebDriverTests.cs). | ||
|
||
For å kjøre testene: | ||
|
||
```console | ||
dotnet test --logger "console;verbosity=detailed" | ||
``` |