Created
August 26, 2011 17:45
-
-
Save whittet/1173946 to your computer and use it in GitHub Desktop.
Visual Studio Macro to convert Exported Selenium C# from NUnit to MSTest per http://www.stormbase.net/converting-from-nunit-to-mstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System | |
Imports EnvDTE | |
Imports EnvDTE80 | |
Imports EnvDTE90 | |
Imports EnvDTE90a | |
Imports EnvDTE100 | |
Imports System.Diagnostics | |
Public Module SeleniumConvertNUnitToMSTest | |
Private Sub FindReplaceHelper(ByVal text As String) | |
DTE.Find.FindWhat = text | |
DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument | |
DTE.Find.MatchCase = True | |
DTE.Find.MatchWholeWord = True | |
DTE.Find.MatchInHiddenText = False | |
DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral | |
DTE.Find.Execute() | |
End Sub | |
Private Sub Replace(ByVal text As String, ByVal replace As String) | |
DTE.ExecuteCommand("Edit.Replace") | |
DTE.Find.Action = vsFindAction.vsFindActionReplaceAll | |
DTE.Find.ReplaceWith = replace | |
DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone | |
FindReplaceHelper(Text) | |
End Sub | |
Private Sub Find(ByVal text As String) | |
DTE.ExecuteCommand("Edit.Find") | |
DTE.Find.Action = vsFindAction.vsFindActionFind | |
DTE.Find.Backwards = False | |
FindReplaceHelper(text) | |
End Sub | |
Sub SeleniumConvertNUnitToMSTest() | |
Replace("using NUnit.Framework;", "using Microsoft.VisualStudio.TestTools.UnitTesting;") | |
'DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) | |
'DTE.ActiveDocument.Selection.Text = "//" | |
Replace("[TestFixture]", "[TestClass]") | |
Replace("[Test]", "[TestMethod]") | |
Replace("[SetUp]", "[TestInitialize]") | |
Replace("[TearDown]", "[TestCleanup]") | |
Replace("[TestFixtureSetUp]", "[ClassInitialize]") | |
Replace("[TestFixtureTearDown]", "[ClassCleanup]") | |
Replace("AssertionException", "AssertFailedException") | |
Replace("public class ", "public sealed class ") | |
'Prevent Code analysis build errors | |
Find("public sealed class ") | |
DTE.ExecuteCommand("Edit.Replace") | |
DTE.ActiveWindow.Close() | |
DTE.ActiveDocument.Selection.EndOfLine() | |
DTE.ActiveDocument.Selection.Text = " : IDisposable" | |
DTE.ActiveDocument.Selection.EndOfDocument() | |
DTE.ActiveDocument.Selection.LineUp(False, 3) | |
DTE.ActiveDocument.Selection.EndOfLine() | |
DTE.ActiveDocument.Selection.NewLine() | |
DTE.ActiveDocument.Selection.Text = "public void Dispose() { driver.Dispose(); }" | |
DTE.ActiveDocument.Save() | |
End Sub | |
End Module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
another solution for this need:
http://files.dotblogs.com.tw/hatelove/1311/20131126132839723.zip
introduction: http://www.dotblogs.com.tw/hatelove/archive/2013/11/26/selenium-ide-export-to-csharp-webdriver-mstest.aspx