Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions Behavioral.Automation.DemoBindings/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,21 @@ public class Bootstrapper
{
private readonly IObjectContainer _objectContainer;
private readonly ITestRunner _runner;
private static DemoTestServicesBuilder _servicesBuilder;
private static readonly BrowserRunner BrowserRunner = new BrowserRunner();
private readonly DemoTestServicesBuilder _servicesBuilder;
private readonly BrowserContext _browserContext;

public Bootstrapper(IObjectContainer objectContainer, ITestRunner runner)
public Bootstrapper(IObjectContainer objectContainer, ITestRunner runner, BrowserContext browserContext)
{
_objectContainer = objectContainer;
_runner = runner;
_browserContext = browserContext;
_servicesBuilder = new DemoTestServicesBuilder(objectContainer, new TestServicesBuilder(_objectContainer));
}

[BeforeTestRun]
public static void OpenBrowser()
[AfterScenario]
public void CloseBrowser()
{
BrowserRunner.OpenChrome();
}

[AfterTestRun]
public static void CloseBrowser()
{
BrowserRunner.CloseBrowser();
_browserContext.CloseBrowser();
}

[BeforeScenario(Order = 0)]
Expand All @@ -39,6 +34,7 @@ public void Bootstrap()
_objectContainer.RegisterTypeAs<UserInterfaceBuilder, IUserInterfaceBuilder>();
_servicesBuilder.Build();
Assert.SetConsumer(_objectContainer.Resolve<IScenarioExecutionConsumer>());
_browserContext.OpenChrome();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using NUnit.Framework;

[assembly: Parallelizable(ParallelScope.Fixtures)]

//edit if more threads are needed
[assembly: LevelOfParallelism(1)]
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;

namespace Behavioral.Automation.Services
{
public class BrowserRunner
public class BrowserContext
{
public RemoteWebDriver Driver;

public void OpenBrowser([NotNull] RemoteWebDriver driver)
{
DriverService.Driver = driver;
Driver = driver;
}

public void CloseBrowser()
{
DriverService.Driver.Dispose();
Driver.Dispose();
}

public void OpenChrome(ChromeOptions options = null)
Expand Down
26 changes: 12 additions & 14 deletions src/Behavioral.Automation/Services/DriverService.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using Behavioral.Automation.Services.Mapping.Contract;
using JetBrains.Annotations;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;
using System.Threading;
using NUnit.Framework;

namespace Behavioral.Automation.Services
{
Expand All @@ -19,18 +18,17 @@ public sealed class DriverService : IDriverService
{
[NotNull]
private readonly IScopeContextManager _scopeContextManager;
private readonly BrowserContext _browserContext;

public static RemoteWebDriver Driver;

public DriverService([NotNull] IScopeContextManager scopeContextManager)
public DriverService([NotNull] IScopeContextManager scopeContextManager, BrowserContext browserContext)
{
_scopeContextManager = scopeContextManager;
_browserContext = browserContext;
}

private WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(4));
private ReadOnlyCollection<string> WindowHandles => Driver.WindowHandles;
public RemoteWebDriver Driver => _browserContext.Driver;

private string SearchAttribute = ConfigServiceBase.SearchAttribute;
private readonly string SearchAttribute = ConfigServiceBase.SearchAttribute;

public string Title => Driver.Title;

Expand Down Expand Up @@ -85,8 +83,8 @@ public ReadOnlyCollection<IWebElement> FindElementsByXpath(string path)
public void ScrollTo(IWebElement element)
{
var scrollElementIntoMiddle = "var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);"
+ "var elementTop = arguments[0].getBoundingClientRect().top;"
+ "window.scrollBy(0, elementTop-(viewPortHeight/2));";
+ "var elementTop = arguments[0].getBoundingClientRect().top;"
+ "window.scrollBy(0, elementTop-(viewPortHeight/2));";

Driver.ExecuteScript(scrollElementIntoMiddle, element);
Actions actions = new Actions(Driver);
Expand Down Expand Up @@ -160,7 +158,7 @@ public void SwitchToLastWindow()
}

public void ResizeWindow(int Height, int Width)
{
{
Driver.Manage().Window.Size = new Size(Width, Height);
}

Expand All @@ -180,4 +178,4 @@ public void ScrollElementTo(IWebElement element, int offset)
Thread.Sleep(1000);
}
}
}
}
3 changes: 3 additions & 0 deletions src/Behavioral.Automation/Services/IDriverService.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using System.Collections.ObjectModel;
using JetBrains.Annotations;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;

namespace Behavioral.Automation.Services
{
public interface IDriverService
{
RemoteWebDriver Driver { get; }

string CurrentUrl { [NotNull] get; }

string Title { [CanBeNull] get; }
Expand Down