Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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.StandardInput.WriteLine($"npx cypress run --spec \"cypress/integration/{cypressSpecFilePath}\" & exit");
var cypressProcessOutput = process.StandardOutput.ReadToEnd();
TestContext.Out.WriteLine($@"Cypress spec {cypressSpecFilePath} run output:");
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