Skip to content

Commit 2531a41

Browse files
committed
Corrige contexto, webdrivers, e adiciona cenario corretamente
1 parent 78c53cb commit 2531a41

34 files changed

+2065
-9
lines changed
Binary file not shown.

.vs/SeleniumBoilerplate/v16/.suo

18 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

.vs/VSWorkspaceState.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"ExpandedNodes": [
3+
""
4+
],
5+
"SelectedNode": "\\SeleniumBoilerplate.sln",
6+
"PreviewInSolutionExplorer": false
7+
}

.vs/slnx.sqlite

180 KB
Binary file not shown.
10.7 MB
Binary file not shown.

SeleniumBoilerplate/PageObjects/SimplePage.cs

+22-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,32 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Text;
5+
using Xunit;
56

67
namespace SeleniumBoilerplate.PageObjects
78
{
8-
public static class SimplePage
9+
public class SimplePage : IClassFixture<StartupFixture>
910
{
10-
public static readonly By botaoStart = By.CssSelector("#start > button");
11+
IWebDriver driver;
12+
StartupFixture fixture;
13+
private By btnStart = By.CssSelector("#start > button");
14+
private By lblFinish = By.CssSelector("#finish > h4");
1115

12-
public static readonly By finishedWord = By.CssSelector("#finish > h4");
16+
public SimplePage(StartupFixture fixture)
17+
{
18+
this.fixture = fixture;
19+
driver = fixture.InicializaDriver("");
20+
}
21+
/*
22+
* Valida a existencia do elemento lblFinish
23+
* @return Boolean
24+
*/
25+
public void validaCampos()
26+
{
27+
driver.FindElement(btnStart).Click();
28+
driver.FindElement(lblFinish);
29+
30+
return;
31+
}
1332
}
1433
}

SeleniumBoilerplate/Scenarios/SimplePageTests.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,24 @@ namespace SeleniumBoilerplate.Scenarios
1010
public class SimplePageTests : IClassFixture<StartupFixture>
1111
{
1212
StartupFixture fixture;
13+
SimplePage simplePage;
1314
IWebDriver browser;
1415
public SimplePageTests(StartupFixture fixture)
1516
{
1617
this.fixture = fixture;
17-
browser = fixture.InicializaDriver("chrome");
18+
browser = fixture.InicializaDriver("");
1819
}
1920

2021
[Fact]
2122
public void AbrirNavegadorEFazerValidacao()
2223
{
24+
simplePage = new SimplePage(fixture);
2325
#region Navega até a tela
2426
browser.Navigate().GoToUrl("https://the-internet.herokuapp.com/dynamic_loading/1");
2527
#endregion
2628

2729
#region Clica no elemento e faz a validação
30+
simplePage.validaCampos();
2831
#endregion
2932
}
3033
}

SeleniumBoilerplate/SeleniumBoilerplate.csproj

+6
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@
2121
</PackageReference>
2222
</ItemGroup>
2323

24+
<ItemGroup>
25+
<None Update="Drivers\chromedriver.exe">
26+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
27+
</None>
28+
</ItemGroup>
29+
2430
</Project>

SeleniumBoilerplate/StartupFixture.cs

+9-5
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ namespace SeleniumBoilerplate
1010
public class StartupFixture : IDisposable
1111
{
1212
IWebDriver _driver;
13-
private char separador = Path.PathSeparator;
1413

15-
public IWebDriver InicializaDriver(string browser)
14+
public IWebDriver InicializaDriver(string? browser)
1615
{
1716
switch (browser)
1817
{
@@ -23,7 +22,7 @@ public IWebDriver InicializaDriver(string browser)
2322
_driver = new FirefoxDriver();
2423
break;
2524
default:
26-
Console.WriteLine("Browser não é suportado!");
25+
_driver = new ChromeDriver(Path.Combine($"{Directory.GetCurrentDirectory()}\\Drivers"));
2726
break;
2827
}
2928

@@ -34,9 +33,14 @@ public void Dispose()
3433
{
3534
Screenshot screenshot = (_driver as ITakesScreenshot).GetScreenshot();
3635

37-
string ScreenshotDir = Path.Combine($"{Directory.GetCurrentDirectory()}{separador}Evidencias");
36+
string screenshotDir = Path.Combine($"{Directory.GetCurrentDirectory()}\\Evidencias");
3837

39-
screenshot.SaveAsFile($"{ScreenshotDir}{DateTime.Now}", ScreenshotImageFormat.Png);
38+
if(!Directory.Exists(screenshotDir))
39+
{
40+
Directory.CreateDirectory(screenshotDir);
41+
}
42+
43+
//screenshot.SaveAsFile($"{screenshotDir}{DateTime.Now}", ScreenshotImageFormat.Png);
4044

4145
_driver.Quit();
4246
}
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)