├── .gitignore ├── Examples └── SeleniumFixture.ExampleTests │ ├── SeleniumFixture.ExampleModels │ ├── Models │ │ └── NewUserModel.cs │ ├── PageObjects │ │ ├── BaseElement.cs │ │ ├── BasePage.cs │ │ ├── HomePage.cs │ │ ├── InputPage.cs │ │ ├── LinksPage.cs │ │ └── MenuElement.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── SeleniumFixture.ExampleModels.csproj │ └── packages.config │ ├── SeleniumFixture.ExampleTests.sln │ ├── SeleniumFixture.mstest.ExampleTests │ ├── AutoFillTests.cs │ ├── FillExampleTests.cs │ ├── PageObjectTests.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── SeleniumFixture.mstest.ExampleTests.csproj │ └── packages.config │ └── SeleniumFixture.xUnit.ExampleTests │ ├── App.config │ ├── AssemblyAttributes.cs │ ├── AutoFillTests.cs │ ├── DataAttributeTets.cs │ ├── FillTests.cs │ ├── InitializeTests.cs │ ├── InitializeToHomePageAttribute.cs │ ├── InitializeToInputFormAttribute.cs │ ├── InternetExplorerOptionsAttribute.cs │ ├── MicrosoftWebDriver.exe │ ├── PageObjectTests.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── SeleniumFixture.xUnit.ExampleTests.csproj │ └── packages.config ├── License.md ├── README.md ├── nuget └── NuGet.exe └── src ├── SeleniumFixture.sln ├── SeleniumFixture.xUnit.dnx └── global.json ├── SeleniumFixture.xUnit ├── ChromeDriverAttribute.cs ├── ChromeDriverProviderAttribute.cs ├── ChromeOptionsAttribute.cs ├── CustomTheoryAttribute.cs ├── EdgeDriverAttribute.cs ├── EdgeDriverProviderAttribute.cs ├── EdgeOptionsAttribute.cs ├── FireFoxDriverAttribute.cs ├── FireFoxProfileAttribute.cs ├── FirefoxDriverProviderAttribute.cs ├── FixtureCreationAttribute.cs ├── IFixtureFinalizerAttribute.cs ├── IFixtureInitializationAttribute.cs ├── IWebDriverFinalizerAttribute.cs ├── IWebDriverInitializationAttribute.cs ├── IWebDriverResetAttribute.cs ├── Impl │ ├── ExceptionExtensions.cs │ ├── LongLivedMarshalByRefObject.cs │ ├── ReflectionHelper.cs │ ├── SeleniumTheoryDiscoverer.cs │ ├── SeleniumTheoryTestCase.cs │ ├── SeleniumTheoryTestCaseRunner.cs │ ├── SerializationHelper.cs │ ├── TestCaseRunner.cs │ ├── TestMethodTestCase.cs │ └── XunitSkippedDataRowTestCase.cs ├── InternetExplorerDriverAttribute.cs ├── InternetExplorerDriverProviderAttribute.cs ├── InternetExplorerOptionsAttribute.cs ├── Properties │ └── AssemblyInfo.cs ├── RemoteDriverAttribute.cs ├── RemoteWebDriverHubAddressAttribute.cs ├── RemoteWebDriverProviderAttribute.cs ├── SeleniumFixture.xUnit.csproj ├── SeleniumFixture.xUnit.nuspec ├── SeleniumTheoryAttribute.cs ├── WebDriverAttribute.cs └── packages.config ├── SeleniumFixture ├── ElementContants.cs ├── Exceptions │ └── AssertionFailedException.cs ├── Fixture.cs ├── FormData.cs ├── Impl │ ├── AlertAction.cs │ ├── AutoBy.cs │ ├── AutoFillAction.cs │ ├── AutoFillAsAction.cs │ ├── AutoFillAsActionProvider.cs │ ├── ClearAction.cs │ ├── ClickAction.cs │ ├── DoubleClickAction.cs │ ├── FillAction.cs │ ├── FixtureActionProvider.cs │ ├── GetAction.cs │ ├── IActionProvider.cs │ ├── ImportSeleniumTypePropertySelector.cs │ ├── JQueryBy.cs │ ├── MouseMoveAction.cs │ ├── NavigateAction.cs │ ├── PropertySetter.cs │ ├── SeleniumTypePropertySelector.cs │ ├── SendToAction.cs │ ├── SwitchAction.cs │ ├── TakeScreenshotAction.cs │ ├── ThenSubmitAction.cs │ ├── WaitAction.cs │ └── YieldsAction.cs ├── ImportAttribute.cs ├── LanguageExtensions.cs ├── PageObject.cs ├── Properties │ └── AssemblyInfo.cs ├── SeleniumFixture.cs ├── SeleniumFixture.csproj ├── SeleniumFixture.nuspec ├── SeleniumFixtureConfiguration.cs ├── Using.cs └── packages.config └── wrap └── SeleniumFixture └── project.json /.gitignore: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This .gitignore file was automatically created by Microsoft(R) Visual Studio. 3 | ################################################################################ 4 | 5 | /src/packages 6 | /src/SeleniumFixture/obj/Debug 7 | /src/SeleniumFixture/bin/Debug 8 | /src/SeleniumFixture.xUnit/obj/Debug 9 | /src/SeleniumFixture.xUnit/bin/Debug 10 | *.suo 11 | *.dll 12 | *.pdb 13 | /Output/bin/AnyCPU 14 | /Examples/SeleniumFixture.ExampleTests/packages 15 | /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.ExampleModels/obj/Debug 16 | /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.ExampleModels/bin/Debug 17 | /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.mstest.ExampleTests/obj/Debug 18 | /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.mstest.ExampleTests/bin/Debug 19 | /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.xUnit.ExampleTests/obj/Debug 20 | /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.xUnit.ExampleTests/bin/Debug 21 | /artifacts 22 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.ExampleModels/Models/NewUserModel.cs: -------------------------------------------------------------------------------- 1 | namespace SeleniumFixture.ExampleModels.Models 2 | { 3 | public class NewUserModel 4 | { 5 | public string FirstName { get; set; } 6 | 7 | public string LastName { get; set; } 8 | 9 | public string Email { get; set; } 10 | 11 | public string Password { get; set; } 12 | 13 | public bool Active { get; set; } 14 | 15 | public bool OptionsCheckbox1 { get; set; } 16 | 17 | public bool OptionsCheckbox2 { get; set; } 18 | 19 | public string Gender { get; set; } 20 | 21 | public string AccountType { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.ExampleModels/PageObjects/BaseElement.cs: -------------------------------------------------------------------------------- 1 | using SeleniumFixture.Impl; 2 | 3 | namespace SeleniumFixture.ExampleModels.PageObjects 4 | { 5 | public class BaseElement 6 | { 7 | protected IActionProvider I { get; private set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.ExampleModels/PageObjects/BasePage.cs: -------------------------------------------------------------------------------- 1 | namespace SeleniumFixture.ExampleModels.PageObjects 2 | { 3 | public class BasePage : BaseElement 4 | { 5 | [Import] 6 | public MenuElement Menu { get; private set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.ExampleModels/PageObjects/HomePage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | 4 | namespace SeleniumFixture.ExampleModels.PageObjects 5 | { 6 | public class HomePage : BasePage 7 | { 8 | public HomePage() 9 | { 10 | Validate = () => I.Get.PageTitle.Should().Be("SeleniumFixture"); 11 | } 12 | 13 | protected Action Validate { get; private set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.ExampleModels/PageObjects/InputPage.cs: -------------------------------------------------------------------------------- 1 | using OpenQA.Selenium; 2 | using SeleniumFixture.ExampleModels.Models; 3 | using SeleniumFixture.Impl; 4 | using System; 5 | 6 | namespace SeleniumFixture.ExampleModels.PageObjects 7 | { 8 | public class InputPage : BasePage 9 | { 10 | public InputPage() 11 | { 12 | Validate = () => I.CheckForElement(By.Id("LastName")); 13 | } 14 | 15 | protected Action Validate { get; private set; } 16 | 17 | 18 | public void FillForm(object formData) 19 | { 20 | I.Fill("//form").With(formData); 21 | } 22 | 23 | public NewUserModel AutoFill(object seedWith = null) 24 | { 25 | I.AutoFill("//form", seedWith); 26 | 27 | return I.Get.ValueAs().From("//form"); 28 | } 29 | 30 | public void Submit() 31 | { 32 | I.Submit("//form"); 33 | } 34 | 35 | public IGetAction Get { get { return I.Get; } } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.ExampleModels/PageObjects/LinksPage.cs: -------------------------------------------------------------------------------- 1 | namespace SeleniumFixture.ExampleModels.PageObjects 2 | { 3 | public class LinksPage : BasePage 4 | { 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.ExampleModels/PageObjects/MenuElement.cs: -------------------------------------------------------------------------------- 1 | using OpenQA.Selenium; 2 | 3 | namespace SeleniumFixture.ExampleModels.PageObjects 4 | { 5 | public class MenuElement : BaseElement 6 | { 7 | public HomePage ClickHome() 8 | { 9 | return I.Click(By.LinkText("Home")).Yields(); 10 | } 11 | 12 | public InputPage ClickInputForm() 13 | { 14 | return I.Click(By.LinkText("Input Form")).Yields(); 15 | } 16 | 17 | public LinksPage ClickLinks() 18 | { 19 | return I.Click(By.LinkText("Link Page")).Yields(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.ExampleModels/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SeleniumFixture.ExampleModels")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SeleniumFixture.ExampleModels")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("b99cf136-b010-45b0-a9c0-96a45524d984")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.ExampleModels/SeleniumFixture.ExampleModels.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {0734547E-D92C-4338-B8F4-1BB1B4289504} 8 | Library 9 | Properties 10 | SeleniumFixture.ExampleModels 11 | SeleniumFixture.ExampleModels 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\packages\FluentAssertions.4.5.0\lib\net45\FluentAssertions.dll 35 | True 36 | 37 | 38 | ..\packages\FluentAssertions.4.5.0\lib\net45\FluentAssertions.Core.dll 39 | True 40 | 41 | 42 | False 43 | ..\..\..\Output\bin\AnyCPU\SeleniumFixture.dll 44 | 45 | 46 | ..\packages\SimpleFixture.1.2.0\lib\portable-net45+win+wpa81+wp80\SimpleFixture.dll 47 | True 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | ..\packages\Selenium.WebDriver.2.53.0\lib\net40\WebDriver.dll 59 | True 60 | 61 | 62 | ..\packages\Selenium.Support.2.53.0\lib\net40\WebDriver.Support.dll 63 | True 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 87 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.ExampleModels/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.ExampleTests.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeleniumFixture.ExampleModels", "SeleniumFixture.ExampleModels\SeleniumFixture.ExampleModels.csproj", "{0734547E-D92C-4338-B8F4-1BB1B4289504}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeleniumFixture.xUnit.ExampleTests", "SeleniumFixture.xUnit.ExampleTests\SeleniumFixture.xUnit.ExampleTests.csproj", "{1058E28E-027E-4650-8FCB-6D88C30613ED}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeleniumFixture.mstest.ExampleTests", "SeleniumFixture.mstest.ExampleTests\SeleniumFixture.mstest.ExampleTests.csproj", "{E25C9041-3500-404C-8190-E9AC3E414FCD}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {0734547E-D92C-4338-B8F4-1BB1B4289504}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {0734547E-D92C-4338-B8F4-1BB1B4289504}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {0734547E-D92C-4338-B8F4-1BB1B4289504}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {0734547E-D92C-4338-B8F4-1BB1B4289504}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {1058E28E-027E-4650-8FCB-6D88C30613ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {1058E28E-027E-4650-8FCB-6D88C30613ED}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {1058E28E-027E-4650-8FCB-6D88C30613ED}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {1058E28E-027E-4650-8FCB-6D88C30613ED}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {E25C9041-3500-404C-8190-E9AC3E414FCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {E25C9041-3500-404C-8190-E9AC3E414FCD}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {E25C9041-3500-404C-8190-E9AC3E414FCD}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {E25C9041-3500-404C-8190-E9AC3E414FCD}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.mstest.ExampleTests/AutoFillTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using FluentAssertions; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using OpenQA.Selenium.Firefox; 5 | using SeleniumFixture.ExampleModels.Models; 6 | 7 | namespace SeleniumFixture.mstest.ExampleTests 8 | { 9 | [TestClass] 10 | public class AutoFillTests 11 | { 12 | //[TestMethod] 13 | public void Fixture_FillForm_PopulatesCorrectly() 14 | { 15 | using (var driver = new FirefoxDriver()) 16 | { 17 | var fixture = new Fixture(driver); 18 | 19 | fixture.Navigate.To("http://ipjohnson.github.io/SeleniumFixture/TestSite/InputForm.html"); 20 | 21 | fixture.AutoFill("//form"); 22 | 23 | var newUser = fixture.Get.ValueAs().From("//form"); 24 | 25 | newUser.FirstName.Should().Match(s => s.All(char.IsLetter)); 26 | 27 | newUser.LastName.Should().Match(s => s.All(char.IsLetter)); 28 | 29 | newUser.Email 30 | .Should() 31 | .MatchRegex("^([0-9a-zA-Z]([-\\.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$"); 32 | 33 | newUser.Gender.Should().BeOneOf("male", "female"); 34 | 35 | newUser.Password.Should() 36 | .MatchRegex(@"^(?=.*[.,;'""!@#$%^&*()\-_=+`~\[\]{}?|])(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).{8,20}$"); 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.mstest.ExampleTests/FillExampleTests.cs: -------------------------------------------------------------------------------- 1 | using FluentAssertions; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using OpenQA.Selenium.Firefox; 4 | 5 | namespace SeleniumFixture.mstest.ExampleTests 6 | { 7 | [TestClass] 8 | public class FillExampleTests 9 | { 10 | //[TestMethod] 11 | public void Fixture_FillForm_PopulatesCorrectly() 12 | { 13 | using (var driver = new FirefoxDriver()) 14 | { 15 | var fixture = new Fixture(driver); 16 | 17 | fixture.Navigate.To("http://ipjohnson.github.io/SeleniumFixture/TestSite/InputForm.html"); 18 | 19 | var fillInfo = new 20 | { 21 | FirstName = "Sterling", 22 | LastName = "Archer", 23 | Email = "sterling.archer@spy.gov", 24 | Password = "HelloWorld1!", 25 | Active = true, 26 | OptionsCheckbox1 = false, 27 | OptionsCheckbox2 = true, 28 | Gender = "Male", 29 | AccountType = "SuperAdmin" 30 | }; 31 | 32 | fixture.Fill("//form") 33 | .With(fillInfo); 34 | 35 | fixture.Get.Value.From("#FirstName").ShouldBeEquivalentTo(fillInfo.FirstName); 36 | 37 | fixture.Get.Value.From("#LastName").ShouldBeEquivalentTo(fillInfo.LastName); 38 | 39 | fixture.Get.Value.From("#Email").ShouldBeEquivalentTo(fillInfo.Email); 40 | 41 | fixture.Get.Value.From("#Password").ShouldBeEquivalentTo(fillInfo.Password); 42 | 43 | fixture.Get.ValueAs().From("#Active").ShouldBeEquivalentTo(fillInfo.Active); 44 | 45 | fixture.Get.ValueAs().From("#OptionsCheckbox1").ShouldBeEquivalentTo(fillInfo.OptionsCheckbox1); 46 | 47 | fixture.Get.ValueAs().From("#OptionsCheckbox2").ShouldBeEquivalentTo(fillInfo.OptionsCheckbox2); 48 | 49 | fixture.Get.ValueAs().From("#OptionsRadios1").ShouldBeEquivalentTo(true); 50 | 51 | fixture.Get.ValueAs().From("#OptionsRadios2").ShouldBeEquivalentTo(false); 52 | 53 | fixture.Get.ValueAs().From("#AccountType").ShouldBeEquivalentTo(fillInfo.AccountType); 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.mstest.ExampleTests/PageObjectTests.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenQA.Selenium.Firefox; 3 | using SeleniumFixture.ExampleModels.PageObjects; 4 | 5 | namespace SeleniumFixture.mstest.ExampleTests 6 | { 7 | [TestClass] 8 | public class PageObjectTests 9 | { 10 | //[TestMethod] 11 | public void Fixture_DriveApp_ClicksAroundAndAutoFillsStuff() 12 | { 13 | using (var driver = new FirefoxDriver()) 14 | { 15 | var fixture = new Fixture(driver, "http://ipjohnson.github.io/SeleniumFixture/TestSite/"); 16 | 17 | var homePage = 18 | fixture.Navigate.To("Home.html"); 19 | 20 | var linkPage = homePage.Menu.ClickLinks(); 21 | 22 | var inputPage = linkPage.Menu.ClickInputForm(); 23 | 24 | var newUser = inputPage.AutoFill(); 25 | 26 | inputPage.Submit(); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.mstest.ExampleTests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SeleniumFixture.mstest.ExampleTests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SeleniumFixture.mstest.ExampleTests")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("a49ba2a6-2d7e-432a-920f-d589951f3345")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.mstest.ExampleTests/SeleniumFixture.mstest.ExampleTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | {E25C9041-3500-404C-8190-E9AC3E414FCD} 7 | Library 8 | Properties 9 | SeleniumFixture.mstest.ExampleTests 10 | SeleniumFixture.mstest.ExampleTests 11 | v4.5 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 10.0 15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 17 | False 18 | UnitTest 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | 29 | 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | 37 | 38 | 39 | ..\packages\FluentAssertions.4.5.0\lib\net45\FluentAssertions.dll 40 | True 41 | 42 | 43 | ..\packages\FluentAssertions.4.5.0\lib\net45\FluentAssertions.Core.dll 44 | True 45 | 46 | 47 | ..\..\..\Output\bin\AnyCPU\SeleniumFixture.dll 48 | 49 | 50 | ..\packages\SimpleFixture.1.2.0\lib\portable-net45+win+wpa81+wp80\SimpleFixture.dll 51 | True 52 | 53 | 54 | 55 | 56 | 57 | 58 | ..\packages\Selenium.WebDriver.2.53.0\lib\net40\WebDriver.dll 59 | True 60 | 61 | 62 | ..\packages\Selenium.Support.2.53.0\lib\net40\WebDriver.Support.dll 63 | True 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | {0734547e-d92c-4338-b8f4-1bb1b4289504} 87 | SeleniumFixture.ExampleModels 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | False 98 | 99 | 100 | False 101 | 102 | 103 | False 104 | 105 | 106 | False 107 | 108 | 109 | 110 | 111 | 112 | 113 | 120 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.mstest.ExampleTests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.xUnit.ExampleTests/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.xUnit.ExampleTests/AssemblyAttributes.cs: -------------------------------------------------------------------------------- 1 | using SeleniumFixture.xUnit; 2 | 3 | [assembly: ChromeDriver(Shared = true), FirefoxDriver(Shared = true)] -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.xUnit.ExampleTests/AutoFillTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using FluentAssertions; 7 | 8 | namespace SeleniumFixture.xUnit.ExampleTests 9 | { 10 | public class AutoFillTests 11 | { 12 | /// 13 | /// Test navigates to the input form and auto fills the form. 14 | /// Runs against Chrome, Firefox and Internet Explorer 15 | /// 16 | /// populated fixture 17 | //[SeleniumTheory] 18 | public void Fixture_FillForm_PopulatesCorrectly(Fixture fixture) 19 | { 20 | fixture.Navigate.To("http://ipjohnson.github.io/SeleniumFixture/TestSite/InputForm.html"); 21 | 22 | fixture.AutoFill("//form"); 23 | 24 | fixture.Get.Value.From("#FirstName").All(char.IsLetter).Should().BeTrue(); 25 | 26 | fixture.Get.Value.From("#LastName").All(char.IsLetter).Should().BeTrue(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.xUnit.ExampleTests/DataAttributeTets.cs: -------------------------------------------------------------------------------- 1 | using FluentAssertions; 2 | using SeleniumFixture.ExampleModels.PageObjects; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using Xunit; 9 | 10 | namespace SeleniumFixture.xUnit.ExampleTests 11 | { 12 | public class DataAttributeTets 13 | { 14 | /// 15 | /// Test that page object is created correctly and that InlineData is correctly populated into variables 16 | /// 17 | /// page object from initialization attribute 18 | /// Hello string 19 | /// 5 value 20 | [SeleniumTheory] 21 | [InlineData("Hello",5)] 22 | [InitializeToInputForm] 23 | public void Fixture_InlineData_CorrectDataPopulated(InputPage inputPage, string helloString, int intValue) 24 | { 25 | helloString.Should().Be("Hello"); 26 | 27 | intValue.Should().Be(5); 28 | 29 | inputPage.AutoFill(); 30 | 31 | inputPage.Get.Value.From("#FirstName").All(char.IsLetter).Should().BeTrue(); 32 | 33 | inputPage.Get.Value.From("#LastName").All(char.IsLetter).Should().BeTrue(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.xUnit.ExampleTests/FillTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using FluentAssertions; 7 | using OpenQA.Selenium; 8 | 9 | namespace SeleniumFixture.xUnit.ExampleTests 10 | { 11 | public class FillTests 12 | { 13 | [SeleniumTheory] 14 | [ChromeDriver] 15 | [FirefoxDriver] 16 | public void Fixture_FillForm_PopulatesCorrectly(Fixture fixture) 17 | { 18 | fixture.Navigate.To("http://ipjohnson.github.io/SeleniumFixture/TestSite/InputForm.html"); 19 | 20 | var fillInfo = new 21 | { 22 | FirstName = "Sterling", 23 | LastName = "Archer", 24 | Email = "sterling.archer@spy.gov", 25 | Password = "HelloWorld1!", 26 | Active = true, 27 | OptionsCheckbox1 = false, 28 | OptionsCheckbox2 = true, 29 | Gender = "Male", 30 | AccountType = "SuperAdmin" 31 | }; 32 | 33 | fixture.Fill("//form") 34 | .With(fillInfo); 35 | 36 | fixture.Get.Value.From("#FirstName").Should().Be(fillInfo.FirstName); 37 | 38 | fixture.Get.Value.From("#LastName").Should().Be(fillInfo.LastName); 39 | 40 | fixture.Get.Value.From("#Email").Should().Be(fillInfo.Email); 41 | 42 | fixture.Get.Value.From("#Password").Should().Be(fillInfo.Password); 43 | 44 | fixture.Get.ValueAs().From("#Active").Should().Be(fillInfo.Active); 45 | 46 | fixture.Get.ValueAs().From("#OptionsCheckbox1").Should().Be(fillInfo.OptionsCheckbox1); 47 | 48 | fixture.Get.ValueAs().From("#OptionsCheckbox2").Should().Be(fillInfo.OptionsCheckbox2); 49 | 50 | fixture.Get.ValueAs().From("#OptionsRadios1").Should().Be(true); 51 | 52 | fixture.Get.ValueAs().From("#OptionsRadios2").Should().Be(false); 53 | 54 | fixture.Get.ValueAs().From("#AccountType").Should().Be(fillInfo.AccountType); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.xUnit.ExampleTests/InitializeTests.cs: -------------------------------------------------------------------------------- 1 | using FluentAssertions; 2 | using SeleniumFixture.ExampleModels.PageObjects; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace SeleniumFixture.xUnit.ExampleTests 10 | { 11 | public class InitializeTests 12 | { 13 | /// 14 | /// Test case that uses attribute to navigate to the input form 15 | /// then autofills the page then tests that the first and last names are all letters 16 | /// 17 | /// Page object returned from InitializeToInputForm 18 | [SeleniumTheory] 19 | [InitializeToInputForm] 20 | public void Fixture_Initialize_ToInputForm(InputPage inputPage) 21 | { 22 | inputPage.AutoFill(); 23 | 24 | inputPage.Get.Value.From("#FirstName").All(char.IsLetter).Should().BeTrue(); 25 | 26 | inputPage.Get.Value.From("#LastName").All(char.IsLetter).Should().BeTrue(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.xUnit.ExampleTests/InitializeToHomePageAttribute.cs: -------------------------------------------------------------------------------- 1 | using SeleniumFixture.ExampleModels.PageObjects; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace SeleniumFixture.xUnit.ExampleTests 10 | { 11 | public class InitializeToHomePageAttribute : Attribute, IFixtureInitializationAttribute 12 | { 13 | public object Initialize(MethodInfo testMethod, Fixture fixture) 14 | { 15 | return fixture.Navigate.To("Home.html"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.xUnit.ExampleTests/InitializeToInputFormAttribute.cs: -------------------------------------------------------------------------------- 1 | using SeleniumFixture.ExampleModels.PageObjects; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace SeleniumFixture.xUnit.ExampleTests 10 | { 11 | public class InitializeToInputFormAttribute : Attribute, IFixtureInitializationAttribute 12 | { 13 | public object Initialize(MethodInfo testMethod, Fixture fixture) 14 | { 15 | fixture.Navigate.To("http://ipjohnson.github.io/SeleniumFixture/TestSite/InputForm.html"); 16 | 17 | return fixture.Yields(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.xUnit.ExampleTests/InternetExplorerOptionsAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using OpenQA.Selenium.IE; 8 | 9 | [assembly: SeleniumFixture.xUnit.ExampleTests.InternetExplorerOptions] 10 | 11 | namespace SeleniumFixture.xUnit.ExampleTests 12 | { 13 | 14 | public class InternetExplorerOptionsAttribute : xUnit.InternetExplorerOptionsAttribute 15 | { 16 | public override InternetExplorerOptions ProvideOptions(MethodInfo methodInfo) 17 | { 18 | return new InternetExplorerOptions { EnableNativeEvents = false }; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.xUnit.ExampleTests/MicrosoftWebDriver.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ipjohnson/SeleniumFixture/5003f1a67e8165ab1fd72007be095a451b3b428f/Examples/SeleniumFixture.ExampleTests/SeleniumFixture.xUnit.ExampleTests/MicrosoftWebDriver.exe -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.xUnit.ExampleTests/PageObjectTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using SeleniumFixture.ExampleModels.PageObjects; 7 | using Xunit; 8 | 9 | namespace SeleniumFixture.xUnit.ExampleTests 10 | { 11 | public class PageObjectTests 12 | { 13 | [SeleniumTheory] 14 | public void Fixture_DriveApp_ClicksAroundAndAutoFillsStuff(Fixture fixture) 15 | { 16 | var homePage = fixture.Navigate.To("Home.html"); 17 | 18 | var linkPage = homePage.Menu.ClickLinks(); 19 | 20 | var inputPage = linkPage.Menu.ClickInputForm(); 21 | 22 | var newUser = inputPage.AutoFill(); 23 | 24 | inputPage.Submit(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.xUnit.ExampleTests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SeleniumFixture.xUnit.ExampleTests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SeleniumFixture.xUnit.ExampleTests")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("f6cf72ee-d452-4e38-872b-0fd54b665cbf")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.xUnit.ExampleTests/SeleniumFixture.xUnit.ExampleTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {1058E28E-027E-4650-8FCB-6D88C30613ED} 9 | Library 10 | Properties 11 | SeleniumFixture.xUnit.ExampleTests 12 | SeleniumFixture.xUnit.ExampleTests 13 | v4.5 14 | 512 15 | 16 | 17 | 18 | 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | ..\packages\FluentAssertions.4.5.0\lib\net45\FluentAssertions.dll 38 | True 39 | 40 | 41 | ..\packages\FluentAssertions.4.5.0\lib\net45\FluentAssertions.Core.dll 42 | True 43 | 44 | 45 | ..\..\..\Output\bin\AnyCPU\SeleniumFixture.dll 46 | 47 | 48 | ..\..\..\Output\bin\AnyCPU\SeleniumFixture.xUnit.dll 49 | 50 | 51 | ..\packages\SimpleFixture.1.2.0\lib\portable-net45+win+wpa81+wp80\SimpleFixture.dll 52 | True 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | ..\packages\Selenium.WebDriver.2.53.0\lib\net40\WebDriver.dll 64 | True 65 | 66 | 67 | ..\packages\Selenium.Support.2.53.0\lib\net40\WebDriver.Support.dll 68 | True 69 | 70 | 71 | ..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll 72 | True 73 | 74 | 75 | ..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll 76 | True 77 | 78 | 79 | ..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll 80 | True 81 | 82 | 83 | ..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll 84 | True 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | {0734547e-d92c-4338-b8f4-1bb1b4289504} 106 | SeleniumFixture.ExampleModels 107 | 108 | 109 | 110 | 111 | chromedriver.exe 112 | PreserveNewest 113 | 114 | 115 | IEDriverServer.exe 116 | PreserveNewest 117 | 118 | 119 | PreserveNewest 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 129 | 130 | 131 | 132 | 139 | -------------------------------------------------------------------------------- /Examples/SeleniumFixture.ExampleTests/SeleniumFixture.xUnit.ExampleTests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /License.md: -------------------------------------------------------------------------------- 1 | ###Microsoft Public License (MS-PL) 2 | 3 | This license governs use of the accompanying software. If you use the software, you 4 | accept this license. If you do not accept the license, do not use the software. 5 | 6 | 1. Definitions 7 | The terms "reproduce," "reproduction," "derivative works," and "distribution" have the 8 | same meaning here as under U.S. copyright law. 9 | A "contribution" is the original software, or any additions or changes to the software. 10 | A "contributor" is any person that distributes its contribution under this license. 11 | "Licensed patents" are a contributor's patent claims that read directly on its contribution. 12 | 13 | 2. Grant of Rights 14 | (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create. 15 | (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software. 16 | 17 | 3. Conditions and Limitations 18 | (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. 19 | (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically. 20 | (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software. 21 | (D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license. 22 | (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SeleniumFixture 2 | =============== 3 | Is a companion library for Selenium C# that provides functionality to easily populate forms, navigate pages and construct PageObjects. 4 | 5 | ```C# 6 | var driver = new FirefoxDriver(); 7 | 8 | var fixture = new Fixture(driver); 9 | 10 | fixture.Navigate.To("http://ipjohnson.github.io/SeleniumFixture/TestSite/InputForm.html"); 11 | 12 | fixture.AutoFill("//form"); 13 | ``` 14 | 15 | ### Click & DoubleClick 16 | Provides short hand for clicking and double clicking elements 17 | 18 | ```C# 19 | // click button with id someButton 20 | fixture.Click("#someButton"); 21 | 22 | // click button of type submit 23 | fixture.Click("button[type='submit']"); 24 | 25 | // DoubleClick any button that has the html class 'some-class' 26 | fixture.DoubleClick("button.some-class", ClickMode.Any); 27 | ``` 28 | 29 | ### Fill 30 | Fill allows you to easily populate form elements with a given set of values. Currently textboxs, radiobutton, checkbox, select and textarea are supported. 31 | 32 | ```C# 33 | // Navigate to page and fill out form 34 | fixture.Navigate.To("http://ipjohnson.github.io/SeleniumFixture/TestSite/InputForm.html"); 35 | 36 | fixture.Fill("//form") 37 | .With(new 38 | { 39 | FirstName = "Sterling", 40 | LastName = "Archer", 41 | Active = true, 42 | Gender = "Male" 43 | }) 44 | .ThenSubmit(); 45 | 46 | // fill all elements with the html class some-class with the value 1111 47 | fixture.Fill(".some-class").With(1111); 48 | ``` 49 | 50 | ### AutoFill 51 | Sometimes its useful to populate a form with random data. The AutoFill method can be used to fill a html input elements. 52 | 53 | ```C# 54 | // AutoFill form element 55 | fixture.AutoFill("//form"); 56 | 57 | // AutoFill form but use Bob to fill the FirstName field 58 | fixture.AutoFill("//form", seedWith: new { FirstName = "Bob"}); 59 | 60 | // Find an element with the id #someDiv and populate all child input and select elements 61 | fixture.AutoFill("#someDiv"); 62 | ``` 63 | 64 | ### Wait 65 | It's useful to wait for certain things to happen on page, the Wait API provides a number of helpful wait methods for things like ajax or form elements to exists. 66 | 67 | ```C# 68 | // wait for ajax calls to finish 69 | fixture.Wait.ForAjax(); 70 | 71 | // wait for #someElement to be present on the page 72 | fixture.Wait.ForElement("#someElement"); 73 | 74 | // long hand for waiting for element 20 seconds 75 | fixture.Wait.Until(i => i.CheckForElement("#someElement"), 20); 76 | ``` 77 | 78 | ### PageObject Pattern 79 | The [PageObject](http://martinfowler.com/bliki/PageObject.html) pattern is very useful and SeleniumFixture fully supports using PageObject classes to help package logic. [SimpleFixture](https://github.com/ipjohnson/SimpleFixture) is used to create instances of PageObjects allowing for very complex object. For example, injecting constructor parameters , properties (using ImportAttribute), and etc. 80 | 81 | ```C# 82 | var driver = new FirefoxDriver(); 83 | 84 | var fixture = new Fixture(driver, "http://ipjohnson.github.io/SeleniumFixture/TestSite/"); 85 | 86 | var formPage = fixture.Navigate.To("InputForm.html"); 87 | 88 | formPage.FillOutForm(); 89 | 90 | public class FormPage 91 | { 92 | public void FillOutForm() 93 | { 94 | I.Fill("//form").With(new { FirstName = "Sterling", LastName = "Archer" }); 95 | } 96 | 97 | protected IActionProvider I { get; private set; } 98 | } 99 | ``` 100 | 101 | ### IActionProvider Property 102 | The IActionProvider allows a page object to import the functionality of the Fixture into a local property. When PageObjects are constructed any IActionProvider property with a setter will be Populated with an instance of IActionProvider. Usually this property is named I 103 | 104 | ```C# 105 | I.Fill("//form").With(new { FirstName = "Sterling" }); 106 | 107 | I.Click("#submitButton").Wait.ForAjax().Then.Yields(); 108 | ``` 109 | 110 | ### Validate 111 | PageObjects can validate themselves upon creation one of two ways. You can either have a method name "Validate" or a property called "Validate" that is an Action. Either choice will be called once the page object has been created. 112 | 113 | ```C# 114 | public class HomePage 115 | { 116 | public HomePage() 117 | { 118 | Validate = () => I.Get.PageTitle.Should().Be("Home"); 119 | } 120 | 121 | protected Action Validate { get; private set; } 122 | 123 | protected IActionProvider I { get; private set; } 124 | } 125 | ``` 126 | 127 | ### Yields 128 | Yields is how you can create new PageObject instances. It takes the type of page as the generic parameter and will instantiate a new instance of T. Note: your page types do not have to inherit from any particular type, you could use structs if you felt so inclined. 129 | 130 | ```C# 131 | // click the submit button and yield a new HomePage object 132 | I.Click("#submitButton").Yields(); 133 | 134 | // click the link Some Text then yield a new OtherPage object 135 | // and pass the value 5 into the constructor parameter someParam 136 | I.Click(By.LinkText("Some Text")).Yields(constraints: new { someParam = 5 }); 137 | 138 | public class OtherPage 139 | { 140 | public OtherPage(int someParam) 141 | { 142 | Validate = () => I.Get.PageTitle.Should().EndWith(someParam.ToString()); 143 | } 144 | 145 | private Action Validate { get; set; } 146 | 147 | private IActionProvider I { get; set; } 148 | } 149 | ``` 150 | 151 | Note: Should() is part of [Fluent Assertions](https://github.com/dennisdoomen/fluentassertions). 152 | 153 | ### xUnit support 154 | [xUnit 2.0](https://github.com/xunit/xunit) is a very extensible testing framework that SeleniumFixture.xUnit provides support for out of the box. Currently there are a set of attributes that make setup and tear down of IWebDrivers and Fixture easier. You can customize initialization and finalization of WebDriver & Fixtures. It also supports creation of PageObjects as well as xUnit DataAttributes 155 | 156 | ```C# 157 | public class AutoFillTests 158 | { 159 | /// 160 | /// Test navigates to the input form and auto fills the form. 161 | /// Runs against Chrome, Firefox and Internet Explorer 162 | /// 163 | /// populated fixture 164 | [SeleniumTheory] 165 | [ChromeDriver] 166 | [FirefoxDriver] 167 | public void Fixture_FillForm_PopulatesCorrectly(Fixture fixture) 168 | { 169 | fixture.Navigate.To("http://ipjohnson.github.io/SeleniumFixture/TestSite/InputForm.html"); 170 | 171 | fixture.AutoFill("//form"); 172 | 173 | fixture.Get.Value.From("#FirstName").All(char.IsLetter).Should().BeTrue(); 174 | 175 | fixture.Get.Value.From("#LastName").All(char.IsLetter).Should().BeTrue(); 176 | } 177 | 178 | /// 179 | /// Test case that uses attribute to navigate to the input form 180 | /// then autofills the page then tests that the first and last names are all letters 181 | /// 182 | /// Page object returned from InitializeToInputForm 183 | [SeleniumTheory] 184 | [ChromeDriver] 185 | [FirefoxDriver] 186 | [InitializeToInputForm] 187 | public void Fixture_Initialize_ToInputForm(InputPage inputPage) 188 | { 189 | inputPage.AutoFill(); 190 | 191 | inputPage.Get.Value.From("#FirstName").All(char.IsLetter).Should().BeTrue(); 192 | 193 | inputPage.Get.Value.From("#LastName").All(char.IsLetter).Should().BeTrue(); 194 | } 195 | 196 | /// 197 | /// Test that page object is created correctly and that InlineData is correctly populated into variables 198 | /// 199 | /// page object from initialization attribute 200 | /// Hello string 201 | /// 5 value 202 | [SeleniumTheory] 203 | [ChromeDriver] 204 | [FirefoxDriver] 205 | [InlineData("Hello",5)] 206 | [InitializeToInputForm] 207 | public void Fixture_InlineData_CorrectDataPopulated(InputPage inputPage, string helloString, int intValue) 208 | { 209 | helloString.Should().Be("Hello"); 210 | 211 | intValue.Should().Be(5); 212 | 213 | inputPage.AutoFill(); 214 | 215 | inputPage.Get.Value.From("#FirstName").All(char.IsLetter).Should().BeTrue(); 216 | 217 | inputPage.Get.Value.From("#LastName").All(char.IsLetter).Should().BeTrue(); 218 | } 219 | } 220 | ``` 221 | 222 | Note: because each driver has slightly different behavior your tests and PageObjects need to be a little bit more robust. 223 | 224 | -------------------------------------------------------------------------------- /nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ipjohnson/SeleniumFixture/5003f1a67e8165ab1fd72007be095a451b3b428f/nuget/NuGet.exe -------------------------------------------------------------------------------- /src/SeleniumFixture.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27004.2005 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeleniumFixture", "SeleniumFixture\SeleniumFixture.csproj", "{9EB00E94-F1DB-40E4-A131-4B28B347785F}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeleniumFixture.xUnit", "SeleniumFixture.xUnit\SeleniumFixture.xUnit.csproj", "{0714F5E0-B98A-44BC-89CC-700A346406AC}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {9EB00E94-F1DB-40E4-A131-4B28B347785F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {9EB00E94-F1DB-40E4-A131-4B28B347785F}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {9EB00E94-F1DB-40E4-A131-4B28B347785F}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {9EB00E94-F1DB-40E4-A131-4B28B347785F}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {0714F5E0-B98A-44BC-89CC-700A346406AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {0714F5E0-B98A-44BC-89CC-700A346406AC}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {0714F5E0-B98A-44BC-89CC-700A346406AC}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {0714F5E0-B98A-44BC-89CC-700A346406AC}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {8FFD8A5B-8698-4C9A-9546-13DD9C5295BB} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit.dnx/global.json: -------------------------------------------------------------------------------- 1 | { 2 | "projects": [ 3 | "wrap" 4 | ] 5 | } -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/ChromeDriverAttribute.cs: -------------------------------------------------------------------------------- 1 | using OpenQA.Selenium; 2 | using OpenQA.Selenium.Chrome; 3 | using SeleniumFixture.xUnit.Impl; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Reflection; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | 11 | namespace SeleniumFixture.xUnit 12 | { 13 | public class ChromeDriverAttribute : WebDriverAttribute 14 | { 15 | public override IEnumerable GetDrivers(MethodInfo testMethod) 16 | { 17 | yield return GetOrCreateWebDriver(testMethod, () => CreateWebDriver(testMethod)); 18 | } 19 | 20 | public override void ReturnDriver(MethodInfo testMethod, IWebDriver driver) 21 | { 22 | ReturnDriver(testMethod, driver as ChromeDriver); 23 | } 24 | 25 | public static ChromeDriver CreateWebDriver(MethodInfo testMethod) 26 | { 27 | ChromeDriver driver = null; 28 | 29 | var chromeDriverProvider = ReflectionHelper.GetAttribute(testMethod); 30 | 31 | if (chromeDriverProvider != null) 32 | { 33 | driver = chromeDriverProvider.ProvideDriver(testMethod); 34 | } 35 | else 36 | { 37 | var optionsProvider = ReflectionHelper.GetAttribute(testMethod); 38 | 39 | driver = new ChromeDriver(optionsProvider != null ? optionsProvider.ProvideOptions(testMethod) : new ChromeOptions()); 40 | } 41 | 42 | InitializeDriver(testMethod, driver); 43 | 44 | return driver; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/ChromeDriverProviderAttribute.cs: -------------------------------------------------------------------------------- 1 | using OpenQA.Selenium.Chrome; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace SeleniumFixture.xUnit 10 | { 11 | public abstract class ChromeDriverProviderAttribute : Attribute 12 | { 13 | public abstract ChromeDriver ProvideDriver(MethodInfo testMethod); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/ChromeOptionsAttribute.cs: -------------------------------------------------------------------------------- 1 | using OpenQA.Selenium.Chrome; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace SeleniumFixture.xUnit 10 | { 11 | public abstract class ChromeOptionsAttribute : Attribute 12 | { 13 | public abstract ChromeOptions ProvideOptions(MethodInfo testMethod); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/CustomTheoryAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Xunit; 7 | using Xunit.Abstractions; 8 | using Xunit.Sdk; 9 | 10 | namespace SeleniumFixture.xUnit 11 | { 12 | public class CustomTheoryDiscoverer : IXunitTestCaseDiscoverer 13 | { 14 | readonly IMessageSink diagnosticMessageSink; 15 | 16 | public CustomTheoryDiscoverer(IMessageSink diagnosticMessageSink) 17 | { 18 | this.diagnosticMessageSink = diagnosticMessageSink; 19 | } 20 | 21 | public IEnumerable Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute) 22 | { 23 | yield return new XunitTheoryTestCase(diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod); 24 | } 25 | } 26 | 27 | 28 | [XunitTestCaseDiscoverer("SeleniumFixture.xUnit.CustomTheoryDiscoverer", "SeleniumFixture.xUnit")] 29 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] 30 | public class CustomTheoryAttribute : TheoryAttribute 31 | { 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/EdgeDriverAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using OpenQA.Selenium; 8 | using OpenQA.Selenium.Edge; 9 | using SeleniumFixture.xUnit.Impl; 10 | 11 | namespace SeleniumFixture.xUnit 12 | { 13 | public class EdgeDriverAttribute : WebDriverAttribute 14 | { 15 | public override IEnumerable GetDrivers(MethodInfo testMethod) 16 | { 17 | yield return GetOrCreateWebDriver(testMethod, () => CreateWebDriver(testMethod)); 18 | } 19 | 20 | public override void ReturnDriver(MethodInfo testMethod, IWebDriver driver) 21 | { 22 | ReturnDriver(testMethod, driver as EdgeDriver); 23 | } 24 | 25 | public static EdgeDriver CreateWebDriver(MethodInfo testMethod) 26 | { 27 | EdgeDriver driver = null; 28 | 29 | var chromeDriverProvider = ReflectionHelper.GetAttribute(testMethod); 30 | 31 | if (chromeDriverProvider != null) 32 | { 33 | driver = chromeDriverProvider.ProvideDriver(testMethod); 34 | } 35 | else 36 | { 37 | var optionsProvider = ReflectionHelper.GetAttribute(testMethod); 38 | 39 | driver = new EdgeDriver(optionsProvider != null ? optionsProvider.ProvideOptions(testMethod) : new EdgeOptions()); 40 | } 41 | 42 | InitializeDriver(testMethod, driver); 43 | 44 | return driver; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/EdgeDriverProviderAttribute.cs: -------------------------------------------------------------------------------- 1 | using OpenQA.Selenium.Edge; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace SeleniumFixture.xUnit 10 | { 11 | public abstract class EdgeDriverProviderAttribute : Attribute 12 | { 13 | public abstract EdgeDriver ProvideDriver(MethodInfo testMethod); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/EdgeOptionsAttribute.cs: -------------------------------------------------------------------------------- 1 | using OpenQA.Selenium.Edge; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace SeleniumFixture.xUnit 10 | { 11 | public abstract class EdgeOptionsAttribute : Attribute 12 | { 13 | public abstract EdgeOptions ProvideOptions(MethodInfo method); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/FireFoxDriverAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using OpenQA.Selenium; 9 | using OpenQA.Selenium.Firefox; 10 | using OpenQA.Selenium.Remote; 11 | using SeleniumFixture.xUnit.Impl; 12 | using Xunit; 13 | using Xunit.Abstractions; 14 | using Xunit.Sdk; 15 | 16 | namespace SeleniumFixture.xUnit 17 | { 18 | public class FirefoxDriverAttribute : WebDriverAttribute 19 | { 20 | public override IEnumerable GetDrivers(MethodInfo testMethod) 21 | { 22 | yield return GetOrCreateWebDriver(testMethod, () => CreateWebDriver(testMethod)); 23 | } 24 | 25 | public override void ReturnDriver(MethodInfo testMethod, IWebDriver driver) 26 | { 27 | ReturnDriver(testMethod, driver as FirefoxDriver); 28 | } 29 | 30 | public static FirefoxDriver CreateWebDriver(MethodInfo testMethod) 31 | { 32 | FirefoxDriver driver = null; 33 | 34 | var firefoxDriverProvider = ReflectionHelper.GetAttribute(testMethod); 35 | 36 | if (firefoxDriverProvider != null) 37 | { 38 | driver = firefoxDriverProvider.ProvideDriver(testMethod); 39 | } 40 | else 41 | { 42 | var provider = ReflectionHelper.GetAttribute(testMethod); 43 | 44 | 45 | driver = new FirefoxDriver(provider != null ? 46 | provider.CreateProfile(testMethod) : 47 | new FirefoxProfile()); 48 | } 49 | 50 | InitializeDriver(testMethod, driver); 51 | 52 | return driver; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/FireFoxProfileAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using OpenQA.Selenium.Firefox; 8 | 9 | namespace SeleniumFixture.xUnit 10 | { 11 | public abstract class FirefoxProfileAttribute : Attribute 12 | { 13 | public abstract FirefoxProfile CreateProfile(MethodInfo methodInfo); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/FirefoxDriverProviderAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using OpenQA.Selenium.Firefox; 8 | using Xunit.Abstractions; 9 | using Xunit.Sdk; 10 | 11 | namespace SeleniumFixture.xUnit 12 | { 13 | public abstract class FirefoxDriverProviderAttribute : Attribute 14 | { 15 | public abstract FirefoxDriver ProvideDriver(MethodInfo methodInfo); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/FixtureCreationAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using OpenQA.Selenium; 9 | using SeleniumFixture.xUnit.Impl; 10 | using Xunit.Abstractions; 11 | 12 | namespace SeleniumFixture.xUnit 13 | { 14 | public abstract class FixtureCreationAttribute : Attribute 15 | { 16 | public abstract Fixture CreateFixture(IWebDriver driver); 17 | 18 | public static Fixture GetNewFixture(IWebDriver driver, MethodInfo method) 19 | { 20 | FixtureCreationAttribute creationAttribute = ReflectionHelper.GetAttribute(method); 21 | 22 | if (creationAttribute != null) 23 | { 24 | return creationAttribute.CreateFixture(driver); 25 | } 26 | 27 | string baseAddress = null; 28 | 29 | #if !DNX 30 | baseAddress = ConfigurationManager.AppSettings["BaseAddress"]; 31 | #endif 32 | 33 | return new Fixture(driver,baseAddress); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/IFixtureFinalizerAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SeleniumFixture.xUnit 9 | { 10 | public interface IFixtureFinalizerAttribute 11 | { 12 | void IFixtureFinalizerAttribute(MethodInfo method, Fixture fixture); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/IFixtureInitializationAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SeleniumFixture.xUnit 9 | { 10 | /// 11 | /// Attributes that implement this interface can provide a IFixtureInitializer to initialize the fixture 12 | /// 13 | public interface IFixtureInitializationAttribute 14 | { 15 | /// 16 | /// Provide fixture initializer 17 | /// 18 | /// fixture 19 | /// 20 | object Initialize(MethodInfo testMethod, Fixture fixture); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/IWebDriverFinalizerAttribute.cs: -------------------------------------------------------------------------------- 1 | using OpenQA.Selenium; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace SeleniumFixture.xUnit 10 | { 11 | public interface IWebDriverFinalizerAttribute 12 | { 13 | void Finalize(MethodInfo method, IWebDriver driver); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/IWebDriverInitializationAttribute.cs: -------------------------------------------------------------------------------- 1 | using OpenQA.Selenium; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace SeleniumFixture.xUnit 10 | { 11 | public interface IWebDriverInitializationAttribute 12 | { 13 | void Initialize(MethodInfo method, IWebDriver driver); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/IWebDriverResetAttribute.cs: -------------------------------------------------------------------------------- 1 | using OpenQA.Selenium; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace SeleniumFixture.xUnit 10 | { 11 | public interface IWebDriverResetAttribute 12 | { 13 | void ResetWebDriver(MethodInfo testMethod, IWebDriver driver); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/Impl/ExceptionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SeleniumFixture.xUnit.Impl 9 | { 10 | static class ExceptionExtensions 11 | { 12 | const string RETHROW_MARKER = "$$RethrowMarker$$"; 13 | 14 | /// 15 | /// Rethrows an exception object without losing the existing stack trace information 16 | /// 17 | /// The exception to re-throw. 18 | /// 19 | /// For more information on this technique, see 20 | /// http://www.dotnetjunkies.com/WebLog/chris.taylor/archive/2004/03/03/8353.aspx. 21 | /// The remote_stack_trace string is here to support Mono. 22 | /// 23 | public static void RethrowWithNoStackTraceLoss(this Exception ex) 24 | { 25 | #if PLATFORM_NET35 26 | FieldInfo remoteStackTraceString = 27 | typeof(Exception).GetField("_remoteStackTraceString", BindingFlags.Instance | BindingFlags.NonPublic) ?? 28 | typeof(Exception).GetField("remote_stack_trace", BindingFlags.Instance | BindingFlags.NonPublic); 29 | 30 | remoteStackTraceString.SetValue(ex, ex.StackTrace + RETHROW_MARKER); 31 | throw ex; 32 | #else 33 | System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(ex).Throw(); 34 | #endif 35 | } 36 | 37 | /// 38 | /// Unwraps an exception to remove any wrappers, like . 39 | /// 40 | /// The exception to unwrap. 41 | /// The unwrapped exception. 42 | public static Exception Unwrap(this Exception ex) 43 | { 44 | while (true) 45 | { 46 | var tiex = ex as TargetInvocationException; 47 | if (tiex == null) 48 | return ex; 49 | 50 | ex = tiex.InnerException; 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/Impl/LongLivedMarshalByRefObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SeleniumFixture.xUnit.Impl 8 | { 9 | class LongLivedMarshalByRefObject 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/Impl/ReflectionHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SeleniumFixture.xUnit.Impl 9 | { 10 | public static class ReflectionHelper 11 | { 12 | public static T GetAttribute(MethodInfo methodInfo) where T : class 13 | { 14 | Attribute returnAttribute = methodInfo.GetCustomAttributes().FirstOrDefault(a => a is T) ?? 15 | (methodInfo.DeclaringType.GetCustomAttributes().FirstOrDefault(a => a is T) ?? 16 | methodInfo.DeclaringType.Assembly.GetCustomAttributes().FirstOrDefault(a => a is T)); 17 | 18 | return returnAttribute as T; 19 | } 20 | 21 | public static IEnumerable GetAttributes(MethodInfo methodInfo) where T : class 22 | { 23 | List returnList = new List(); 24 | 25 | returnList.AddRange(methodInfo.GetCustomAttributes().Where(a => a is T).Select(a => a as T)); 26 | 27 | if(returnList.Count == 0) 28 | { 29 | returnList.AddRange(methodInfo.DeclaringType.GetCustomAttributes().Where(a => a is T).Select(a => a as T)); 30 | } 31 | 32 | if(returnList.Count == 0) 33 | { 34 | returnList.AddRange(methodInfo.DeclaringType.Assembly.GetCustomAttributes().Where(a => a is T).Select(a => a as T)); 35 | } 36 | 37 | return returnList; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/Impl/SeleniumTheoryDiscoverer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Xunit.Abstractions; 8 | using Xunit.Sdk; 9 | 10 | namespace SeleniumFixture.xUnit.Impl 11 | { 12 | public class SeleniumTheoryDiscoverer : IXunitTestCaseDiscoverer 13 | { 14 | readonly IMessageSink diagnosticMessageSink; 15 | 16 | public const string ClassName = "SeleniumFixture.xUnit.Impl.SeleniumTheoryDiscoverer"; 17 | 18 | #if DNX 19 | public const string AssemblyName = "SeleniumFixture.xUnit.dnx"; 20 | #else 21 | public const string AssemblyName = "SeleniumFixture.xUnit"; 22 | #endif 23 | 24 | public SeleniumTheoryDiscoverer(IMessageSink diagnosticMessageSink) 25 | { 26 | this.diagnosticMessageSink = diagnosticMessageSink; 27 | } 28 | 29 | /// 30 | /// Creates a test case for a single row of data. By default, returns an instance of 31 | /// with the data row inside of it. 32 | /// 33 | /// The discovery options to be used. 34 | /// The test method the test cases belong to. 35 | /// The theory attribute attached to the test method. 36 | /// The row of data for this test case. 37 | /// The test case 38 | protected virtual IXunitTestCase CreateTestCaseForDataRow(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute, object[] dataRow) 39 | => new XunitTestCase(diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod, dataRow); 40 | 41 | /// 42 | /// Creates a test case for a skipped theory. By default, returns an instance of 43 | /// (which inherently discovers the skip reason via the fact attribute). 44 | /// 45 | /// The discovery options to be used. 46 | /// The test method the test cases belong to. 47 | /// The theory attribute attached to the test method. 48 | /// The skip reason that decorates . 49 | /// The test case 50 | protected virtual IXunitTestCase CreateTestCaseForSkip(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute, string skipReason) 51 | => new XunitTestCase(diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod); 52 | 53 | /// 54 | /// Creates a test case for the entire theory. This is used when one or more of the theory data items 55 | /// are not serializable, or if the user has requested to skip theory pre-enumeration. By default, 56 | /// returns an instance of , which performs the data discovery at runtime. 57 | /// 58 | /// The discovery options to be used. 59 | /// The test method the test cases belong to. 60 | /// The theory attribute attached to the test method. 61 | /// The test case 62 | protected virtual IXunitTestCase CreateTestCaseForTheory(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute) 63 | => new SeleniumTheoryTestCase(diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod); 64 | 65 | /// 66 | /// Creates a test case for a single row of data. By default, returns an instance of 67 | /// with the data row inside of it. 68 | /// 69 | /// If this method is overridden, the implementation will have to override otherwise 70 | /// the default behavior will look at the and the test case will not be skipped. 71 | /// The discovery options to be used. 72 | /// The test method the test cases belong to. 73 | /// The theory attribute attached to the test method. 74 | /// The row of data for this test case. 75 | /// The reason this test case is to be skipped 76 | /// The test case 77 | protected virtual IXunitTestCase CreateTestCaseForSkippedDataRow(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute, object[] dataRow, string skipReason) 78 | => new XunitSkippedDataRowTestCase(diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod, skipReason, dataRow); 79 | 80 | 81 | public IEnumerable Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute) 82 | { 83 | try 84 | { 85 | var skipReason = theoryAttribute.GetNamedArgument("Skip"); 86 | if (skipReason != null) 87 | return new[] { CreateTestCaseForSkip(discoveryOptions, testMethod, theoryAttribute, skipReason) }; 88 | 89 | return new[] { CreateTestCaseForTheory(discoveryOptions, testMethod, theoryAttribute) }; 90 | } 91 | catch(Exception exp) 92 | { 93 | diagnosticMessageSink.OnMessage(new DiagnosticMessage($"Exception thrown during theory discovery on '{testMethod.TestClass.Class.Name}.{testMethod.Method.Name}'; falling back to single test case.{Environment.NewLine}{exp}")); 94 | } 95 | 96 | return new IXunitTestCase[] { }; 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/Impl/SeleniumTheoryTestCase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using Xunit.Abstractions; 9 | using Xunit.Sdk; 10 | 11 | namespace SeleniumFixture.xUnit.Impl 12 | { 13 | public class SeleniumTheoryTestCase : XunitTheoryTestCase 14 | { 15 | [EditorBrowsable(EditorBrowsableState.Never)] 16 | [Obsolete("Called by the de-serializer", error: true)] 17 | public SeleniumTheoryTestCase() { } 18 | 19 | public SeleniumTheoryTestCase(IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, ITestMethod testMethod) 20 | : base(diagnosticMessageSink, defaultMethodDisplay, testMethod) 21 | { 22 | } 23 | 24 | public override Task RunAsync(IMessageSink diagnosticMessageSink, IMessageBus messageBus, object[] constructorArguments, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource) 25 | { 26 | return new SeleniumTheoryTestCaseRunner(this, DisplayName, SkipReason, constructorArguments, diagnosticMessageSink, messageBus, aggregator, cancellationTokenSource).RunAsync(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/Impl/SerializationHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SeleniumFixture.xUnit.Impl 9 | { 10 | static class SerializationHelper 11 | { 12 | /// 13 | /// Converts an assembly name + type name into a object. 14 | /// 15 | /// The assembly name. 16 | /// The type name. 17 | /// The instance of the , if available; null, otherwise. 18 | public static Type GetType(string assemblyName, string typeName) 19 | { 20 | #if XUNIT_FRAMEWORK // This behavior is only for v2, and only done on the remote app domain side 21 | if (assemblyName.EndsWith(ExecutionHelper.SubstitutionToken, StringComparison.OrdinalIgnoreCase)) 22 | assemblyName = assemblyName.Substring(0, assemblyName.Length - ExecutionHelper.SubstitutionToken.Length + 1) + ExecutionHelper.PlatformSuffix; 23 | #endif 24 | 25 | #if PLATFORM_DOTNET 26 | Assembly assembly = null; 27 | try 28 | { 29 | // Make sure we only use the short form 30 | var an = new AssemblyName(assemblyName); 31 | assembly = Assembly.Load(new AssemblyName { Name = an.Name, Version = an.Version }); 32 | 33 | } 34 | catch { } 35 | #else 36 | // Support both long name ("assembly, version=x.x.x.x, etc.") and short name ("assembly") 37 | var assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.FullName == assemblyName || a.GetName().Name == assemblyName); 38 | if (assembly == null) 39 | { 40 | try 41 | { 42 | assembly = Assembly.Load(assemblyName); 43 | } 44 | catch { } 45 | } 46 | #endif 47 | 48 | if (assembly == null) 49 | return null; 50 | 51 | return assembly.GetType(typeName); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/Impl/TestCaseRunner.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SeleniumFixture.xUnit.Impl 8 | { 9 | class TestCaseRunner 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/Impl/TestMethodTestCase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SeleniumFixture.xUnit.Impl 8 | { 9 | class TestMethodTestCase 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/Impl/XunitSkippedDataRowTestCase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Xunit.Abstractions; 8 | using Xunit.Sdk; 9 | 10 | namespace SeleniumFixture.xUnit.Impl 11 | { 12 | internal class XunitSkippedDataRowTestCase : XunitTestCase 13 | { 14 | readonly string skipReason; 15 | 16 | /// 17 | [EditorBrowsable(EditorBrowsableState.Never)] 18 | [Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] 19 | public XunitSkippedDataRowTestCase() 20 | { 21 | } 22 | 23 | /// 24 | /// Initializes a new instance of the class. 25 | /// 26 | /// The message sink used to send diagnostic messages 27 | /// Default method display to use (when not customized). 28 | /// The test method this test case belongs to. 29 | /// The reason that this test case will be skipped 30 | /// The arguments for the test method. 31 | public XunitSkippedDataRowTestCase(IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, ITestMethod testMethod, string skipReason, object[] testMethodArguments = null) : 32 | base(diagnosticMessageSink, defaultMethodDisplay, testMethod, testMethodArguments) 33 | { 34 | this.skipReason = skipReason; 35 | } 36 | 37 | /// 38 | /// Gets the skip reason for the test case. Overrides the default to use the skip reason from the 39 | /// value found during discovery 40 | /// 41 | /// The fact attribute the decorated the test case. 42 | /// The skip reason, if skipped; null, otherwise. 43 | protected override string GetSkipReason(IAttributeInfo factAttribute) 44 | { 45 | return skipReason; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/InternetExplorerDriverAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using OpenQA.Selenium; 8 | using OpenQA.Selenium.Chrome; 9 | using OpenQA.Selenium.IE; 10 | using SeleniumFixture.xUnit.Impl; 11 | using Xunit.Sdk; 12 | 13 | namespace SeleniumFixture.xUnit 14 | { 15 | public class InternetExplorerDriverAttribute : WebDriverAttribute 16 | { 17 | 18 | public override IEnumerable GetDrivers(MethodInfo testMethod) 19 | { 20 | yield return GetOrCreateWebDriver(testMethod, () => CreateWebDriver(testMethod)); 21 | } 22 | 23 | public override void ReturnDriver(MethodInfo testMethod, IWebDriver driver) 24 | { 25 | ReturnDriver(testMethod, driver as InternetExplorerDriver); 26 | } 27 | 28 | public static InternetExplorerDriver CreateWebDriver(MethodInfo testMethod) 29 | { 30 | InternetExplorerDriver driver = null; 31 | 32 | var chromeDriverProvider = ReflectionHelper.GetAttribute(testMethod); 33 | 34 | if (chromeDriverProvider != null) 35 | { 36 | driver = chromeDriverProvider.ProvideDriver(testMethod); 37 | } 38 | else 39 | { 40 | var optionsProvider = ReflectionHelper.GetAttribute(testMethod); 41 | 42 | driver = new InternetExplorerDriver(optionsProvider != null ? 43 | optionsProvider.ProvideOptions(testMethod) : 44 | new InternetExplorerOptions { IgnoreZoomLevel = true }); 45 | } 46 | 47 | InitializeDriver(testMethod, driver); 48 | 49 | return driver; 50 | } 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/InternetExplorerDriverProviderAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using OpenQA.Selenium.IE; 8 | using Xunit.Abstractions; 9 | 10 | namespace SeleniumFixture.xUnit 11 | { 12 | public abstract class InternetExplorerDriverProviderAttribute : Attribute 13 | { 14 | public abstract InternetExplorerDriver ProvideDriver(MethodInfo methodInfo); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/InternetExplorerOptionsAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using OpenQA.Selenium.IE; 8 | 9 | namespace SeleniumFixture.xUnit 10 | { 11 | public abstract class InternetExplorerOptionsAttribute : Attribute 12 | { 13 | public abstract InternetExplorerOptions ProvideOptions(MethodInfo methodInfo); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SeleniumFixture.xUnit")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SeleniumFixture.xUnit")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("ff8d7b1b-acd3-4db9-9ab4-af0c618298ba")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/RemoteDriverAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using OpenQA.Selenium; 8 | using OpenQA.Selenium.Remote; 9 | using OpenQA.Selenium.Safari; 10 | using SeleniumFixture.xUnit.Impl; 11 | using Xunit.Sdk; 12 | 13 | namespace SeleniumFixture.xUnit 14 | { 15 | [Flags] 16 | public enum RemoteWebDriverCapability 17 | { 18 | Andriod = 1, 19 | Chrome = 2, 20 | FireFox = 4, 21 | HtmlUnit = 8, 22 | HtmlUnitWithJS = 16, 23 | InternetExplorer = 32, 24 | IPhone = 64, 25 | IPad = 128, 26 | Safari = 256, 27 | MajorFour = FireFox | InternetExplorer | Chrome | Safari, 28 | 29 | } 30 | 31 | public class RemoteDriverAttribute : WebDriverAttribute 32 | { 33 | public RemoteDriverAttribute(RemoteWebDriverCapability capability) 34 | { 35 | Capability = capability; 36 | } 37 | 38 | public override IEnumerable GetDrivers(MethodInfo testMethod) 39 | { 40 | yield return CreateWebDriver(testMethod, Capability, Hub); 41 | } 42 | 43 | /// 44 | /// Url for grid 45 | /// 46 | public string Hub { get; set; } 47 | 48 | /// 49 | /// Capability 50 | /// 51 | public RemoteWebDriverCapability Capability { get; private set; } 52 | 53 | public static IWebDriver CreateWebDriver(MethodInfo testMethod, RemoteWebDriverCapability capability, string hub) 54 | { 55 | DesiredCapabilities capabilities = null; 56 | 57 | switch (capability) 58 | { 59 | case RemoteWebDriverCapability.Andriod: 60 | capabilities = DesiredCapabilities.Android(); 61 | break; 62 | case RemoteWebDriverCapability.Chrome: 63 | capabilities = DesiredCapabilities.Chrome(); 64 | break; 65 | case RemoteWebDriverCapability.FireFox: 66 | capabilities = DesiredCapabilities.Firefox(); 67 | break; 68 | case RemoteWebDriverCapability.HtmlUnit: 69 | capabilities = DesiredCapabilities.HtmlUnit(); 70 | break; 71 | case RemoteWebDriverCapability.HtmlUnitWithJS: 72 | capabilities = DesiredCapabilities.HtmlUnitWithJavaScript(); 73 | break; 74 | case RemoteWebDriverCapability.InternetExplorer: 75 | capabilities = DesiredCapabilities.InternetExplorer(); 76 | break; 77 | case RemoteWebDriverCapability.IPad: 78 | capabilities = DesiredCapabilities.IPad(); 79 | break; 80 | case RemoteWebDriverCapability.IPhone: 81 | capabilities = DesiredCapabilities.IPhone(); 82 | break; 83 | case RemoteWebDriverCapability.Safari: 84 | capabilities = DesiredCapabilities.Safari(); 85 | break; 86 | } 87 | 88 | if (string.IsNullOrEmpty(hub)) 89 | { 90 | var attr = ReflectionHelper.GetAttribute(testMethod); 91 | 92 | if (attr != null) 93 | { 94 | hub = attr.Hub; 95 | } 96 | } 97 | 98 | return CreateWebDriverInstance(testMethod, hub, capabilities); 99 | } 100 | 101 | public static IWebDriver CreateWebDriverInstance(MethodInfo testMethod, string hub, DesiredCapabilities capabilities) 102 | { 103 | var driver = string.IsNullOrEmpty(hub) ? new RemoteWebDriver(capabilities) : new RemoteWebDriver(new Uri(hub), capabilities); 104 | 105 | InitializeDriver(testMethod, driver); 106 | 107 | return driver; 108 | } 109 | 110 | public override void ReturnDriver(MethodInfo testMethod, IWebDriver driver) 111 | { 112 | driver.Dispose(); 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/RemoteWebDriverHubAddressAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SeleniumFixture.xUnit 8 | { 9 | public class RemoteWebDriverHubAddressAttribute : Attribute 10 | { 11 | public string Hub { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/RemoteWebDriverProviderAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using OpenQA.Selenium; 7 | using Xunit.Abstractions; 8 | 9 | namespace SeleniumFixture.xUnit 10 | { 11 | public abstract class RemoteWebDriverProviderAttribute : Attribute 12 | { 13 | public abstract IEnumerable ProvideDriver(IMethodInfo testMethod, RemoteWebDriverCapability capability); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/SeleniumFixture.xUnit.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {0714F5E0-B98A-44BC-89CC-700A346406AC} 9 | Library 10 | Properties 11 | SeleniumFixture.xUnit 12 | SeleniumFixture.xUnit 13 | v4.5 14 | 512 15 | 16 | 17 | 18 | 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | bin\Debug\SeleniumFixture.xUnit.XML 27 | 28 | 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | bin\Release\SeleniumFixture.xUnit.XML 36 | 37 | 38 | 39 | ..\packages\SimpleFixture.1.3.0\lib\portable45-net45+win8+wp8+wpa81\SimpleFixture.dll 40 | True 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | ..\packages\Selenium.WebDriver.2.53.0\lib\net40\WebDriver.dll 53 | True 54 | 55 | 56 | ..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll 57 | True 58 | 59 | 60 | ..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll 61 | True 62 | 63 | 64 | ..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll 65 | True 66 | 67 | 68 | ..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll 69 | True 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | {9eb00e94-f1db-40e4-a131-4b28b347785f} 112 | SeleniumFixture 113 | 114 | 115 | 116 | 117 | 118 | xcopy /Y "$(TargetPath)" "$(ProjectDir)..\..\Output\bin\$(PlatformName)\" 119 | xcopy /Y "$(TargetDir)$(TargetName).xml" "$(ProjectDir)..\..\Output\bin\$(PlatformName)\" 120 | xcopy /Y "$(TargetDir)$(TargetName).pdb" "$(ProjectDir)..\..\Output\bin\$(PlatformName)\" 121 | 122 | 123 | 124 | 125 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 126 | 127 | 128 | 129 | 136 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/SeleniumFixture.xUnit.nuspec: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | SeleniumFixture.xUnit 5 | $version$ 6 | SeleniumFixture.xUnit 7 | Ian Johnson 8 | Ian Johnson 9 | https://github.com/ipjohnson/SeleniumFixture/blob/master/License.md 10 | https://github.com/ipjohnson/SeleniumFixture 11 | false 12 | Provides xUnit attributes for SeleniumFixture 13 | Adding dnx support for SeleniumFixture.xUnit 14 | Copyright © 2015 15 | Selenium Test Fixture Data Generation PageObject xUnit 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/SeleniumTheoryAttribute.cs: -------------------------------------------------------------------------------- 1 | using SeleniumFixture.xUnit.Impl; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Xunit; 8 | using Xunit.Sdk; 9 | 10 | namespace SeleniumFixture.xUnit 11 | { 12 | [XunitTestCaseDiscoverer(SeleniumTheoryDiscoverer.ClassName, SeleniumTheoryDiscoverer.AssemblyName)] 13 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] 14 | public class SeleniumTheoryAttribute : FactAttribute 15 | { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/WebDriverAttribute.cs: -------------------------------------------------------------------------------- 1 | using OpenQA.Selenium; 2 | using SeleniumFixture.xUnit.Impl; 3 | using System; 4 | using System.Collections.Concurrent; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Reflection; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using Xunit.Sdk; 11 | 12 | namespace SeleniumFixture.xUnit 13 | { 14 | public abstract class WebDriverAttribute : Attribute 15 | { 16 | private class InternalStorageHelper where T : IWebDriver 17 | { 18 | private static InternalStorageHelper _instance; 19 | private static object _lockObject = new object(); 20 | private List _allInstances = new List(); 21 | private Stack _freeInstances = new Stack(); 22 | 23 | ~InternalStorageHelper() 24 | { 25 | _freeInstances.Clear(); 26 | 27 | foreach(var instances in _allInstances) 28 | { 29 | instances.Dispose(); 30 | } 31 | } 32 | 33 | public T GetOrAdd(Func create) 34 | { 35 | T tInstance; 36 | lock(_freeInstances) 37 | { 38 | if(_freeInstances.Count > 0) 39 | { 40 | tInstance = _freeInstances.Pop(); 41 | } 42 | else 43 | { 44 | tInstance = create(); 45 | 46 | _allInstances.Add(tInstance); 47 | } 48 | } 49 | 50 | return tInstance; 51 | } 52 | 53 | public void ReturnInstance(T instance) 54 | { 55 | lock(_freeInstances) 56 | { 57 | _freeInstances.Push(instance); 58 | } 59 | } 60 | 61 | public static InternalStorageHelper Instance 62 | { 63 | get 64 | { 65 | if(_instance == null) 66 | { 67 | lock(_lockObject) 68 | { 69 | if (_instance == null) 70 | { 71 | _instance = new InternalStorageHelper(); 72 | } 73 | } 74 | } 75 | 76 | return _instance; 77 | } 78 | } 79 | } 80 | 81 | protected virtual T GetOrCreateWebDriver(MethodInfo method, Func createMethod) where T : IWebDriver 82 | { 83 | if(Shared) 84 | { 85 | var sharedInstance = GetSharedInstance(createMethod); 86 | 87 | ResetWebDriver(method, sharedInstance); 88 | 89 | return sharedInstance; 90 | } 91 | 92 | return createMethod(); 93 | } 94 | 95 | protected virtual void ResetWebDriver(MethodInfo method, T driver) where T : IWebDriver 96 | { 97 | var resetAttribute = ReflectionHelper.GetAttribute(method); 98 | 99 | if (resetAttribute != null) 100 | { 101 | resetAttribute.ResetWebDriver(method, driver); 102 | } 103 | else 104 | { 105 | driver.Manage().Cookies.DeleteAllCookies(); 106 | driver.Manage().Window.Maximize(); 107 | driver.Navigate().GoToUrl("about:blank"); 108 | } 109 | } 110 | 111 | protected T GetSharedInstance(Func createMethod) where T : IWebDriver 112 | { 113 | return InternalStorageHelper.Instance.GetOrAdd(createMethod); 114 | } 115 | 116 | public bool Shared { get; set; } 117 | 118 | public abstract IEnumerable GetDrivers(MethodInfo testMethod); 119 | 120 | public abstract void ReturnDriver(MethodInfo testMethod, IWebDriver driver); 121 | 122 | protected virtual void ReturnDriver(MethodInfo testMethod, T driver) where T : IWebDriver 123 | { 124 | var finalizerAttribute = ReflectionHelper.GetAttribute(testMethod); 125 | 126 | if(finalizerAttribute != null) 127 | { 128 | finalizerAttribute.Finalize(testMethod, driver); 129 | } 130 | 131 | if(driver != null) 132 | { 133 | if (Shared) 134 | { 135 | InternalStorageHelper.Instance.ReturnInstance(driver); 136 | } 137 | else 138 | { 139 | driver.Dispose(); 140 | } 141 | } 142 | } 143 | 144 | public static void InitializeDriver(MethodInfo testMethod, IWebDriver driver) 145 | { 146 | var initializeAttribute = ReflectionHelper.GetAttribute(testMethod); 147 | 148 | if (initializeAttribute != null) 149 | { 150 | initializeAttribute.Initialize(testMethod, driver); 151 | } 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /src/SeleniumFixture.xUnit/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/SeleniumFixture/ElementContants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SeleniumFixture 8 | { 9 | public static class ElementContants 10 | { 11 | public const string IdAttribute = "id"; 12 | 13 | public const string NameAttribute = "name"; 14 | 15 | public const string ValueAttribute = "value"; 16 | 17 | public const string TypeAttribute = "type"; 18 | 19 | public const string CheckBoxType = "checkbox"; 20 | 21 | public const string RadioButtonType = "radio"; 22 | 23 | public const string HiddenType = "hidden"; 24 | 25 | public const string SubmitType = "submit"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Exceptions/AssertionFailedException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SeleniumFixture.Exceptions 8 | { 9 | /// 10 | /// Exception thrown while executing 11 | /// 12 | public class AssertionFailedException : Exception 13 | { 14 | /// 15 | /// Default constructor 16 | /// 17 | /// 18 | /// 19 | public AssertionFailedException(Exception innerException, Type pageType) 20 | : base(FormatErrorMessage(innerException, pageType), innerException) 21 | { 22 | PageType = pageType; 23 | } 24 | 25 | /// 26 | /// Type of page being constructed 27 | /// 28 | public Type PageType { get; private set; } 29 | 30 | 31 | public static string FormatErrorMessage(Exception innerException, Type pageType) 32 | { 33 | return string.Format("Validation failure while constructing page: {0}{1}{2}", pageType.Name, Environment.NewLine, innerException.Message); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/SeleniumFixture/FormData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SeleniumFixture 8 | { 9 | public class FormData : Dictionary 10 | { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Impl/AlertAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SeleniumFixture.Impl 8 | { 9 | /// 10 | /// Alert action 11 | /// 12 | public interface IAlertAction 13 | { 14 | /// 15 | /// Accept alert 16 | /// 17 | /// action provider 18 | IActionProvider Accept(); 19 | 20 | /// 21 | /// Dismiss alert 22 | /// 23 | /// action provider 24 | IActionProvider Dismiss(); 25 | } 26 | 27 | /// 28 | /// Alert action 29 | /// 30 | public class AlertAction : IAlertAction 31 | { 32 | protected readonly IActionProvider _actionProvider; 33 | 34 | public AlertAction(IActionProvider actionProvider) 35 | { 36 | _actionProvider = actionProvider; 37 | } 38 | 39 | /// 40 | /// Accept alert 41 | /// 42 | /// action provider 43 | public virtual IActionProvider Accept() 44 | { 45 | _actionProvider.UsingFixture.Driver.SwitchTo().Alert().Accept(); 46 | 47 | return _actionProvider; 48 | } 49 | 50 | /// 51 | /// Dismiss alert 52 | /// 53 | /// action provider 54 | public virtual IActionProvider Dismiss() 55 | { 56 | _actionProvider.UsingFixture.Driver.SwitchTo().Alert().Dismiss(); 57 | 58 | return _actionProvider; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Impl/AutoBy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using OpenQA.Selenium; 8 | using OpenQA.Selenium.Internal; 9 | 10 | namespace SeleniumFixture.Impl 11 | { 12 | /// 13 | /// Selenium By selector that uses JQuery, CSS Selector, or XPath depending on the selector and if jquery is avaliable 14 | /// 15 | public class AutoBy : By 16 | { 17 | protected readonly string _selector; 18 | protected readonly string _jQueryTest; 19 | 20 | /// 21 | /// Default constructor 22 | /// 23 | /// selector 24 | /// 25 | public AutoBy(string selector, string jQueryTest = "return typeof jQuery != 'undefined';") 26 | { 27 | if (string.IsNullOrEmpty(selector)) 28 | { 29 | throw new ArgumentNullException("selector", "Must provide a string to select by"); 30 | } 31 | 32 | if (string.IsNullOrEmpty(jQueryTest)) 33 | { 34 | throw new ArgumentNullException("jQueryTest", "Must provide a valid javascript statement"); 35 | } 36 | 37 | _selector = selector; 38 | _jQueryTest = jQueryTest; 39 | } 40 | 41 | /// 42 | /// Finds the first element matching the criteria. 43 | /// 44 | /// An object to use to search for the elements. 45 | /// 46 | /// The first matching on the current context. 47 | /// 48 | public override IWebElement FindElement(ISearchContext context) 49 | { 50 | return FindElements(context).First(); 51 | } 52 | 53 | /// 54 | /// Finds all elements matching the criteria. 55 | /// 56 | /// An object to use to search for the elements. 57 | /// 58 | /// A of all WebElements 59 | /// matching the current criteria, or an empty list if nothing matches. 60 | /// 61 | public override ReadOnlyCollection FindElements(ISearchContext context) 62 | { 63 | By by = null; 64 | 65 | if (_selector.StartsWith("//")) 66 | { 67 | by = XPath(_selector); 68 | } 69 | else 70 | { 71 | by = IsJavaScriptEnabled(context, _jQueryTest) ? Using.JQuery(_selector) : CssSelector(_selector); 72 | } 73 | 74 | return context.FindElements(by); 75 | } 76 | 77 | public static bool IsJavaScriptEnabled(ISearchContext context, string jQueryTest = "return typeof jQuery != 'undefined';") 78 | { 79 | IJavaScriptExecutor executor = context as IJavaScriptExecutor; 80 | 81 | if (executor == null && context is IWrapsDriver) 82 | { 83 | executor = ((IWrapsDriver)context).WrappedDriver as IJavaScriptExecutor; 84 | } 85 | 86 | if (executor != null) 87 | { 88 | object returnValue = executor.ExecuteScript(jQueryTest); 89 | 90 | if (returnValue is bool) 91 | { 92 | return (bool)returnValue; 93 | } 94 | } 95 | 96 | return false; 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Impl/AutoFillAsAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using OpenQA.Selenium; 7 | 8 | namespace SeleniumFixture.Impl 9 | { 10 | public interface IAutoFillAsAction 11 | { 12 | IThenSubmitAction PerformFill(string requestName, object constraints); 13 | } 14 | 15 | public class AutoFillAsAction : IAutoFillAsAction 16 | { 17 | protected readonly IActionProvider _actionProvider; 18 | protected readonly IEnumerable _elements; 19 | 20 | public AutoFillAsAction(IActionProvider actionProvider, IEnumerable elements) 21 | { 22 | _actionProvider = actionProvider; 23 | _elements = elements; 24 | } 25 | 26 | public virtual IThenSubmitAction PerformFill(string requestName, object constraints) 27 | { 28 | T seedValue = _actionProvider.UsingFixture.Data.Generate(requestName, constraints); 29 | 30 | return new AutoFillAction(_actionProvider, _elements, seedValue).PerformFill(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Impl/AutoFillAsActionProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using OpenQA.Selenium; 7 | 8 | namespace SeleniumFixture.Impl 9 | { 10 | public interface IAutoFillAsActionProvider 11 | { 12 | IAutoFillAsAction CreateAction(IEnumerable elements); 13 | } 14 | 15 | public class AutoFillAsActionProvider : IAutoFillAsActionProvider 16 | { 17 | protected readonly IActionProvider _actionProvider; 18 | 19 | public AutoFillAsActionProvider(IActionProvider actionProvider) 20 | { 21 | _actionProvider = actionProvider; 22 | } 23 | 24 | public virtual IAutoFillAsAction CreateAction(IEnumerable elements) 25 | { 26 | return new AutoFillAsAction(_actionProvider,elements); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Impl/ClearAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using OpenQA.Selenium; 8 | 9 | namespace SeleniumFixture.Impl 10 | { 11 | public interface IClearAction 12 | { 13 | /// 14 | /// Clear by selector 15 | /// 16 | /// selector 17 | /// action provider 18 | IActionProvider Clear(string selector); 19 | 20 | /// 21 | /// Clear by selenium selector 22 | /// 23 | /// selector 24 | /// action provider 25 | IActionProvider Clear(By selector); 26 | 27 | /// 28 | /// Clear all elements provided 29 | /// 30 | /// 31 | /// 32 | IActionProvider Clear(IEnumerable elements); 33 | } 34 | 35 | /// 36 | /// Clear action 37 | /// 38 | public class ClearAction : IClearAction 39 | { 40 | protected readonly IActionProvider _actionProvider; 41 | 42 | /// 43 | /// Default constructor 44 | /// 45 | /// action provider 46 | public ClearAction(IActionProvider actionProvider) 47 | { 48 | _actionProvider = actionProvider; 49 | } 50 | 51 | /// 52 | /// Clear the elements provided 53 | /// 54 | /// 55 | /// 56 | public IActionProvider Clear(IEnumerable elements) 57 | { 58 | elements.Apply(e => e.Clear()); 59 | 60 | return _actionProvider; 61 | } 62 | 63 | /// 64 | /// Clear by selector 65 | /// 66 | /// selector 67 | /// action provider 68 | public virtual IActionProvider Clear(string selector) 69 | { 70 | _actionProvider.FindElements(selector).Apply(e => e.Clear()); 71 | 72 | return _actionProvider; 73 | } 74 | 75 | /// 76 | /// Clear by selenium selector 77 | /// 78 | /// selector 79 | /// action provider 80 | public virtual IActionProvider Clear(By selector) 81 | { 82 | _actionProvider.FindElements(selector).Apply(e => e.Clear()); 83 | 84 | return _actionProvider; 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Impl/ClickAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using OpenQA.Selenium; 8 | 9 | namespace SeleniumFixture.Impl 10 | { 11 | public interface IClickAction 12 | { 13 | IActionProvider Click(string selector, ClickMode clickMode = ClickMode.ClickAll); 14 | 15 | IActionProvider Click(By selector, ClickMode clickMode = ClickMode.ClickAll); 16 | 17 | IActionProvider Click(IEnumerable elements, ClickMode clickMode = ClickMode.ClickAll); 18 | } 19 | 20 | /// 21 | /// Click provider 22 | /// 23 | public class ClickAction : IClickAction 24 | { 25 | protected readonly IActionProvider _actionProvider; 26 | 27 | public ClickAction(IActionProvider actionProvider) 28 | { 29 | _actionProvider = actionProvider; 30 | } 31 | 32 | public IActionProvider Click(IEnumerable elements, ClickMode clickMode = ClickMode.ClickAll) 33 | { 34 | switch (clickMode) 35 | { 36 | case ClickMode.ClickOne: 37 | var element = elements.FirstOrDefault(); 38 | 39 | if(element != null) 40 | { 41 | element.Click(); 42 | } 43 | break; 44 | 45 | case ClickMode.ClickAny: 46 | elements.Apply(c => c.Click()); 47 | break; 48 | 49 | case ClickMode.ClickAll: 50 | bool found = false; 51 | 52 | elements.Apply(c => { c.Click(); found = true; }); 53 | 54 | if (!found) 55 | { 56 | throw new Exception("No elements found in collection"); 57 | } 58 | break; 59 | 60 | case ClickMode.ClickFirst: 61 | elements.First().Click(); 62 | break; 63 | } 64 | 65 | var configuration = _actionProvider.UsingFixture.Configuration; 66 | 67 | var waitTime = (int)(configuration.FixtureImplicitWait * 1000); 68 | 69 | if (waitTime >= 0) 70 | { 71 | Thread.Sleep(waitTime); 72 | } 73 | 74 | return configuration.AlwaysWaitForAjax ? _actionProvider.Wait.ForAjax().Then : _actionProvider; 75 | } 76 | 77 | public virtual IActionProvider Click(string selector, ClickMode clickMode = ClickMode.ClickAll) 78 | { 79 | switch (clickMode) 80 | { 81 | case ClickMode.ClickOne: 82 | _actionProvider.FindElement(selector).Click(); 83 | break; 84 | 85 | case ClickMode.ClickAny: 86 | _actionProvider.FindElements(selector).Apply(c => c.Click()); 87 | break; 88 | 89 | case ClickMode.ClickAll: 90 | var all = _actionProvider.FindElements(selector); 91 | 92 | if (all.Count == 0) 93 | { 94 | throw new Exception("Could not locate any using selector: " + selector); 95 | } 96 | all.Apply(c => c.Click()); 97 | break; 98 | 99 | case ClickMode.ClickFirst: 100 | var firstList = _actionProvider.FindElements(selector); 101 | 102 | if (firstList.Count == 0) 103 | { 104 | throw new Exception("Could not locate any using selector: " + selector); 105 | } 106 | firstList[0].Click(); 107 | break; 108 | } 109 | var configuration = _actionProvider.UsingFixture.Configuration; 110 | 111 | var waitTime = (int)(configuration.FixtureImplicitWait * 1000); 112 | 113 | if (waitTime >= 0) 114 | { 115 | Thread.Sleep(waitTime); 116 | } 117 | 118 | return configuration.AlwaysWaitForAjax ? _actionProvider.Wait.ForAjax().Then : _actionProvider; 119 | } 120 | 121 | public virtual IActionProvider Click(By selector, ClickMode clickMode = ClickMode.ClickAll) 122 | { 123 | switch (clickMode) 124 | { 125 | case ClickMode.ClickOne: 126 | _actionProvider.FindElement(selector).Click(); 127 | break; 128 | case ClickMode.ClickAny: 129 | _actionProvider.FindElements(selector).Apply(c => c.Click()); 130 | break; 131 | case ClickMode.ClickAll: 132 | var all = _actionProvider.FindElements(selector); 133 | 134 | if (all.Count == 0) 135 | { 136 | throw new Exception("Could not locate any using selector: " + selector); 137 | } 138 | all.Apply(c => c.Click()); 139 | break; 140 | case ClickMode.ClickFirst: 141 | var firstList = _actionProvider.FindElements(selector); 142 | 143 | if (firstList.Count == 0) 144 | { 145 | throw new Exception("Could not locate any using selector: " + selector); 146 | } 147 | firstList[0].Click(); 148 | break; 149 | } 150 | 151 | var configuration = _actionProvider.UsingFixture.Configuration; 152 | 153 | var waitTime = (int)(configuration.FixtureImplicitWait * 1000); 154 | 155 | if (waitTime >= 0) 156 | { 157 | Thread.Sleep(waitTime); 158 | } 159 | 160 | return configuration.AlwaysWaitForAjax ? _actionProvider.Wait.ForAjax().Then : _actionProvider; 161 | } 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Impl/DoubleClickAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using OpenQA.Selenium; 8 | using OpenQA.Selenium.Interactions; 9 | 10 | namespace SeleniumFixture.Impl 11 | { 12 | public interface IDoubleClickAction 13 | { 14 | IActionProvider DoubleClick(string selector, ClickMode clickMode = ClickMode.ClickAll); 15 | 16 | IActionProvider DoubleClick(By selector, ClickMode clickMode = ClickMode.ClickAll); 17 | 18 | IActionProvider DoubleClick(IEnumerable elements, ClickMode clickMode = ClickMode.ClickAll); 19 | } 20 | 21 | public class DoubleClickAction : IDoubleClickAction 22 | { 23 | protected readonly IActionProvider _actionProvider; 24 | protected readonly Fixture _fixture; 25 | 26 | public DoubleClickAction(IActionProvider actionProvider) 27 | { 28 | _actionProvider = actionProvider; 29 | _fixture = _actionProvider.UsingFixture; 30 | } 31 | 32 | public IActionProvider DoubleClick(IEnumerable elements, ClickMode clickMode = ClickMode.ClickAll) 33 | { 34 | bool found = false; 35 | Actions action = null; 36 | 37 | switch (clickMode) 38 | { 39 | case ClickMode.ClickAll: 40 | elements.Apply(allElement => 41 | { 42 | action = new Actions(_fixture.Driver); 43 | action.DoubleClick(allElement); 44 | action.Perform(); 45 | found = true; 46 | }); 47 | 48 | if(!found) 49 | { 50 | throw new Exception("Must provide elements to click"); 51 | } 52 | break; 53 | case ClickMode.ClickAny: 54 | elements.Apply(anyElement => 55 | { 56 | action = new Actions(_fixture.Driver); 57 | action.DoubleClick(anyElement); 58 | action.Perform(); 59 | found = true; 60 | }); 61 | break; 62 | case ClickMode.ClickFirst: 63 | var firstElement = elements.First(); 64 | 65 | action = new Actions(_fixture.Driver); 66 | action.DoubleClick(firstElement); 67 | action.Perform(); 68 | break; 69 | case ClickMode.ClickOne: 70 | var oneElement = elements.FirstOrDefault(); 71 | if(oneElement != null) 72 | 73 | { 74 | action = new Actions(_fixture.Driver); 75 | action.DoubleClick(oneElement); 76 | action.Perform(); 77 | } 78 | break; 79 | } 80 | 81 | var configuration = _fixture.Configuration; 82 | 83 | var waitTime = (int)(configuration.FixtureImplicitWait * 1000); 84 | 85 | if (waitTime >= 0) 86 | { 87 | Thread.Sleep(waitTime); 88 | } 89 | 90 | return configuration.AlwaysWaitForAjax ? _fixture.Wait.ForAjax().Then : _actionProvider; 91 | } 92 | 93 | public virtual IActionProvider DoubleClick(string selector, ClickMode clickMode = ClickMode.ClickAll) 94 | { 95 | switch (clickMode) 96 | { 97 | case ClickMode.ClickOne: 98 | { 99 | var element = _actionProvider.FindElement(selector); 100 | 101 | Actions action = new Actions(_fixture.Driver); 102 | action.DoubleClick(element); 103 | action.Perform(); 104 | } 105 | break; 106 | 107 | case ClickMode.ClickAny: 108 | { 109 | _actionProvider.FindElements(selector).Apply(element => 110 | { 111 | Actions action = new Actions(_fixture.Driver); 112 | action.DoubleClick(element); 113 | action.Perform(); 114 | }); 115 | } 116 | break; 117 | case ClickMode.ClickAll: 118 | { 119 | var all = _actionProvider.FindElements(selector); 120 | 121 | if (all.Count == 0) 122 | { 123 | throw new Exception("Could not locate any using selector: " + selector); 124 | } 125 | 126 | all.Apply(element => 127 | { 128 | Actions action = new Actions(_fixture.Driver); 129 | action.DoubleClick(element); 130 | action.Perform(); 131 | }); 132 | } 133 | break; 134 | 135 | case ClickMode.ClickFirst: 136 | { 137 | var firstList = _actionProvider.FindElements(selector); 138 | 139 | if (firstList.Count == 0) 140 | { 141 | throw new Exception("Could not locate any using selector: " + selector); 142 | } 143 | 144 | Actions action = new Actions(_fixture.Driver); 145 | action.DoubleClick(firstList[0]); 146 | action.Perform(); 147 | } 148 | break; 149 | } 150 | 151 | var configuration = _fixture.Configuration; 152 | 153 | var waitTime = (int)(configuration.FixtureImplicitWait * 1000); 154 | 155 | if (waitTime >= 0) 156 | { 157 | Thread.Sleep(waitTime); 158 | } 159 | 160 | return configuration.AlwaysWaitForAjax ? _fixture.Wait.ForAjax().Then : _actionProvider; 161 | } 162 | 163 | public virtual IActionProvider DoubleClick(By selector, ClickMode clickMode = ClickMode.ClickAll) 164 | { 165 | switch (clickMode) 166 | { 167 | case ClickMode.ClickOne: 168 | { 169 | var element = _actionProvider.FindElement(selector); 170 | 171 | Actions action = new Actions(_fixture.Driver); 172 | action.DoubleClick(element); 173 | action.Perform(); 174 | } 175 | break; 176 | 177 | case ClickMode.ClickAny: 178 | { 179 | _actionProvider.FindElements(selector).Apply(element => 180 | { 181 | Actions action = new Actions(_fixture.Driver); 182 | action.DoubleClick(element); 183 | action.Perform(); 184 | }); 185 | 186 | 187 | } 188 | break; 189 | case ClickMode.ClickAll: 190 | { 191 | var all = _actionProvider.FindElements(selector); 192 | 193 | if (all.Count == 0) 194 | { 195 | throw new Exception("Could not locate any using selector: " + selector); 196 | } 197 | 198 | all.Apply(element => 199 | { 200 | Actions action = new Actions(_fixture.Driver); 201 | action.DoubleClick(element); 202 | action.Perform(); 203 | }); 204 | } 205 | break; 206 | 207 | case ClickMode.ClickFirst: 208 | { 209 | var firstList = _actionProvider.FindElements(selector); 210 | 211 | if (firstList.Count == 0) 212 | { 213 | throw new Exception("Could not locate any using selector: " + selector); 214 | } 215 | 216 | Actions action = new Actions(_fixture.Driver); 217 | action.DoubleClick(firstList[0]); 218 | action.Perform(); 219 | } 220 | break; 221 | } 222 | 223 | var configuration = _fixture.Configuration; 224 | 225 | var waitTime = (int)(configuration.FixtureImplicitWait * 1000); 226 | 227 | if (waitTime >= 0) 228 | { 229 | Thread.Sleep(waitTime); 230 | } 231 | 232 | return configuration.AlwaysWaitForAjax ? _fixture.Wait.ForAjax().Then : _actionProvider; 233 | } 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Impl/ImportSeleniumTypePropertySelector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using SimpleFixture; 6 | using SimpleFixture.Impl; 7 | 8 | namespace SeleniumFixture.Impl 9 | { 10 | public class ImportSeleniumTypePropertySelector : SeleniumTypePropertySelector 11 | { 12 | public ImportSeleniumTypePropertySelector(IConstraintHelper helper) 13 | : base(helper) 14 | { 15 | 16 | } 17 | 18 | public override IEnumerable SelectProperties(object instance, DataRequest request, ComplexModel model) 19 | { 20 | foreach (PropertyInfo runtimeProperty in instance.GetType().GetRuntimeProperties()) 21 | { 22 | if (runtimeProperty.GetSetMethod(true) == null) 23 | { 24 | if (runtimeProperty.DeclaringType == null || 25 | runtimeProperty.DeclaringType == instance.GetType()) 26 | continue; 27 | 28 | var baseProperty = runtimeProperty.DeclaringType.GetProperty(runtimeProperty.Name, 29 | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); 30 | 31 | if(baseProperty == null || baseProperty.GetSetMethod(true) == null) 32 | continue; 33 | } 34 | 35 | if(runtimeProperty.GetCustomAttributes(true).Any(o => o.GetType() == typeof(ImportAttribute)) || 36 | runtimeProperty.PropertyType == typeof(IActionProvider)) 37 | { 38 | yield return runtimeProperty; 39 | } 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Impl/JQueryBy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using OpenQA.Selenium; 8 | using OpenQA.Selenium.Internal; 9 | 10 | namespace SeleniumFixture.Impl 11 | { 12 | /// 13 | /// Selenium By Selector that uses jQuery 14 | /// 15 | public class JQueryBy : By 16 | { 17 | private readonly string _selector; 18 | 19 | /// 20 | /// Default constructor 21 | /// 22 | /// jquery selector 23 | public JQueryBy(string selector) 24 | { 25 | _selector = selector; 26 | } 27 | 28 | /// 29 | /// Finds the first element matching the criteria. 30 | /// 31 | /// An object to use to search for the elements. 32 | /// 33 | /// The first matching on the current context. 34 | /// 35 | public override IWebElement FindElement(ISearchContext context) 36 | { 37 | return FindElements(context).First(); 38 | } 39 | 40 | /// 41 | /// Finds all elements matching the criteria. 42 | /// 43 | /// An object to use to search for the elements. 44 | /// 45 | /// A of all WebElements 46 | /// matching the current criteria, or an empty list if nothing matches. 47 | /// 48 | public override ReadOnlyCollection FindElements(ISearchContext context) 49 | { 50 | if (context is IJavaScriptExecutor) 51 | { 52 | return FindElementsOnDriver(context as IJavaScriptExecutor); 53 | } 54 | 55 | if (context is IWrapsDriver) 56 | { 57 | return FindElementsOnElement(context as IWrapsDriver); 58 | } 59 | 60 | throw new Exception("Can't perform JQueryBy in this context: " + context.GetType().FullName); 61 | } 62 | 63 | protected virtual ReadOnlyCollection FindElementsOnElement(IWrapsDriver wrapsDriver) 64 | { 65 | IJavaScriptExecutor executor = wrapsDriver.WrappedDriver as IJavaScriptExecutor; 66 | 67 | if (executor == null) 68 | { 69 | throw new Exception("IWrapsDriver does not implement IJavaScriptExecutor"); 70 | } 71 | 72 | string script = 73 | @" var returnList = []; 74 | $(arguments[0]).find('" + _selector + @"').each(function () { returnList.push(this); }); 75 | return returnList;"; 76 | 77 | var objects = (IEnumerable)executor.ExecuteScript(script, wrapsDriver); 78 | 79 | return new ReadOnlyCollection(objects.Cast().ToList()); 80 | } 81 | 82 | protected virtual ReadOnlyCollection FindElementsOnDriver(IJavaScriptExecutor executor) 83 | { 84 | IEnumerable matchedItems = 85 | (IEnumerable)executor.ExecuteScript("return jQuery.find('" + _selector + "')"); 86 | 87 | return new ReadOnlyCollection(matchedItems.Cast().ToList()); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Impl/MouseMoveAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using OpenQA.Selenium; 7 | using OpenQA.Selenium.Interactions; 8 | 9 | namespace SeleniumFixture.Impl 10 | { 11 | public interface IMouseMoveAction 12 | { 13 | IActionProvider MoveTheMouseTo(string selector, int? x = null, int? y = null); 14 | 15 | IActionProvider MoveTheMouseTo(By selector, int? x = null, int? y = null); 16 | } 17 | 18 | public class MouseMoveAction : IMouseMoveAction 19 | { 20 | protected readonly IActionProvider _actionProvider; 21 | 22 | public MouseMoveAction(IActionProvider actionProvider) 23 | { 24 | _actionProvider = actionProvider; 25 | } 26 | 27 | public virtual IActionProvider MoveTheMouseTo(string selector, int? x = null, int? y = null) 28 | { 29 | Actions action = new Actions(_actionProvider.UsingFixture.Driver); 30 | 31 | var element = _actionProvider.FindElement(selector); 32 | 33 | if (x.HasValue && y.HasValue) 34 | { 35 | action.MoveToElement(element, x.Value, y.Value); 36 | } 37 | else 38 | { 39 | action.MoveToElement(element); 40 | } 41 | 42 | action.Perform(); 43 | 44 | return _actionProvider; 45 | } 46 | 47 | public virtual IActionProvider MoveTheMouseTo(By selector, int? x = null, int? y = null) 48 | { 49 | Actions action = new Actions(_actionProvider.UsingFixture.Driver); 50 | 51 | var element = _actionProvider.FindElement(selector); 52 | 53 | if (x.HasValue && y.HasValue) 54 | { 55 | action.MoveToElement(element, x.Value, y.Value); 56 | } 57 | else 58 | { 59 | action.MoveToElement(element); 60 | } 61 | 62 | action.Perform(); 63 | 64 | return _actionProvider; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Impl/NavigateAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | 8 | namespace SeleniumFixture.Impl 9 | { 10 | /// 11 | /// Provides navigation actions 12 | /// 13 | public interface INavigateAction 14 | { 15 | /// 16 | /// Navigate to the specified url 17 | /// 18 | /// url, if null navigate to base address 19 | /// action provider 20 | IActionProvider To(string url = null); 21 | 22 | /// 23 | /// Navigate to specified url and return page object 24 | /// 25 | /// page object type 26 | /// url to navigate to 27 | /// page object 28 | T To(string url = null); 29 | 30 | /// 31 | /// Navigate to provided Uri 32 | /// 33 | /// uri to navigate to 34 | /// 35 | IActionProvider To(Uri uri); 36 | 37 | /// 38 | /// Navigate to provided uri and return page object 39 | /// 40 | /// page object type 41 | /// uri 42 | /// page object 43 | T To(Uri uri); 44 | 45 | /// 46 | /// Navigate the browser back 47 | /// 48 | /// 49 | IActionProvider Back(); 50 | 51 | /// 52 | /// Navigate back and return page model 53 | /// 54 | /// page object type 55 | /// page object 56 | T Back(); 57 | 58 | /// 59 | /// Navigate the browser forward 60 | /// 61 | /// 62 | IActionProvider Forward(); 63 | 64 | /// 65 | /// Navigate forward and return page object 66 | /// 67 | /// page object type 68 | /// 69 | T Forward(); 70 | } 71 | 72 | /// 73 | /// Provide fluent syntax for Navigation 74 | /// 75 | public class NavigateAction : INavigateAction 76 | { 77 | protected readonly IActionProvider _actionProvider; 78 | 79 | /// 80 | /// Default constructor 81 | /// 82 | /// action provider 83 | public NavigateAction(IActionProvider actionProvider) 84 | { 85 | _actionProvider = actionProvider; 86 | } 87 | 88 | /// 89 | /// Navigate to the specified url 90 | /// 91 | /// url, if null navigate to base address 92 | /// action provider 93 | public virtual IActionProvider To(string url = null) 94 | { 95 | if (url == null || !url.StartsWith("http", StringComparison.CurrentCultureIgnoreCase)) 96 | { 97 | url = _actionProvider.UsingFixture.Configuration.BaseAddress + url; 98 | } 99 | 100 | _actionProvider.UsingFixture.Driver.Navigate().GoToUrl(url); 101 | 102 | var configuration = _actionProvider.UsingFixture.Configuration; 103 | 104 | var waitTime = (int)(configuration.FixtureImplicitWait * 1000); 105 | 106 | if (waitTime >= 0) 107 | { 108 | Thread.Sleep(waitTime); 109 | } 110 | 111 | if (configuration.AlwaysWaitForAjax) 112 | { 113 | _actionProvider.Wait.ForAjax(); 114 | } 115 | 116 | return _actionProvider; 117 | } 118 | 119 | /// 120 | /// Navigate to specified url and return page object 121 | /// 122 | /// page object type 123 | /// url to navigate to 124 | /// page object 125 | public virtual T To(string url = null) 126 | { 127 | To(url); 128 | 129 | return _actionProvider.Yields(); 130 | } 131 | 132 | /// 133 | /// Navigate to provided Uri 134 | /// 135 | /// uri to navigate to 136 | /// 137 | public virtual IActionProvider To(Uri uri) 138 | { 139 | _actionProvider.UsingFixture.Driver.Navigate().GoToUrl(uri); 140 | 141 | var configuration = _actionProvider.UsingFixture.Configuration; 142 | 143 | var waitTime = (int)(configuration.FixtureImplicitWait * 1000); 144 | 145 | if (waitTime >= 0) 146 | { 147 | Thread.Sleep(waitTime); 148 | } 149 | 150 | if (configuration.AlwaysWaitForAjax) 151 | { 152 | _actionProvider.Wait.ForAjax(); 153 | } 154 | 155 | return _actionProvider; 156 | } 157 | 158 | /// 159 | /// Navigate to provided uri and return page object 160 | /// 161 | /// page object type 162 | /// uri 163 | /// page object 164 | public virtual T To(Uri uri) 165 | { 166 | To(uri); 167 | 168 | return _actionProvider.Yields(); 169 | } 170 | 171 | /// 172 | /// Navigate the browser back 173 | /// 174 | /// 175 | public virtual IActionProvider Back() 176 | { 177 | _actionProvider.UsingFixture.Driver.Navigate().Back(); 178 | 179 | var configuration = _actionProvider.UsingFixture.Configuration; 180 | 181 | var waitTime = (int)(configuration.FixtureImplicitWait * 1000); 182 | 183 | if (waitTime >= 0) 184 | { 185 | Thread.Sleep(waitTime); 186 | } 187 | 188 | if (configuration.AlwaysWaitForAjax) 189 | { 190 | _actionProvider.Wait.ForAjax(); 191 | } 192 | 193 | return _actionProvider; 194 | } 195 | 196 | /// 197 | /// Navigate back and return page model 198 | /// 199 | /// page object type 200 | /// page object 201 | public virtual T Back() 202 | { 203 | Back(); 204 | 205 | return _actionProvider.Yields(); 206 | } 207 | 208 | /// 209 | /// Navigate the browser forward 210 | /// 211 | /// 212 | public virtual IActionProvider Forward() 213 | { 214 | _actionProvider.UsingFixture.Driver.Navigate().Forward(); 215 | 216 | var configuration = _actionProvider.UsingFixture.Configuration; 217 | 218 | var waitTime = (int)(configuration.FixtureImplicitWait * 1000); 219 | 220 | if (waitTime >= 0) 221 | { 222 | Thread.Sleep(waitTime); 223 | } 224 | 225 | if (configuration.AlwaysWaitForAjax) 226 | { 227 | _actionProvider.Wait.ForAjax(); 228 | } 229 | 230 | return _actionProvider; 231 | } 232 | 233 | /// 234 | /// Navigate forward and return page object 235 | /// 236 | /// page object type 237 | /// 238 | public virtual T Forward() 239 | { 240 | Forward(); 241 | 242 | return _actionProvider.Yields(); 243 | } 244 | } 245 | } 246 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Impl/PropertySetter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using SimpleFixture.Impl; 9 | 10 | namespace SeleniumFixture.Impl 11 | { 12 | /// 13 | /// SimpleFixture property setter, allows the user to inject properties into private members 14 | /// 15 | public class PropertySetter : IPropertySetter 16 | { 17 | public void SetProperty(PropertyInfo propertyInfo, object instance, object value) 18 | { 19 | var methods = propertyInfo.DeclaringType.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); 20 | 21 | var method = 22 | methods.FirstOrDefault(m => m.Name == "set_" + propertyInfo.Name && m.GetParameters().Count() == 1); 23 | 24 | if (method != null) 25 | { 26 | method.Invoke(instance, new[] { value }); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Impl/SeleniumTypePropertySelector.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System.Reflection; 4 | using SeleniumFixture.Impl; 5 | using SimpleFixture; 6 | using SimpleFixture.Impl; 7 | 8 | namespace SeleniumFixture 9 | { 10 | public class SeleniumTypePropertySelector : TypePropertySelector 11 | { 12 | public SeleniumTypePropertySelector(IConstraintHelper helper) : base(helper) 13 | { 14 | 15 | } 16 | 17 | public override IEnumerable SelectProperties(object instance, DataRequest request, ComplexModel model) 18 | { 19 | return instance 20 | .GetType() 21 | .GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) 22 | .Where(p => !p.GetCustomAttributes(true).Any(o => o.GetType().Namespace.StartsWith("OpenQA.Selenium")) && 23 | (p.CanWrite || 24 | p.GetCustomAttributes(typeof(ImportAttribute), true).Any() || 25 | p.PropertyType == typeof(IActionProvider))); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Impl/SendToAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using OpenQA.Selenium; 7 | 8 | namespace SeleniumFixture.Impl 9 | { 10 | /// 11 | /// Send to action interface 12 | /// 13 | public interface ISendToAction 14 | { 15 | /// 16 | /// Send value to alert 17 | /// 18 | /// 19 | IActionProvider ToAlert(); 20 | 21 | /// 22 | /// Select a set of elements to send value to 23 | /// 24 | /// element selector 25 | /// action provider 26 | IActionProvider To(string selector); 27 | 28 | /// 29 | /// Select a set of elements to send value to 30 | /// 31 | /// by selector 32 | /// action provider 33 | IActionProvider To(By selector); 34 | } 35 | 36 | /// 37 | /// Send to action 38 | /// 39 | public class SendToAction : ISendToAction 40 | { 41 | protected readonly string _sendValue; 42 | protected readonly IActionProvider _actionProvider; 43 | 44 | /// 45 | /// Default constructor 46 | /// 47 | /// action provider 48 | /// send value 49 | public SendToAction(IActionProvider actionProvider, string sendValue) 50 | { 51 | _sendValue = sendValue; 52 | _actionProvider = actionProvider; 53 | } 54 | 55 | /// 56 | /// Send value to alert 57 | /// 58 | /// 59 | public virtual IActionProvider ToAlert() 60 | { 61 | _actionProvider.UsingFixture.Driver.SwitchTo().Alert().SendKeys(_sendValue); 62 | 63 | return _actionProvider; 64 | } 65 | 66 | /// 67 | /// Select a set of elements to send value to 68 | /// 69 | /// element selector 70 | /// action provider 71 | public virtual IActionProvider To(string selector) 72 | { 73 | _actionProvider.FindElements(selector).Apply(e => e.SendKeys(_sendValue)); 74 | 75 | return _actionProvider; 76 | } 77 | 78 | /// 79 | /// Select a set of elements to send value to 80 | /// 81 | /// by selector 82 | /// action provider 83 | public virtual IActionProvider To(By selector) 84 | { 85 | _actionProvider.FindElements(selector).Apply(e => e.SendKeys(_sendValue)); 86 | 87 | return _actionProvider; 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Impl/SwitchAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using OpenQA.Selenium; 7 | 8 | namespace SeleniumFixture.Impl 9 | { 10 | public interface ISwitchToAction 11 | { 12 | /// 13 | /// Switch to a window by name 14 | /// 15 | /// window name 16 | /// 17 | IYieldsAction Window(string windowName); 18 | 19 | /// 20 | /// Switch to parent frame 21 | /// 22 | /// 23 | IYieldsAction ParentFrame(); 24 | 25 | /// 26 | /// Switch to frame by specific name 27 | /// 28 | /// 29 | /// 30 | IYieldsAction Frame(string frameName); 31 | 32 | /// 33 | /// Switch to frame by element 34 | /// 35 | /// 36 | /// 37 | IYieldsAction Frame(IWebElement element); 38 | 39 | /// 40 | /// Switch to element using by 41 | /// 42 | /// 43 | /// 44 | IYieldsAction Frame(By selector); 45 | 46 | /// 47 | /// Switch to default content 48 | /// 49 | /// 50 | IYieldsAction DefaultContent(); 51 | 52 | /// 53 | /// Switch to alert 54 | /// 55 | /// 56 | IAlert Alert(); 57 | } 58 | 59 | /// 60 | /// Switch action provider 61 | /// 62 | public class SwitchAction : ISwitchToAction 63 | { 64 | protected readonly IActionProvider _actionProvider; 65 | 66 | /// 67 | /// Default constructor 68 | /// 69 | /// action provider 70 | public SwitchAction(IActionProvider actionProvider) 71 | { 72 | _actionProvider = actionProvider; 73 | } 74 | 75 | /// 76 | /// Switch to a window by name 77 | /// 78 | /// window name 79 | /// 80 | public virtual IYieldsAction Window(string windowName) 81 | { 82 | _actionProvider.UsingFixture.Driver.SwitchTo().Window(windowName); 83 | 84 | return new YieldsAction(_actionProvider.UsingFixture); 85 | } 86 | 87 | /// 88 | /// Switch to parent frame 89 | /// 90 | /// 91 | public virtual IYieldsAction ParentFrame() 92 | { 93 | _actionProvider.UsingFixture.Driver.SwitchTo().ParentFrame(); 94 | 95 | return new YieldsAction(_actionProvider.UsingFixture); 96 | } 97 | 98 | /// 99 | /// Switch to frame by specific name 100 | /// 101 | /// 102 | /// 103 | public virtual IYieldsAction Frame(string frameName) 104 | { 105 | _actionProvider.UsingFixture.Driver.SwitchTo().Frame(frameName); 106 | 107 | return new YieldsAction(_actionProvider.UsingFixture); 108 | } 109 | 110 | /// 111 | /// Switch to frame by element 112 | /// 113 | /// 114 | /// 115 | public virtual IYieldsAction Frame(IWebElement element) 116 | { 117 | _actionProvider.UsingFixture.Driver.SwitchTo().Frame(element); 118 | 119 | return new YieldsAction(_actionProvider.UsingFixture); 120 | } 121 | 122 | /// 123 | /// Switch to element using by 124 | /// 125 | /// 126 | /// 127 | public virtual IYieldsAction Frame(By selector) 128 | { 129 | var element = _actionProvider.FindElement(selector); 130 | 131 | _actionProvider.UsingFixture.Driver.SwitchTo().Frame(element); 132 | 133 | return new YieldsAction(_actionProvider.UsingFixture); 134 | } 135 | 136 | /// 137 | /// Switch to default content 138 | /// 139 | /// 140 | public virtual IYieldsAction DefaultContent() 141 | { 142 | _actionProvider.UsingFixture.Driver.SwitchTo().DefaultContent(); 143 | 144 | return new YieldsAction(_actionProvider.UsingFixture); 145 | } 146 | 147 | /// 148 | /// Switch to alert 149 | /// 150 | /// 151 | public virtual IAlert Alert() 152 | { 153 | return _actionProvider.UsingFixture.Driver.SwitchTo().Alert(); 154 | } 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Impl/TakeScreenshotAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Drawing.Imaging; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using OpenQA.Selenium; 9 | 10 | namespace SeleniumFixture.Impl 11 | { 12 | /// 13 | /// Screenshot action 14 | /// 15 | public interface ITakeScreenshotAction 16 | { 17 | /// 18 | /// Take screenshot 19 | /// 20 | /// screenshot name 21 | /// throws if driver does not support taking a screenshot 22 | /// 23 | /// 24 | IActionProvider TakeScreenshot(string screenshotName, bool throwsIfNotSupported, ImageFormat format); 25 | } 26 | 27 | /// 28 | /// Screenshot action 29 | /// 30 | public class TakeScreenshotAction : ITakeScreenshotAction 31 | { 32 | protected readonly IActionProvider _actionProvider; 33 | 34 | /// 35 | /// Default constructor 36 | /// 37 | /// 38 | public TakeScreenshotAction(IActionProvider actionProvider) 39 | { 40 | _actionProvider = actionProvider; 41 | } 42 | 43 | /// 44 | /// Take screenshot 45 | /// 46 | /// screenshot name 47 | /// throws if driver does not support taking a screenshot 48 | /// 49 | /// 50 | public virtual IActionProvider TakeScreenshot(string screenshotName, bool throwsIfNotSupported, ImageFormat format) 51 | { 52 | format = format ?? ImageFormat.Png; 53 | 54 | if (string.IsNullOrEmpty(screenshotName)) 55 | { 56 | screenshotName = GetScreenshotName(format); 57 | } 58 | 59 | ITakesScreenshot screenshotDriver = null; 60 | 61 | try 62 | { 63 | screenshotDriver = ((ITakesScreenshot)_actionProvider.UsingFixture.Driver); 64 | } 65 | catch (Exception) 66 | { 67 | if(throwsIfNotSupported) 68 | throw; 69 | } 70 | 71 | if (screenshotDriver != null) 72 | { 73 | screenshotDriver.GetScreenshot().SaveAsFile(screenshotName,format); 74 | } 75 | 76 | return _actionProvider; 77 | } 78 | 79 | protected virtual string GetScreenshotName(ImageFormat format) 80 | { 81 | StackTrace stackTrace = new StackTrace(); 82 | 83 | StackFrame stackFrame = null; 84 | 85 | foreach (var frame in stackTrace.GetFrames()) 86 | { 87 | if (frame.GetMethod().DeclaringType.Assembly != GetType().Assembly) 88 | { 89 | stackFrame = frame; 90 | break; 91 | } 92 | } 93 | 94 | if (stackFrame == null) 95 | { 96 | return "UNKNOWN"; 97 | } 98 | 99 | var method = stackFrame.GetMethod(); 100 | 101 | string returnName = method.DeclaringType != null ? method.DeclaringType.Name + "_" : ""; 102 | 103 | returnName += method.Name + "." + format.ToString().ToLower(); 104 | 105 | return returnName; 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Impl/ThenSubmitAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using OpenQA.Selenium; 8 | 9 | namespace SeleniumFixture.Impl 10 | { 11 | /// 12 | /// TheSubmit provider 13 | /// 14 | public interface IThenSubmitAction : IActionProvider 15 | { 16 | /// 17 | /// Submit the form you just filled 18 | /// 19 | /// this 20 | IYieldsAction ThenSubmit(); 21 | } 22 | 23 | /// 24 | /// Then submit provider 25 | /// 26 | public class ThenSubmitAction : FixtureActionProvider, IThenSubmitAction 27 | { 28 | protected readonly IWebElement _formElement; 29 | 30 | /// 31 | /// Default constructor 32 | /// 33 | /// 34 | /// 35 | public ThenSubmitAction(Fixture fixture, IWebElement formElement) : base(fixture) 36 | { 37 | _formElement = formElement; 38 | } 39 | 40 | /// 41 | /// Submit the form you just filled 42 | /// 43 | /// this 44 | public virtual IYieldsAction ThenSubmit() 45 | { 46 | _formElement.Submit(); 47 | 48 | var configuration = _fixture.Configuration; 49 | 50 | var waitTime = (int)(configuration.FixtureImplicitWait * 1000); 51 | 52 | if (waitTime >= 0) 53 | { 54 | Thread.Sleep(waitTime); 55 | } 56 | 57 | if (configuration.AlwaysWaitForAjax) 58 | { 59 | _fixture.Wait.ForAjax(); 60 | } 61 | 62 | return new YieldsAction(_fixture); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Impl/WaitAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using OpenQA.Selenium; 8 | 9 | namespace SeleniumFixture.Impl 10 | { 11 | 12 | /// 13 | /// Provides wait fluent syntax 14 | /// 15 | public interface IWaitAction 16 | { 17 | /// 18 | /// Wait for X number of seconds. 19 | /// 20 | /// wait time in seconds 21 | /// fluent syntax object 22 | IWaitAction For(double seconds); 23 | 24 | /// 25 | /// Wait for no ajax calls to be active 26 | /// 27 | /// timeout in seconds 28 | /// fluent syntax object 29 | IWaitAction ForAjax(double? timeout = null); 30 | 31 | /// 32 | /// Wait for an element to be visible 33 | /// 34 | /// element selector 35 | /// timeout in seconds 36 | /// fluent syntax object 37 | IWaitAction ForElement(string selector, double? timeout = null); 38 | 39 | /// 40 | /// Wait for an element to be visible 41 | /// 42 | /// element selector 43 | /// timeout in seconds 44 | /// fluent syntax object 45 | IWaitAction ForElement(By selector, double? timeout = null); 46 | 47 | /// 48 | /// Wait for page source to contain a specific string 49 | /// 50 | /// string to check for in page source 51 | /// timeout in seconds 52 | /// fluent syntax object 53 | IWaitAction ForPageSourceToContain(string stringToCheckFor, double? timeout = null); 54 | 55 | /// 56 | /// Wait for page source to pass a specific test 57 | /// 58 | /// function to test for 59 | /// timeout in seconds 60 | /// fluent syntax object 61 | IWaitAction ForPageSource(Func matchFunc, double? timeout = null); 62 | 63 | /// 64 | /// Wait for a page title 65 | /// 66 | /// page title 67 | /// timeout in seconds 68 | /// fluent syntax object 69 | IWaitAction ForPageTitle(string pageTitle, double? timeout = null); 70 | 71 | /// 72 | /// Wait for a page title by specified func 73 | /// 74 | /// function to test against the page title 75 | /// timeout in seconds 76 | /// fluent syntax object 77 | IWaitAction ForPageTitle(Func pageTitleFunc,double? timeout = null); 78 | 79 | /// 80 | /// Wait until the provided delegate is true 81 | /// 82 | /// func to test 83 | /// timeout in seconds 84 | /// fluent syntax object 85 | IWaitAction Until(Func testFunc, double? timeout = null); 86 | 87 | /// 88 | /// Provides a way back to action syntax 89 | /// 90 | IActionProvider Then { get; } 91 | } 92 | 93 | /// 94 | /// Provides wait fluent syntax 95 | /// 96 | public class WaitAction : IWaitAction 97 | { 98 | protected readonly IActionProvider _actionProvider; 99 | 100 | /// 101 | /// Default constructor 102 | /// 103 | /// 104 | public WaitAction(IActionProvider actionProvider) 105 | { 106 | _actionProvider = actionProvider; 107 | Then = _actionProvider; 108 | } 109 | 110 | /// 111 | /// Wait for X number of seconds. 112 | /// 113 | /// 114 | /// 115 | public virtual IWaitAction For(double seconds) 116 | { 117 | Thread.Sleep((int)(seconds * 1000)); 118 | 119 | return this; 120 | } 121 | 122 | /// 123 | /// Wait for no ajax calls to be active 124 | /// 125 | /// timeout in seconds 126 | /// fluent syntax object 127 | public virtual IWaitAction ForAjax(double? timeout = null) 128 | { 129 | return Until( 130 | i => 131 | { 132 | // static cast because I want an exception to be thrown when the driver doesn't support executing javascript 133 | IJavaScriptExecutor executor = (IJavaScriptExecutor)_actionProvider.UsingFixture.Driver; 134 | 135 | return (bool)executor.ExecuteScript(_actionProvider.UsingFixture.Configuration.AjaxActiveTest); 136 | }, timeout) 137 | .For(0.1); 138 | } 139 | 140 | /// 141 | /// Wait for an element to be present 142 | /// 143 | /// element selector 144 | /// timeout in seconds 145 | /// fluent syntax object 146 | public virtual IWaitAction ForElement(string selector, double? timeout = null) 147 | { 148 | return Until(i => i.CheckForElement(selector), timeout); 149 | } 150 | 151 | /// 152 | /// Wait for an element to be present 153 | /// 154 | /// element selector 155 | /// timeout in seconds 156 | /// fluent syntax object 157 | public virtual IWaitAction ForElement(By selector, double? timeout = null) 158 | { 159 | return Until(i => i.CheckForElement(selector), timeout); 160 | } 161 | 162 | /// 163 | /// Wait for page source to contain a specific string 164 | /// 165 | /// string to check for in page source 166 | /// timeout in seconds 167 | /// fluent syntax object 168 | public IWaitAction ForPageSourceToContain(string stringToCheckFor, double? timeout = null) 169 | { 170 | return Until(i => i.Get.PageSource.Contains(stringToCheckFor), timeout); 171 | } 172 | 173 | /// 174 | /// Wait for page source to contain a specific string 175 | /// 176 | /// function to test the page source 177 | /// timeout in seconds 178 | /// fluent syntax object 179 | public IWaitAction ForPageSource(Func matchFunc, double? timeout = null) 180 | { 181 | return Until(i => matchFunc(i.Get.PageSource), timeout); 182 | } 183 | 184 | /// 185 | /// Wait for a page title 186 | /// 187 | /// 188 | /// 189 | /// 190 | public virtual IWaitAction ForPageTitle(string pageTitle, double? timeout = null) 191 | { 192 | return ForPageTitle(s => s.Equals(pageTitle)); 193 | } 194 | 195 | /// 196 | /// Wait for a page title by specified func 197 | /// 198 | /// 199 | /// 200 | /// 201 | public virtual IWaitAction ForPageTitle(Func pageTitleFunc, double? timeout = null) 202 | { 203 | return Until(i => pageTitleFunc(i.Get.PageTitle), timeout); 204 | } 205 | 206 | /// 207 | /// Wait until the provided delegate is true 208 | /// 209 | /// func to test 210 | /// timeout in seconds 211 | /// fluent syntax object 212 | public virtual IWaitAction Until(Func testFunc, double? timeout = null) 213 | { 214 | if (!timeout.HasValue) 215 | { 216 | timeout = _actionProvider.UsingFixture.Configuration.DefaultTimeout; 217 | } 218 | 219 | DateTime expire = DateTime.Now.AddSeconds(timeout.Value); 220 | bool untilResult = false; 221 | 222 | int defaultWaitIntercal = (int)(_actionProvider.UsingFixture.Configuration.DefaultWaitInterval * 1000); 223 | 224 | while (!untilResult) 225 | { 226 | Thread.Sleep(defaultWaitIntercal); 227 | 228 | untilResult = testFunc(_actionProvider); 229 | 230 | if (DateTime.Now > expire) 231 | { 232 | break; 233 | } 234 | } 235 | 236 | if (!untilResult) 237 | { 238 | throw new Exception("Timedout waiting: " + timeout); 239 | } 240 | 241 | return this; 242 | } 243 | 244 | /// 245 | /// Provides a way back to action syntax 246 | /// 247 | public virtual IActionProvider Then { get; private set; } 248 | } 249 | } 250 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Impl/YieldsAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using SimpleFixture; 7 | 8 | namespace SeleniumFixture.Impl 9 | { 10 | public interface IYieldsAction 11 | { 12 | /// 13 | /// Yields a Page Object using SimpleFixture 14 | /// 15 | /// Type of object to Generate 16 | /// request name 17 | /// constraints for the locate 18 | /// new T 19 | T Yields(string requestName = null, object constraints = null); 20 | 21 | /// 22 | /// Yields a Page Object using SimpleFixture 23 | /// 24 | /// Type of object to Generate 25 | /// request name 26 | /// constraints for the locate 27 | /// new instance 28 | object Yields(Type type, string requestName = null, object constraints = null); 29 | } 30 | 31 | /// 32 | /// Provides fluent syntax for yields 33 | /// 34 | public class YieldsAction : IYieldsAction 35 | { 36 | protected readonly IActionProvider _actionProvider; 37 | 38 | /// 39 | /// Default constructor 40 | /// 41 | /// action provider 42 | public YieldsAction(IActionProvider fixture) 43 | { 44 | _actionProvider = fixture; 45 | } 46 | 47 | /// 48 | /// Yields a Page Object using SimpleFixture 49 | /// 50 | /// Type of object to Generate 51 | /// request name 52 | /// constraints for the locate 53 | /// new T 54 | public virtual T Yields(string requestName = null, object constraints = null) 55 | { 56 | return (T)Yields(typeof(T), requestName, constraints); 57 | } 58 | 59 | /// 60 | /// Yields a Page Object using SimpleFixture 61 | /// 62 | /// Type of object to Generate 63 | /// request name 64 | /// constraints for the locate 65 | /// new instance 66 | public virtual object Yields(Type type, string requestName = null, object constraints = null) 67 | { 68 | var request = new DataRequest(null, _actionProvider.UsingFixture.Data, type, requestName, false, constraints, null); 69 | 70 | return _actionProvider.UsingFixture.Data.Generate(request); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/SeleniumFixture/ImportAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SeleniumFixture 4 | { 5 | public class ImportAttribute : Attribute 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/SeleniumFixture/LanguageExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using OpenQA.Selenium; 7 | using OpenQA.Selenium.Interactions; 8 | 9 | namespace SeleniumFixture 10 | { 11 | public static class LanguageExtensions 12 | { 13 | public static void Apply(this IEnumerable enumerable, Action action) 14 | { 15 | foreach (T t in enumerable) 16 | { 17 | action(t); 18 | } 19 | } 20 | 21 | public static IReadOnlyCollection Click(this IReadOnlyCollection elements) 22 | { 23 | elements.Apply(e => e.Click()); 24 | 25 | return elements; 26 | } 27 | 28 | public static IReadOnlyCollection Clear(this IReadOnlyCollection elements) 29 | { 30 | elements.Apply(e => e.Clear()); 31 | 32 | return elements; 33 | } 34 | 35 | public static IReadOnlyCollection SendKeys(this IReadOnlyCollection elements, 36 | string keys) 37 | { 38 | elements.Apply(e => e.SendKeys(keys)); 39 | 40 | return elements; 41 | } 42 | 43 | public static IReadOnlyCollection SendKeys(this IReadOnlyCollection elements, 44 | Func keysFunc) 45 | { 46 | elements.Apply(e => e.SendKeys(keysFunc())); 47 | 48 | return elements; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/SeleniumFixture/PageObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using SeleniumFixture.Impl; 7 | 8 | namespace SeleniumFixture 9 | { 10 | /// 11 | /// Base object that represents a web element 12 | /// 13 | public class PageObject 14 | { 15 | /// 16 | /// Action that will be called after the page has been created and imports satisfied 17 | /// 18 | protected Action Validate { get; set; } 19 | 20 | /// 21 | /// Perform action on a page 22 | /// 23 | protected IActionProvider I { get; private set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SeleniumFixture")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SeleniumFixture")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("58981bdd-0c8b-4f94-9af9-fcd64b729aa5")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/SeleniumFixture/SeleniumFixture.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using OpenQA.Selenium; 8 | using OpenQA.Selenium.Support.PageObjects; 9 | using SimpleFixture.Impl; 10 | 11 | namespace SimpleFixture.Selenium 12 | { 13 | public class SeleniumFixture : Fixture 14 | { 15 | #region Constructor 16 | public SeleniumFixture(IWebDriver webDriver, string baseAddress = null) 17 | : base(new SeleniumFixtureConfiguration()) 18 | { 19 | Initialize(webDriver, baseAddress); 20 | } 21 | #endregion 22 | 23 | #region Public Members 24 | 25 | public IWebDriver WebDriver { get; private set; } 26 | 27 | public string BaseAddress { get; private set; } 28 | 29 | public void PopulateForm(string formName, object formValues) 30 | { 31 | 32 | } 33 | 34 | public T Page() 35 | { 36 | return Locate(); 37 | } 38 | 39 | #endregion 40 | 41 | #region Private Members 42 | private void Initialize(IWebDriver webDriver, string baseAddress) 43 | { 44 | Return(this); 45 | Return(webDriver); 46 | Return(baseAddress).WhenNamed("BaseAddress"); 47 | 48 | WebDriver = webDriver; 49 | BaseAddress = baseAddress; 50 | 51 | Behavior.Add((r, o) => 52 | { 53 | if (o.GetType().IsValueType || o is string) 54 | { 55 | return o; 56 | } 57 | 58 | PageFactory.InitElements(webDriver, o); 59 | 60 | return o; 61 | }); 62 | 63 | Behavior.Add(ImportPropertiesOnLocate); 64 | } 65 | 66 | private object ImportPropertiesOnLocate(DataRequest r, object o) 67 | { 68 | if (o.GetType().IsValueType || o is string || r.Populate) 69 | { 70 | return o; 71 | } 72 | 73 | IModelService modelService = Configuration.Locate(); 74 | 75 | TypePopulator typePopulator = new TypePopulator(Configuration.Locate(), new ImportSeleniumTypePropertySelector(Configuration.Locate())); 76 | 77 | typePopulator.Populate(o, r, modelService.GetModel(r.RequestedType)); 78 | 79 | return 0; 80 | } 81 | #endregion 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/SeleniumFixture/SeleniumFixture.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {9EB00E94-F1DB-40E4-A131-4B28B347785F} 8 | Library 9 | Properties 10 | SeleniumFixture 11 | SeleniumFixture 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | bin\Debug\SeleniumFixture.XML 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | bin\Release\SeleniumFixture.XML 33 | 34 | 35 | 36 | ..\packages\SimpleFixture.1.3.0\lib\portable45-net45+win8+wp8+wpa81\SimpleFixture.dll 37 | True 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | ..\packages\Selenium.WebDriver.2.53.0\lib\net40\WebDriver.dll 49 | True 50 | 51 | 52 | ..\packages\Selenium.Support.2.53.0\lib\net40\WebDriver.Support.dll 53 | True 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | xcopy /Y "$(TargetPath)" "$(ProjectDir)..\..\Output\bin\$(PlatformName)\" 99 | xcopy /Y "$(TargetDir)$(TargetName).xml" "$(ProjectDir)..\..\Output\bin\$(PlatformName)\" 100 | xcopy /Y "$(TargetDir)$(TargetName).pdb" "$(ProjectDir)..\..\Output\bin\$(PlatformName)\" 101 | 102 | 103 | 110 | -------------------------------------------------------------------------------- /src/SeleniumFixture/SeleniumFixture.nuspec: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | SeleniumFixture 5 | $version$ 6 | SeleniumFixture 7 | Ian Johnson 8 | Ian Johnson 9 | https://github.com/ipjohnson/SeleniumFixture/blob/master/License.md 10 | https://github.com/ipjohnson/SeleniumFixture 11 | false 12 | Companion library for Selenium that helps implement the PageObject pattern. 13 | Adding dnx support for SeleniumFixture.xUnit 14 | Copyright © 2015 15 | Selenium Test Fixture Data Generation PageObject 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/SeleniumFixture/SeleniumFixtureConfiguration.cs: -------------------------------------------------------------------------------- 1 | using SimpleFixture; 2 | using SimpleFixture.Impl; 3 | 4 | namespace SeleniumFixture 5 | { 6 | /// 7 | /// Algorithm to use when selecting 8 | /// 9 | public enum SelectorAlgorithm 10 | { 11 | /// 12 | /// Detech which method to use 13 | /// 14 | Auto, 15 | 16 | /// 17 | /// Use jQuery selector 18 | /// 19 | JQuery, 20 | 21 | /// 22 | /// CSS selector 23 | /// 24 | CSS, 25 | 26 | /// 27 | /// XPath 28 | /// 29 | XPath 30 | } 31 | 32 | /// 33 | /// Configuration object for SeleniumFoxture 34 | /// 35 | public class SeleniumFixtureConfiguration 36 | { 37 | /// 38 | /// Default constructor 39 | /// 40 | public SeleniumFixtureConfiguration() 41 | { 42 | Initialize(); 43 | } 44 | 45 | private void Initialize() 46 | { 47 | Selector = SelectorAlgorithm.Auto; 48 | 49 | DefaultTimeout = 10; 50 | DefaultWaitInterval = 0.1; 51 | FixtureImplicitWait = 0.2; 52 | 53 | AjaxActiveTest = "return (document.readyState === \"complete\") && ((window.jQuery || { active : 0 }).active == 0);"; 54 | 55 | AlwaysWaitForAjax = true; 56 | ExecuteValidate = true; 57 | WrapValidationExceptions = true; 58 | ValidateMember = "Validate"; 59 | DataConfiguration = new DefaultFixtureConfiguration(); 60 | } 61 | 62 | /// 63 | /// String to test if ajax is still active 64 | /// 65 | public string AjaxActiveTest { get; set; } 66 | 67 | /// 68 | /// Always wait for ajax after click, double click, navigate and submit 69 | /// 70 | public bool AlwaysWaitForAjax { get; set; } 71 | 72 | /// 73 | /// Base address for navigation 74 | /// 75 | public string BaseAddress { get; set; } 76 | 77 | /// 78 | /// Default timeout for actions, in seconds 79 | /// 80 | public double DefaultTimeout { get; set; } 81 | 82 | /// 83 | /// Time to wait in between testing for wait condition 84 | /// 85 | public double DefaultWaitInterval { get; set; } 86 | 87 | /// 88 | /// Execute validate on page objects 89 | /// 90 | public bool ExecuteValidate { get; set; } 91 | 92 | /// 93 | /// Fixture will wait a small amount of time after every time Click, DoubleClick and Navigate is called 94 | /// 95 | public double FixtureImplicitWait { get; set; } 96 | 97 | /// 98 | /// Element selector algorithm 99 | /// 100 | public SelectorAlgorithm Selector { get; set; } 101 | 102 | /// 103 | /// Name of member to execute on validation 104 | /// 105 | public string ValidateMember { get; set; } 106 | 107 | /// 108 | /// Wrap validation exception with extra information 109 | /// 110 | public bool WrapValidationExceptions { get; set; } 111 | 112 | /// 113 | /// Data configuration for SimpleFixture 114 | /// 115 | public DefaultFixtureConfiguration DataConfiguration { get; set; } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/SeleniumFixture/Using.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using SeleniumFixture.Impl; 7 | 8 | namespace SeleniumFixture 9 | { 10 | /// 11 | /// Provides custom implemenation of Selenium By class 12 | /// 13 | public static class Using 14 | { 15 | /// 16 | /// Automatically decide which type of selector (jQuery, CSS, XPath) to use based on the type of selector and if jQuery is enabled for the site 17 | /// 18 | /// selector string 19 | /// By implementation 20 | public static AutoBy Auto(string selector) 21 | { 22 | return new AutoBy(selector); 23 | } 24 | 25 | /// 26 | /// Select elements using jQuery selector syntax 27 | /// 28 | /// jQuery selector 29 | /// jQuery By implementation 30 | public static JQueryBy JQuery(string selector) 31 | { 32 | return new JQueryBy(selector); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/SeleniumFixture/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/wrap/SeleniumFixture/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "frameworks": { 4 | "net45": { 5 | "wrappedProject": "../../SeleniumFixture/SeleniumFixture.csproj", 6 | "bin": { 7 | "assembly": "../../SeleniumFixture/obj/{configuration}/SeleniumFixture.dll", 8 | "pdb": "../../SeleniumFixture/obj/{configuration}/SeleniumFixture.pdb" 9 | }, 10 | "dependencies": { 11 | "Selenium.Support": "2.53.0", 12 | "Selenium.WebDriver": "2.53.0", 13 | "SimpleFixture": "1.3.0" 14 | } 15 | } 16 | } 17 | } --------------------------------------------------------------------------------