This commit is contained in:
Tian Liao 2024-11-25 14:44:15 +08:00
commit 6370f28f8e

View file

@ -2,6 +2,7 @@
// Licensed under the MIT License. // Licensed under the MIT License.
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Threading;
using CalculatorUITestFramework; using CalculatorUITestFramework;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
@ -25,6 +26,7 @@ namespace CalculatorUITests
{ {
// Create session to launch a Calculator window // Create session to launch a Calculator window
_currencyServer = new MockedCurrencyServer(); _currencyServer = new MockedCurrencyServer();
Thread.Sleep(5000);
CalculatorDriver.Instance.SetupCalculatorSession(context); CalculatorDriver.Instance.SetupCalculatorSession(context);
} }
@ -45,8 +47,10 @@ namespace CalculatorUITests
[TestInitialize] [TestInitialize]
public void TestInit() public void TestInit()
{ {
VerifyConnection(); VerifyConnection("http://localhost/calctesting/file/?id=currency+converter+data&localCurrency=en-US");
VerifyConnection("http://localhost/calctesting/file/?id=currency+static+data&localizeFor=en-US");
CalculatorApp.EnsureCalculatorHasFocus(); CalculatorApp.EnsureCalculatorHasFocus();
Thread.Sleep(5000);
page.EnsureCalculatorIsCurrencyMode(); page.EnsureCalculatorIsCurrencyMode();
page.EnsureCalculatorResultTextIsZero(); page.EnsureCalculatorResultTextIsZero();
page.EnsureSameUnitsAreSelected(); page.EnsureSameUnitsAreSelected();
@ -58,14 +62,15 @@ namespace CalculatorUITests
page.ClearAll(); page.ClearAll();
} }
private static void VerifyConnection() private static void VerifyConnection(string url)
{ {
Console.WriteLine($"VerifyConnection begins: url: {url}");
var process = new Process(); var process = new Process();
var startInfo = new ProcessStartInfo var startInfo = new ProcessStartInfo
{ {
WindowStyle = ProcessWindowStyle.Hidden, WindowStyle = ProcessWindowStyle.Hidden,
FileName = "cmd.exe", FileName = "cmd.exe",
Arguments = @"/C curl ""http://localhost/calctesting/file/?id=currency+converter+data&localCurrency=""", Arguments = @$"/C curl ""{url}""",
RedirectStandardOutput = true, // Redirect the standard output RedirectStandardOutput = true, // Redirect the standard output
UseShellExecute = false, UseShellExecute = false,
CreateNoWindow = true CreateNoWindow = true
@ -74,7 +79,7 @@ namespace CalculatorUITests
process.Start(); process.Start();
var debug = process.StandardOutput.ReadToEnd(); var debug = process.StandardOutput.ReadToEnd();
process.WaitForExit(); process.WaitForExit();
Console.WriteLine($"----------- exitcode: {process.ExitCode}, curl result: {debug}"); Console.WriteLine($"VerifyConnection ends: exitcode: {process.ExitCode}, curl result: {debug}");
} }
private string NormalizeCurrencyText(string realValue, int fractionDigits) private string NormalizeCurrencyText(string realValue, int fractionDigits)