Exemple #1
0
        public static void ExecuteTest(this RemoteWebDriver driver, string testScript, params object[] args)
        {
            if (driver == null)
            {
                throw new ArgumentNullException(nameof(driver));
            }

            if (testScript == null)
            {
                throw new ArgumentNullException(nameof(testScript));
            }

            IWebElement testsConsole = driver.GetElementById("testsConsole");

            const string success = "Success";

            string consoleValue = testsConsole.GetAttribute("value");

            string arguments = JsonConvert.SerializeObject(args, new JsonSerializerSettings
            {
                DateFormatHandling    = DateFormatHandling.IsoDateFormat,
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            string finalTestScript = $"executeTest({testScript},'{arguments}');";

            driver.WaitForControlReady();

            driver.ExecuteScript(finalTestScript);

            int triesCount = 0;

            do
            {
                if (testsConsole.GetAttribute("value") != consoleValue)
                {
                    break;
                }
                Thread.Sleep(200);
                triesCount++;
            } while (triesCount < 50);

            consoleValue = testsConsole.GetAttribute("value");

            bool testIsPassed = consoleValue == success;

            Console.WriteLine("Test console value: " + consoleValue);
            Console.WriteLine("Url: " + driver.Url);
            Console.WriteLine("Final test script: " + finalTestScript);

            if (testIsPassed != true)
            {
                throw new InvalidOperationException(consoleValue);
            }
        }