コード例 #1
0
        public static void AttachText(this NUnit.Framework.TestContext context, string fileName, string[] lines)
        {
            fileName = context.GetAttachmentPath(fileName, true);

            System.IO.File.WriteAllLines(fileName, lines.ToArray());

            NUnit.Framework.TestContext.AddTestAttachment(fileName);
        }
コード例 #2
0
ファイル: TestUtils.cs プロジェクト: promontis/glTF2Sharp
        public static string GetAttachmentPath(this NUnit.Framework.TestContext context, string fileName)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentNullException(nameof(fileName));
            }
            if (System.IO.Path.IsPathRooted(fileName))
            {
                throw new ArgumentException(nameof(fileName), "path must be a relative path");
            }

            return(System.IO.Path.Combine(context.TestDirectory, $"{context.Test.ID}.{fileName}"));
        }
コード例 #3
0
        public static void AttachUrlLink(this NUnit.Framework.TestContext context, string linkPath, string url)
        {
            var sb = new StringBuilder();

            sb.AppendLine("[InternetShortcut]");
            sb.AppendLine("URL=" + url);

            linkPath = System.IO.Path.ChangeExtension(linkPath, ".url");
            linkPath = context.GetAttachmentPath(linkPath, true);

            System.IO.File.WriteAllText(linkPath, sb.ToString());

            NUnit.Framework.TestContext.AddTestAttachment(linkPath);
        }
コード例 #4
0
        public static void AttachFileLink(this NUnit.Framework.TestContext context, string linkPath, string targetPath)
        {
            var sb = new StringBuilder();

            sb.AppendLine("[InternetShortcut]");
            sb.AppendLine("URL=file:///" + targetPath);
            sb.AppendLine("IconIndex=0");
            string icon = targetPath.Replace('\\', '/');

            sb.AppendLine("IconFile=" + icon);

            linkPath = System.IO.Path.ChangeExtension(linkPath, ".url");
            linkPath = context.GetAttachmentPath(linkPath, true);

            System.IO.File.WriteAllText(linkPath, sb.ToString());

            NUnit.Framework.TestContext.AddTestAttachment(linkPath);
        }
コード例 #5
0
        public static string GetAttachmentPath(this NUnit.Framework.TestContext context, string fileName, bool ensureDirectoryExists = false)
        {
            var path = System.IO.Path.Combine(context.TestDirectory, "TestResults", $"{context.Test.ID}");
            var dir  = path;

            if (!string.IsNullOrWhiteSpace(fileName))
            {
                if (System.IO.Path.IsPathRooted(fileName))
                {
                    throw new ArgumentException(nameof(fileName), "path must be a relative path");
                }
                path = System.IO.Path.Combine(path, fileName);

                dir = System.IO.Path.GetDirectoryName(path);
            }

            System.IO.Directory.CreateDirectory(dir);

            return(path);
        }
コード例 #6
0
 public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
 {
     TestContext.WriteLine(state.ToString());
 }
コード例 #7
0
 public static void AttachGltfValidatorLink(this NUnit.Framework.TestContext context)
 {
     context.AttachUrlLink("🌍 glTF Validator", "http://github.khronos.org/glTF-Validator/");
 }
コード例 #8
0
 public static void AttachShowDirLink(this NUnit.Framework.TestContext context)
 {
     context.AttachFileLink("📂 Show Directory", context.GetAttachmentPath(string.Empty));
 }
