Example #1
0
        /// <summary>
        /// Path is assuming that Phantomjs executable is in project folder (root) of tests.
        /// Path is from the root to the file or folder.
        /// </summary>
        /// <param name="path">Path to file (htm, html) or folder to files (htm, html)</param>
        /// <returns></returns> 
        public static IEnumerable<TestCaseData> GetTestResults(string path)
        {
            if (string.IsNullOrEmpty(path))
                throw new NullReferenceException("parameter file cant be null or empty!");

            bool isPathDirectory;

            var combinedPath = Path.Combine(Environment.CurrentDirectory, path);

            if (!PathIsValid(combinedPath, out isPathDirectory))
            {
                if (!isPathDirectory)
                    throw new Exception("File not exepted, only, htm or html files are ok");

                throw new Exception("Directory contains no valid files");
            }

            using (var phantomJs = new PhantomJSDriver(Environment.CurrentDirectory))
                {
                    phantomJs.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 0, 10));

                    if (isPathDirectory)
                    {
                        var qUnitTests = new List<NPQTest>();

                        foreach (var file in Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, path), "*.htm").Select(file => file.Replace(Environment.CurrentDirectory + "\\", "")).ToList())
                        {
                            var tests = phantomJs.GetTests(file);
                            qUnitTests.AddRange(tests);
                        }

                        foreach (var qUnitTest in qUnitTests)
                        {
                            yield return MapTestCaseData(qUnitTest);
                        }

                    }
                    else
                    {
                        foreach (var qTest in phantomJs.GetTests(path))
                        {
                            yield return MapTestCaseData(qTest);
                        }
                    }
                }
        }