Skip to content

Commit

Permalink
quite a few selenium updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dummy committed Feb 6, 2019
1 parent 404dfd5 commit 90f86ab
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ await _page.Mouse.ClickAsync(

public void Dispose()
{
_page.Dispose();
_browser.Dispose();
_page?.Dispose();
_browser?.Dispose();
}

public async Task DoubleClickAsync(IReadOnlyList<IDomElement> elements, int offsetX, int offsetY)
Expand Down
16 changes: 11 additions & 5 deletions src/FluffySpoon.Automation.Web.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ static async Task Main(string[] args)
var serviceCollection = new ServiceCollection();
serviceCollection.UseJQueryDomSelector();

serviceCollection.AddSeleniumWebAutomationFrameworkInstance(GetFirefoxDriverAsync);
serviceCollection.AddSeleniumWebAutomationFrameworkInstance(GetChromeDriverAsync);
serviceCollection.AddSeleniumWebAutomationFrameworkInstance(GetEdgeDriverAsync);
//serviceCollection.AddSeleniumWebAutomationFrameworkInstance(GetFirefoxDriverAsync);
//serviceCollection.AddSeleniumWebAutomationFrameworkInstance(GetChromeDriverAsync);
//serviceCollection.AddSeleniumWebAutomationFrameworkInstance(GetEdgeDriverAsync);

serviceCollection.AddPuppeteerWebAutomationFrameworkInstance(GetPuppeteerDriverAsync);

Expand All @@ -40,13 +40,19 @@ await automationEngine
.Wait(until =>
until.Exists("input[type=submit][name=btnK]:visible"));

var elements = await automationEngine
await automationEngine
.Click.On("input[type=submit][name=btnK]:visible")
.Wait(until =>
until.Exists("#rso .g:visible"))
until.Exists("#rso .g:visible"));

var elements = await automationEngine
.Expect
.Count(10).Of("#rso .g:visible");

foreach (var element in elements) {
await automationEngine.TakeScreenshot.Of(element).SaveAs("screenshot.jpg");
}

Console.WriteLine("Test done!");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public async Task RightClickAsync(IReadOnlyList<IDomElement> elements, int relat

public void Dispose()
{
_driver.Quit();
_driver.Dispose();
_driver?.Quit();
_driver?.Dispose();
}

public async Task EnterTextInAsync(IReadOnlyList<IDomElement> elements, string text)
Expand All @@ -106,7 +106,7 @@ public async Task EnterTextInAsync(IReadOnlyList<IDomElement> elements, string t
public Task<string> EvaluateJavaScriptAsync(string code)
{
var scriptExecutor = GetScriptExecutor();
var result = scriptExecutor.ExecuteScript(code);
var result = scriptExecutor.ExecuteScript("return " + code);

return Task.FromResult(result?.ToString());
}
Expand Down
3 changes: 3 additions & 0 deletions src/FluffySpoon.Automation.Web/Dom/DomTunnel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -96,6 +97,8 @@ public async Task<IReadOnlyList<IDomElement>> GetDomElementsFromJavaScriptCode(
return JSON.stringify(returnValues);
"));

Debug.Assert(resultJsonBlobs != null, "result json blobs not null");

var blobs = JsonConvert.DeserializeObject<ElementWrapper[]>(resultJsonBlobs);
return blobs
.Select(x =>
Expand Down
20 changes: 15 additions & 5 deletions src/FluffySpoon.Automation.Web/Fluent/BaseMethodChainNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,35 @@ abstract class BaseMethodChainNode<TParentMethodChainNode> :
where TParentMethodChainNode : IBaseMethodChainNode
{
private readonly SemaphoreSlim _executeSemaphore;

private IMethodChainContext _methodChainContext;
private IReadOnlyList<IDomElement> _elements;

public IMethodChainContext MethodChainContext {
public IMethodChainContext MethodChainContext
{
protected get
{
return _methodChainContext;
}
}
set
{
_methodChainContext = value;
if(value != null)
if (value != null)
MethodChainOffset = value.NodeCount;
}
}
public virtual IReadOnlyList<IDomElement> Elements { get; protected set; }

public virtual IReadOnlyList<IDomElement> Elements {
get => _elements;
protected set => _elements = value;
}

public int MethodChainOffset { get; set; }

protected internal TParentMethodChainNode Parent { get; private set; }
protected internal TParentMethodChainNode Parent {
get;
private set;
}

public BaseMethodChainNode()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public MethodChainContext(

_methodChainOffset = Interlocked.Increment(ref _globalMethodChainOffset);

foreach(var framework in Frameworks)
foreach (var framework in Frameworks)
{
_userAgentMethodChainQueue.Add(framework, new MethodChain());
}
Expand Down Expand Up @@ -95,10 +95,16 @@ public async Task RunNextAsync()
foreach (var framework in Frameworks)
{
var methodChainQueue = _userAgentMethodChainQueue[framework];

var next = methodChainQueue.PendingNodesToRun.Dequeue();
var nextNext = methodChainQueue.PendingNodesToRun.Count > 0 ?
methodChainQueue.PendingNodesToRun.Peek() :
null;

Log("[" + framework.UserAgentName + "] Executing: " + next);

var nextToString = next.ToString();
Log("[" + framework.UserAgentName + "] Executing: " + nextToString);
if (nextNext != null)
Log("[" + framework.UserAgentName + "] Next is: " + nextNext);

tasks.Add(next.ExecuteAsync(framework));
}
Expand Down Expand Up @@ -146,12 +152,15 @@ public TMethodChainNode Enqueue<TMethodChainNode>(TMethodChainNode node) where T
var linkedListNode = allNodes.AddLast(newNode);
var parentNode = linkedListNode?.Previous?.Value;
if (parentNode != null)
{
newNode.SetParent(parentNode);
node.SetParent(parentNode);
}

methodChainQueue
.PendingNodesToRun
.Enqueue(newNode);
.Enqueue(newNode);

Log("[" + framework.UserAgentName + "] Queued: " + newNode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ namespace FluffySpoon.Automation.Web.Fluent.Expect.Root
{
class ExpectMethodChainEntryPoint : ExpectMethodChainRoot<IBaseMethodChainNode>
{
public ExpectMethodChainEntryPoint()
{

}

public override IBaseMethodChainNode Clone()
{
return this;
Expand Down
3 changes: 1 addition & 2 deletions src/FluffySpoon.Automation.Web/WebAutomationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ public async Task InitializeAsync()

await _domSelectorStrategy.InitializeAsync();

foreach(var framework in _frameworks) {
foreach(var framework in _frameworks)
await framework.InitializeAsync();
}

_isInitialized = true;
_isInitializing = false;
Expand Down

0 comments on commit 90f86ab

Please sign in to comment.