コード例 #9
0
        public static void Initialize(Browser browser, NUnit.Framework.TestContext testContext, bool headless = false)
        {
            //BrowserStack
            DesiredCapabilities capability = null;

            ChromeMobileEmulationDeviceSettings chromeMobileEmulationDeviceSettings = null;

            ChromeOptions chromeOptions = new ChromeOptions();

            chromeOptions.AddArgument("--test-type");
            chromeOptions.AddArgument("--disable-extensions");

            InternetExplorerOptions ieOptions = new InternetExplorerOptions();

            if (headless)
            {
                chromeOptions.AddArgument("--headless");
                chromeOptions.AddArgument("--hide-scrollbars");
                chromeOptions.AddArgument("--disable-gpu");
                //headless_option.AddArgument("--remote-debugging-port=9222");
                chromeOptions.BinaryLocation = string.Format(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe");
            }


            switch (browser)
            {
            case Browser.Chrome:
                chromeOptions.AddArgument("--test-type");
                chromeOptions.AddArgument("--disable-extensions");
                chromeOptions.AddArgument("start-maximized");
                driver = new ChromeDriver(chromeOptions);
                Maximise();

                break;

            case Browser.Chrome_1024x768:
                chromeMobileEmulationDeviceSettings                   = new ChromeMobileEmulationDeviceSettings();
                chromeMobileEmulationDeviceSettings.Width             = 1024;
                chromeMobileEmulationDeviceSettings.Height            = 768;
                chromeMobileEmulationDeviceSettings.EnableTouchEvents = false;
                chromeMobileEmulationDeviceSettings.UserAgent         = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36";
                chromeOptions.EnableMobileEmulation(chromeMobileEmulationDeviceSettings);
                driver = new ChromeDriver(chromeOptions);
                Resize(1024, 768);
                break;

            case Browser.Chrome_1366x768:
                chromeMobileEmulationDeviceSettings                   = new ChromeMobileEmulationDeviceSettings();
                chromeMobileEmulationDeviceSettings.Width             = 1366;
                chromeMobileEmulationDeviceSettings.Height            = 768;
                chromeMobileEmulationDeviceSettings.EnableTouchEvents = false;
                chromeMobileEmulationDeviceSettings.UserAgent         = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36";
                chromeOptions.EnableMobileEmulation(chromeMobileEmulationDeviceSettings);
                driver = new ChromeDriver(chromeOptions);
                Resize(1366, 768);
                break;

            case Browser.Chrome_Mobile:
                chromeOptions.EnableMobileEmulation("iPhone 6");
                chromeOptions.AddArgument("--test-type");
                chromeOptions.AddArgument("--disable-extensions");
                driver = new ChromeDriver(chromeOptions);
                Resize(414, 736);
                break;

            case Browser.Chrome_Ipad:
                chromeMobileEmulationDeviceSettings           = new ChromeMobileEmulationDeviceSettings();
                chromeMobileEmulationDeviceSettings.Width     = 768;
                chromeMobileEmulationDeviceSettings.Height    = 1024;
                chromeMobileEmulationDeviceSettings.UserAgent = "Mozilla/5.0 (iPad; CPU OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1";
                chromeOptions.EnableMobileEmulation(chromeMobileEmulationDeviceSettings);
                driver = new ChromeDriver(chromeOptions);
                Resize(768, 1024);
                break;

            case Browser.Chrome_Landscape_Ipad:
                chromeMobileEmulationDeviceSettings           = new ChromeMobileEmulationDeviceSettings();
                chromeMobileEmulationDeviceSettings.Width     = 1024;
                chromeMobileEmulationDeviceSettings.Height    = 768;
                chromeMobileEmulationDeviceSettings.UserAgent = "Mozilla/5.0 (iPad; CPU OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1";
                chromeOptions.EnableMobileEmulation(chromeMobileEmulationDeviceSettings);
                driver = new ChromeDriver(chromeOptions);
                Resize(1024, 768);
                break;

            case Browser.PhantomJS:
                PhantomJSOptions       optionsPJS = new PhantomJSOptions();
                PhantomJSDriverService service    = PhantomJSDriverService.CreateDefaultService(rootLocation);
                service.IgnoreSslErrors = true;
                service.AddArgument("logfile.txt 2>&1");
                //optionsPJS.AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25");
                DesiredCapabilities phantomCapabilites = DesiredCapabilities.PhantomJS();
                optionsPJS.AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:16.0) Gecko/20121026 Firefox/16.0");
                //service.CookiesFile = "cookies.txt";
                service.LocalStoragePath = rootLocation;
                driver = new PhantomJSDriver(service, optionsPJS, TimeSpan.FromMinutes(3.0));

                break;

            case Browser.Firefox:
                driver = new FirefoxDriver();
                break;

            case Browser.IE:
                var optionsIE = new InternetExplorerOptions {
                    EnableNativeEvents = false
                };
                driver = new InternetExplorerDriver(rootLocation, optionsIE);
                break;

            case Browser.Edge:
                var optionsEdge = new EdgeOptions();
                optionsEdge.PageLoadStrategy = EdgePageLoadStrategy.Eager;
                driver = new EdgeDriver(rootLocation, optionsEdge);
                break;

            case Browser.BSIE9:
                capability = (DesiredCapabilities)ieOptions.ToCapabilities();
                SetCapabilities(capability);
                capability.SetCapability("version", 9.0);
                capability.SetCapability("browser", "IE");
                capability.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Vista));
                driver = new WebdriverExtensions.ScreenShotRemoteWebDriver(new Uri("http://hub.browserstack.com/wd/hub/"), capability);
                break;

            case Browser.BSIE10:
                capability = (DesiredCapabilities)ieOptions.ToCapabilities();
                SetCapabilities(capability);
                SetCapabilities(capability);
                capability.SetCapability("browser", "IE");
                capability.SetCapability("version", 10.0);
                driver = new WebdriverExtensions.ScreenShotRemoteWebDriver(new Uri("http://hub.browserstack.com/wd/hub/"), capability);
                break;

            case Browser.BSIE11:
                capability = (DesiredCapabilities)ieOptions.ToCapabilities();
                SetCapabilities(capability);
                capability.SetCapability("browser", "IE");
                capability.SetCapability("version", 11.0);
                capability.SetCapability(CapabilityType.Platform, "Win8");
                driver = new WebdriverExtensions.ScreenShotRemoteWebDriver(new Uri("http://hub.browserstack.com/wd/hub/"), capability);
                break;
            }

            explicitlyWait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
        }