Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet core in parallel script #27

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ public void Teardown()
{
if (_driver == null) return;

_sessionId = _driver.SessionId;
_driver.Quit();
//TODO fix this as it doesn't seem to update the status for failed tests
var isTestPassed = TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Passed;
new SimpleSauce().Rdc.UpdateTestStatus(isTestPassed, _sessionId);
new SimpleSauce().Rdc.UpdateTestStatus(isTestPassed, _driver.SessionId);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,11 @@ public void ShouldPassAndSetTestStatusToPass()
[TestCleanup]
public void Teardown()
{
if (_driver != null)
{
_sessionId = _driver.SessionId;
_driver.Quit();
}
if (_driver == null) return;

var isTestPassed = TestContext.CurrentTestOutcome == UnitTestOutcome.Passed;

new SimpleSauce().Rdc.UpdateTestStatus(isTestPassed, _sessionId);
new SimpleSauce().Rdc.UpdateTestStatus(isTestPassed, _driver.SessionId);
_driver.Quit();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
<PackageReference Include="coverlet.collector" Version="1.0.1" />
<PackageReference Include="Selenium.WebDriver" Version="4.0.0-alpha04" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;
using System;
using System.Collections.Generic;

namespace Core.Selenium4.MsTest.Scripts
{
[TestClass]
public class UnitTest1
{
/*
* How to execute parallel tests at the method level using MsTest
*
* Make sure that your AssemplyInfo.cs for the project has this property:
* [assembly: Parallelize(Workers = 100, Scope = ExecutionScope.MethodLevel)]
*
* There are recommendations on the web to configure the .runsettings file,
* but you do not need it to run in parallel.
*
* In this example, we can run many Selenium test methods in parallel without any issue
*/
IWebDriver _driver;
private string sauceUserName;
private string sauceAccessKey;
private Dictionary<string, object> sauceOptions;
public TestContext TestContext { get; set; }
[TestInitialize]
public void Setup()
{
//TODO please supply your Sauce Labs user name in an environment variable
sauceUserName = Environment.GetEnvironmentVariable("SAUCE_USERNAME", EnvironmentVariableTarget.User);
//TODO please supply your own Sauce Labs access Key in an environment variable
sauceAccessKey = Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY", EnvironmentVariableTarget.User);
sauceOptions = new Dictionary<string, object>
{
["username"] = sauceUserName,
["accessKey"] = sauceAccessKey
};
var chromeOptions = new ChromeOptions
{
BrowserVersion = "latest",
PlatformName = "Windows 10"
};
sauceOptions.Add("name", TestContext.TestName);
chromeOptions.AddAdditionalOption("sauce:options", sauceOptions);

_driver = new RemoteWebDriver(new Uri("https://ondemand.saucelabs.com/wd/hub"),
chromeOptions.ToCapabilities(), TimeSpan.FromSeconds(30));
}
[TestMethod]
public void TestMethod1()
{
GoToThenAssert();
}
private void GoToThenAssert()
{
_driver.Navigate().GoToUrl("https://www.saucedemo.com");
Assert.IsTrue(_driver.Url.Contains("saucedemo.com"));
}
[TestMethod]
public void TestMethod2()
{
GoToThenAssert();
}
[TestMethod]
public void TestMethod3()
{
GoToThenAssert();
}
}
}
9 changes: 9 additions & 0 deletions SauceExamples/SauceExamples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SampleApps", "SampleApps",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Appium4.NUnit.Scripts", "Appium4.NUnit.Scripts\Appium4.NUnit.Scripts.csproj", "{51476835-726E-4948-AFE7-B05B0FA42BE6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DotnetCore", "DotnetCore", "{35920FCA-2547-4818-AC6F-0797CFD85549}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.Selenium4.MsTest.Scripts", "DotnetCore\Core.Selenium4.MsTest.Scripts\Core.Selenium4.MsTest.Scripts.csproj", "{E507CB7D-4628-47B8-AF47-72EC1EEB345D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -82,6 +86,10 @@ Global
{51476835-726E-4948-AFE7-B05B0FA42BE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{51476835-726E-4948-AFE7-B05B0FA42BE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{51476835-726E-4948-AFE7-B05B0FA42BE6}.Release|Any CPU.Build.0 = Release|Any CPU
{E507CB7D-4628-47B8-AF47-72EC1EEB345D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E507CB7D-4628-47B8-AF47-72EC1EEB345D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E507CB7D-4628-47B8-AF47-72EC1EEB345D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E507CB7D-4628-47B8-AF47-72EC1EEB345D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -98,6 +106,7 @@ Global
{43F0822F-C5D4-44CE-A7BF-4FE6B6C4968C} = {C06B06E4-9DD7-4536-93D9-343944EF4F8D}
{FC693E5B-3A53-49EB-A28B-FB5A584E23C2} = {21DDBE02-10ED-40E3-8F18-05B9845577BC}
{51476835-726E-4948-AFE7-B05B0FA42BE6} = {21DDBE02-10ED-40E3-8F18-05B9845577BC}
{E507CB7D-4628-47B8-AF47-72EC1EEB345D} = {35920FCA-2547-4818-AC6F-0797CFD85549}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6019E59C-E9C4-4734-90C4-B49A0CCF0A59}
Expand Down
2 changes: 1 addition & 1 deletion SauceExamples/Web.Tests/BestPractices/test/LoginFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Selenium3.Nunit.Framework.BestPractices.test
{
[TestFixture]
[TestFixtureSource(typeof(CrossBrowserData),
nameof(CrossBrowserData.HeadlessTestData))]
nameof(CrossBrowserData.LatestConfigurations))]
[Parallelizable]
public class LoginFeature : BaseTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Selenium3.Nunit.Framework.BestPractices.test
{
[TestFixture]
[TestFixtureSource(typeof(CrossBrowserData),
nameof(CrossBrowserData.HeadlessTestData))]
nameof(CrossBrowserData.LatestConfigurations))]
[Parallelizable]
public class LogoutFeature : BaseTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Selenium3.Nunit.Framework.BestPractices.test
{
[TestFixture]
[TestFixtureSource(typeof(CrossBrowserData),
nameof(CrossBrowserData.HeadlessTestData))]
nameof(CrossBrowserData.LatestConfigurations))]
[Parallelizable]
public class ProductsPageFeature : BaseTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Selenium3.Nunit.Framework.BestPractices.test
[TestFixture]
[Parallelizable]
[TestFixtureSource(typeof(CrossBrowserData),
nameof(CrossBrowserData.HeadlessTestData))]
nameof(CrossBrowserData.LatestConfigurations))]
public class ShoppingCartFeature : BaseTest
{
public ShoppingCartFeature(string browser, string browserVersion, string osPlatform) :
Expand Down
10 changes: 8 additions & 2 deletions SauceExamples/Web.Tests/CrossBrowserData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ public static IEnumerable LatestConfigurations
yield return new TestFixtureData("Chrome", "latest-2", "Windows 7");

//safari
//doesn't work
//yield return new TestFixtureData("Safari", "latest", "macOS 10.15");
yield return new TestFixtureData("Safari", "13.0", "macOS 10.15");
yield return new TestFixtureData("Safari", "latest", "macOS 10.14");
yield return new TestFixtureData("Safari", "latest", "macOS 10.13");
yield return new TestFixtureData("Safari", "latest-1", "macOS 10.12");
yield return new TestFixtureData("Safari", "latest", "macOS 10.12");

//firefox
yield return new TestFixtureData("Firefox", "latest", "macOS 10.13");
Expand All @@ -42,7 +45,10 @@ public static IEnumerable LatestConfigurations
//IE
yield return new TestFixtureData("Internet Explorer", "latest", "Windows 10");
yield return new TestFixtureData("Internet Explorer", "latest", "Windows 7");
yield return new TestFixtureData("Internet Explorer", "10.0", "Windows 7");

//Doesn't work
//yield return new TestFixtureData("Internet Explorer", "latest", "Windows 8");
//yield return new TestFixtureData("Internet Explorer", "10.0", "Windows 7");

}
}
Expand Down
32 changes: 16 additions & 16 deletions SauceExamples/Web.Tests/Selenium3.Nunit.Framework.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit3TestAdapter.3.11.2\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.11.2\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\packages\NUnit.3.11.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" />
<Import Project="..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.props')" />
<Import Project="..\packages\NUnit3TestAdapter.3.16.1\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.16.1\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\packages\NUnit.3.12.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.12.0\build\NUnit.props')" />
<Import Project="..\packages\MSTest.TestAdapter.2.1.0\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.2.1.0\build\net45\MSTest.TestAdapter.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -41,20 +41,20 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="FluentAssertions, Version=5.5.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.5.5.0\lib\net45\FluentAssertions.dll</HintPath>
<Reference Include="FluentAssertions, Version=5.10.2.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.5.10.2\lib\net45\FluentAssertions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Protocols">
<HintPath>..\..\..\..\..\..\..\Users\nikolay\.nuget\packages\microsoft.identitymodel.protocols\5.2.0\lib\netstandard1.4\Microsoft.IdentityModel.Protocols.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.4.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
<HintPath>..\packages\MSTest.TestFramework.2.1.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.4.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
<HintPath>..\packages\MSTest.TestFramework.2.1.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=3.11.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.11.0\lib\net45\nunit.framework.dll</HintPath>
<Reference Include="nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="RestSharp, Version=106.0.0.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
<HintPath>..\packages\RestSharp.106.10.1\lib\net452\RestSharp.dll</HintPath>
Expand All @@ -66,8 +66,8 @@
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll</HintPath>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
Expand Down Expand Up @@ -121,10 +121,10 @@
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.targets'))" />
<Error Condition="!Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.11.0\build\NUnit.props'))" />
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.11.2\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.11.2\build\net35\NUnit3TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.2.1.0\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.1.0\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.2.1.0\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.1.0\build\net45\MSTest.TestAdapter.targets'))" />
<Error Condition="!Exists('..\packages\NUnit.3.12.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.12.0\build\NUnit.props'))" />
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.16.1\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.16.1\build\net35\NUnit3TestAdapter.props'))" />
</Target>
<Import Project="..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.targets')" />
<Import Project="..\packages\MSTest.TestAdapter.2.1.0\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.2.1.0\build\net45\MSTest.TestAdapter.targets')" />
</Project>
2 changes: 1 addition & 1 deletion SauceExamples/Web.Tests/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
12 changes: 6 additions & 6 deletions SauceExamples/Web.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DotNetSeleniumExtras.WaitHelpers" version="3.11.0" targetFramework="net461" />
<package id="FluentAssertions" version="5.5.0" targetFramework="net461" />
<package id="MSTest.TestAdapter" version="1.4.0" targetFramework="net461" />
<package id="MSTest.TestFramework" version="1.4.0" targetFramework="net461" />
<package id="NUnit" version="3.11.0" targetFramework="net461" />
<package id="NUnit3TestAdapter" version="3.11.2" targetFramework="net461" />
<package id="FluentAssertions" version="5.10.2" targetFramework="net461" />
<package id="MSTest.TestAdapter" version="2.1.0" targetFramework="net461" />
<package id="MSTest.TestFramework" version="2.1.0" targetFramework="net461" />
<package id="NUnit" version="3.12.0" targetFramework="net461" />
<package id="NUnit3TestAdapter" version="3.16.1" targetFramework="net461" developmentDependency="true" />
<package id="RestSharp" version="106.10.1" targetFramework="net461" />
<package id="Selenium.Support" version="3.141.0" targetFramework="net461" />
<package id="Selenium.WebDriver" version="3.141.0" targetFramework="net461" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
</packages>