Skip to content

Instantly share code, notes, and snippets.

@dsibinski
Created September 5, 2021 04:36
Show Gist options
  • Save dsibinski/70631294e17f4a0230f4fdbbfbc71fe1 to your computer and use it in GitHub Desktop.
Save dsibinski/70631294e17f4a0230f4fdbbfbc71fe1 to your computer and use it in GitHub Desktop.
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