-
Notifications
You must be signed in to change notification settings - Fork 4
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
58 changed files
with
600 additions
and
226 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
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
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
5 changes: 1 addition & 4 deletions
5
src/FluffySpoon.Automation.Web.Puppeteer/PuppeteerWebAutomationFrameworkInstance.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
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<runtime> | ||
<ThrowUnobservedTaskExceptions enabled="true"/> | ||
</runtime> | ||
</configuration> |
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
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
26 changes: 26 additions & 0 deletions
26
src/FluffySpoon.Automation.Web.Tests/AutomationEngineFactory.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,26 @@ | ||
using PuppeteerSharp; | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
|
||
namespace FluffySpoon.Automation.Web.Tests | ||
{ | ||
class AutomationEngineFactory | ||
{ | ||
public static async Task<Browser> GetPuppeteerDriverAsync() | ||
{ | ||
foreach (var process in Process.GetProcessesByName("chrome")) | ||
process.Kill(); | ||
|
||
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision); | ||
return await PuppeteerSharp.Puppeteer.LaunchAsync(new LaunchOptions | ||
{ | ||
Headless = false, | ||
DefaultViewport = new ViewPortOptions() | ||
{ | ||
Width = 1100, | ||
Height = 500 | ||
} | ||
}); | ||
} | ||
} | ||
} |
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,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FluffySpoon.Automation.Web.Tests | ||
{ | ||
public static class Extensions | ||
{ | ||
public static async Task OpenTest(this IWebAutomationEngine engine, string page) | ||
{ | ||
await engine.Open(WebServerHelper.Url + "/" + page); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/FluffySpoon.Automation.Web.Tests/FluffySpoon.Automation.Web.Tests.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,36 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\FluffySpoon.Automation.Web.JQuery\FluffySpoon.Automation.Web.JQuery.csproj" /> | ||
<ProjectReference Include="..\FluffySpoon.Automation.Web.Puppeteer\FluffySpoon.Automation.Web.Puppeteer.csproj" /> | ||
<ProjectReference Include="..\FluffySpoon.Automation.Web.Selenium\FluffySpoon.Automation.Web.Selenium.csproj" /> | ||
<ProjectReference Include="..\FluffySpoon.Automation.Web\FluffySpoon.Automation.Web.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="wwwroot\engine\click.html"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="wwwroot\engine\find.html"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="wwwroot\selector\index.html"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
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,80 @@ | ||
using FluffySpoon.Automation.Web.JQuery; | ||
using FluffySpoon.Automation.Web.Puppeteer; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace FluffySpoon.Automation.Web.Tests | ||
{ | ||
[TestClass] | ||
public class SelectorTests | ||
{ | ||
private class TestCase | ||
{ | ||
public Action<IServiceCollection> SelectorConfiguration { get; } | ||
|
||
public string OuterElementSelector { get; } | ||
|
||
public string InnerElementSelector { get; } | ||
|
||
public TestCase( | ||
Action<IServiceCollection> selectorConfiguration, | ||
string outerElementSelector, | ||
string innerElementSelector) | ||
{ | ||
SelectorConfiguration = selectorConfiguration; | ||
OuterElementSelector = outerElementSelector; | ||
InnerElementSelector = innerElementSelector; | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public async Task SelectorTest() | ||
{ | ||
var testCases = new List<TestCase> | ||
{ | ||
new TestCase( | ||
p => p.AddJQueryDomSelector(), | ||
"#outer:first", | ||
".inner:first") | ||
}; | ||
|
||
using (var server = WebServerHelper.CreateWebServer()) | ||
{ | ||
foreach (var testCase in testCases) | ||
{ | ||
var serviceCollection = new ServiceCollection(); | ||
testCase.SelectorConfiguration(serviceCollection); | ||
|
||
serviceCollection.AddPuppeteerWebAutomationFrameworkInstance(AutomationEngineFactory.GetPuppeteerDriverAsync); | ||
|
||
var serviceProvider = serviceCollection.BuildServiceProvider(); | ||
using (var automationEngine = serviceProvider.GetRequiredService<IWebAutomationEngine>()) | ||
{ | ||
await automationEngine.InitializeAsync(); | ||
|
||
await automationEngine.OpenTest("selector/index.html"); | ||
|
||
var outerElements = await automationEngine.Find(testCase.OuterElementSelector); | ||
Assert.IsNotNull(outerElements); | ||
|
||
var outerElement = outerElements.SingleOrDefault(); | ||
Assert.IsNotNull(outerElement); | ||
Assert.AreEqual("hello world", outerElement.TextContent); | ||
|
||
var innerElements = await automationEngine.Find(testCase.InnerElementSelector); | ||
Assert.IsNotNull(innerElements); | ||
|
||
var innerElement = innerElements.SingleOrDefault(); | ||
Assert.IsNotNull(innerElement); | ||
Assert.AreEqual("world", innerElement.TextContent?.Trim()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.