Added ScriptManager to execute scripts

This commit is contained in:
Aaron Yarborough 2017-01-26 10:02:25 +00:00
parent 22d7294cd9
commit 5adaa52b59
5 changed files with 1079 additions and 0 deletions

File diff suppressed because it is too large Load diff

View file

@ -68,11 +68,16 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Responses\LoginResponse.cs" /> <Compile Include="Responses\LoginResponse.cs" />
<Compile Include="Responses\Response.cs" /> <Compile Include="Responses\Response.cs" />
<Compile Include="ScriptManagement\ScriptManager.cs" />
<Compile Include="ScriptManagement\Scripts.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup />
<ItemGroup>
<Content Include="ScriptManagement\Scripts\test.js" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View file

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BankingBot.Contracts;
using OpenQA.Selenium;
using OpenQA.Selenium.Internal;
namespace BankingBot.ScriptManagement
{
public class ScriptManager
{
private readonly IBrowserBot _browserBot;
public ScriptManager(IBrowserBot browserBot)
{
_browserBot = browserBot;
}
public T Execute<T>(string scriptPath, Dictionary<string, string> data = null)
{
var scriptContent = File.ReadAllText(scriptPath);
if (data != null)
{
var placeholderFormat = "__${0}";
foreach (var pair in data)
{
var placeholderText = string.Format(placeholderFormat, pair.Key);
scriptContent = scriptContent.Replace(placeholderText, pair.Value);
}
}
var executor = _browserBot.WebDriver as IJavaScriptExecutor;
return (T)executor.ExecuteScript(scriptContent);
}
}
}

View file

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankingBot.ScriptManagement
{
public static class Scripts
{
}
}

View file

@ -0,0 +1,3 @@
(function () {
var test = (/*{test}*/);
})();