Created
September 5, 2021 04:36
-
-
Save dsibinski/70631294e17f4a0230f4fdbbfbc71fe1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class CypressTestsBase | |
{ | |
protected void RunCypressTest(string cypressSpecFilePath) | |
{ | |
var process = new System.Diagnostics.Process(); | |
var testAssemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | |
if (string.IsNullOrEmpty(testAssemblyPath)) | |
{ | |
throw new Exception("Cannot find test assembly path!"); | |
} | |
var reactAppPath = Path.GetFullPath(Path.Combine(testAssemblyPath, @"..\..\..\..\cypress-react-app")); | |
var startInfo = new System.Diagnostics.ProcessStartInfo | |
{ | |
UseShellExecute = false, | |
WorkingDirectory = reactAppPath, | |
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden, FileName = "cmd.exe", | |
RedirectStandardInput = true, | |
RedirectStandardOutput = true | |
}; | |
process.StartInfo = startInfo; | |
process.Start(); | |
process.StandardInput.WriteLine($"npx cypress run --spec \"cypress/integration/{cypressSpecFilePath}\" & exit"); | |
var cypressProcessOutput = process.StandardOutput.ReadToEnd(); | |
process.WaitForExit(); | |
TestContext.Out.WriteLine($@"Cypress spec {cypressSpecFilePath} run output:"); | |
TestContext.Out.WriteLine(cypressProcessOutput); | |
Assert.AreEqual(0, process.ExitCode, $"Some Cypress tests from {cypressSpecFilePath} failed. See the details for details."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment