2

我有一台 PC 和 Mac。我正在使用 PC 来托管 selenium 网格集线器,而 Mac 是 safari 节点。我正在运行 Visual Studio 2017 单元测试。只要我不尝试调整浏览器窗口的大小,测试就会通过。如果我这样做,则没有这样的窗口异常。driver.Manage().Window.Maximize();不会创建异常,但不会对浏览器窗口执行任何操作。

代码:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Safari;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;


namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {


        [TestMethod]
        public void TestMethod1()
        {
            var uri = "http://localhost:4444/wd/hub";
            var capabilities = new SafariOptions().ToCapabilities();
            var commandTimeout = TimeSpan.FromMinutes(5);
            var driver = new RemoteWebDriver(new Uri(uri), capabilities, commandTimeout);
            driver.Manage().Window.Size = new System.Drawing.Size(1080, 920);
            driver.Navigate().GoToUrl("http://google.com");
            IWebElement query = driver.FindElement(By.Name("q"));
            query.SendKeys("cheese");
            query.Submit();
            new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            Console.WriteLine("Page title is " + driver.Title);
            driver.Quit();
        }
    }
}

错误:

Test Name:  TestMethod1
Test FullName:  UnitTestProject1.UnitTest1.TestMethod1
Test Source:    d:\users\user\documents\visual studio 2017\Projects\UnitTestProject1\UnitTestProject1\UnitTest1.cs : line 18
Test Outcome:   Failed
Test Duration:  0:00:01.012796

Result StackTrace:  
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWindow.set_Size(Size value)
   at UnitTestProject1.UnitTest1.TestMethod1() in d:\users\user\documents\visual studio 2017\Projects\UnitTestProject1\UnitTestProject1\UnitTest1.cs:line 23
Result Message: 
Test method UnitTestProject1.UnitTest1.TestMethod1 threw exception: 
OpenQA.Selenium.NoSuchWindowException: A request to use a window could not be satisfied because the window could not be found. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 13 milliseconds
Build info: version: '3.3.1', revision: '5234b32', time: '2017-03-10 09:04:52 -0800'
System info: host: 'iMacTest.local', ip: 'fe80:0:0:0:1415:613c:3783:2326%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.4', java.version: '1.8.0_60'
Driver info: org.openqa.selenium.safari.SafariDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, databaseEnabled=true, handlesAlerts=true, version=12603.1.30.0.34, cleanSession=true, platform=MAC, nativeEvents=true, locationContextEnabled=false, webStorageEnabled=true, browserName=safari, javascriptEnabled=true, platformName=macOS, cssSelectorsEnabled=true}]
Session ID: 5C53B34F-6516-4B57-926D-9EADE6AD4D53
4

0 回答 0