File tree Expand file tree Collapse file tree 4 files changed +89
-3
lines changed
examples/dotnet/SeleniumDocs Expand file tree Collapse file tree 4 files changed +89
-3
lines changed Original file line number Diff line number Diff line change 3
3
using OpenQA . Selenium . Edge ;
4
4
using OpenQA . Selenium . Firefox ;
5
5
using OpenQA . Selenium . IE ;
6
+ using SeleniumDocs . TestSupport ;
6
7
using WebDriverManager ;
7
8
using WebDriverManager . DriverConfigs . Impl ;
8
9
9
10
namespace SeleniumDocs . GettingStarted
10
11
{
11
- [ TestClass ]
12
+ [ TestClassCustom ]
12
13
public class InstallDriversTest
13
14
{
14
15
[ TestMethod ]
@@ -21,7 +22,6 @@ public void ChromeSession()
21
22
driver . Quit ( ) ;
22
23
}
23
24
24
- [ Ignore ] // WebDriverManager.Net does not resolve msedgedriver in Linux
25
25
[ TestMethod ]
26
26
public void EdgeSession ( )
27
27
{
@@ -42,7 +42,7 @@ public void FirefoxSession()
42
42
driver . Quit ( ) ;
43
43
}
44
44
45
- [ Ignore ] // Only runs on Windows
45
+ [ EnabledOnOs ( "WINDOWS" ) ]
46
46
[ TestMethod ]
47
47
public void InternetExplorerSession ( )
48
48
{
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Runtime . InteropServices ;
3
+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
4
+
5
+ namespace SeleniumDocs . TestSupport
6
+ {
7
+ // Solution based on — https://matt.kotsenas.com/posts/ignoreif-mstest
8
+ [ AttributeUsage ( AttributeTargets . Class | AttributeTargets . Method ) ]
9
+ public class EnabledOnOsAttribute : Attribute
10
+ {
11
+ public OSPlatform EnabledOnOs { get ; set ; }
12
+
13
+ public EnabledOnOsAttribute ( String platform )
14
+ {
15
+ EnabledOnOs = OSPlatform . Create ( platform ) ;
16
+ }
17
+
18
+ internal bool ShouldIgnore ( ITestMethod testMethod )
19
+ {
20
+ return ! RuntimeInformation . IsOSPlatform ( this . EnabledOnOs ) ;
21
+ }
22
+ }
23
+ }
Original file line number Diff line number Diff line change
1
+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
2
+
3
+ namespace SeleniumDocs . TestSupport
4
+ {
5
+ // Solution based on — https://matt.kotsenas.com/posts/ignoreif-mstest
6
+ public class TestClassCustomAttribute : TestClassAttribute
7
+ {
8
+ public override TestMethodAttribute GetTestMethodAttribute ( TestMethodAttribute testMethodAttribute )
9
+ {
10
+ if ( testMethodAttribute is TestMethodCustomAttribute )
11
+ {
12
+ return testMethodAttribute ;
13
+ }
14
+ return new TestMethodCustomAttribute ( ) ;
15
+ }
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ using System . Collections . Generic ;
2
+ using System . Reflection ;
3
+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
4
+
5
+ namespace SeleniumDocs . TestSupport
6
+ {
7
+ // Solution based on — https://matt.kotsenas.com/posts/ignoreif-mstest
8
+ public class TestMethodCustomAttribute : TestMethodAttribute
9
+ {
10
+ public override TestResult [ ] Execute ( ITestMethod testMethod )
11
+ {
12
+ var enabledOsAttributes = FindEnabledAttributes ( testMethod ) ;
13
+
14
+ foreach ( var enabledOsAttribute in enabledOsAttributes )
15
+ {
16
+ if ( enabledOsAttribute . ShouldIgnore ( testMethod ) )
17
+ {
18
+ var message = $ "Test not executed. Only enabled on '{ enabledOsAttribute . EnabledOnOs } ' OS.";
19
+ return new [ ]
20
+ {
21
+ new TestResult
22
+ {
23
+ Outcome = UnitTestOutcome . Inconclusive ,
24
+ TestFailureException = new AssertInconclusiveException ( message )
25
+ }
26
+ } ;
27
+ }
28
+ }
29
+ return base . Execute ( testMethod ) ;
30
+ }
31
+
32
+ private IEnumerable < EnabledOnOsAttribute > FindEnabledAttributes ( ITestMethod testMethod )
33
+ {
34
+ var enabledOsAttributes = new List < EnabledOnOsAttribute > ( ) ;
35
+ enabledOsAttributes . AddRange ( testMethod . GetAttributes < EnabledOnOsAttribute > ( inherit : true ) ) ;
36
+
37
+ var type = testMethod . MethodInfo . DeclaringType ;
38
+ while ( type != null )
39
+ {
40
+ enabledOsAttributes . AddRange ( type . GetCustomAttributes < EnabledOnOsAttribute > ( inherit : true ) ) ;
41
+ type = type . DeclaringType ;
42
+ }
43
+ return enabledOsAttributes ;
44
+ }
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments