문제

In my first very simple test of Selenium with GhostDriver (PhantomJS) the tests pass, but PhantomJS.exe doesn't exit. I'm running on Windows 7, PhantomJS 1.9.0, Selenium WebDriver API 2.32.1 and NUnit 2.6.2.12296, .NET 3.5.

Here's my C#/Nunit/WebDriver code:

[TestFixture]
public class Driver
{
    IWebDriver driver;

    [SetUp]
    public void Setup()
    {
        driver = new PhantomJSDriver(@"D:\src\Tests\Drivers");
    }

    [TearDown]
    public void Teardown()
    {
        driver.Quit();
        driver.Dispose();
    }

    [Test]
    public void GoogleSearch()
    {
        //Navigate to the site
        driver.Navigate().GoToUrl("http://www.google.com");
        Assert.AreEqual("Google", driver.Title);
    }
}

And here's everything from PhantomJS:

PhantomJS is launching GhostDriver...
[INFO  - 2013-04-26T16:38:56.417Z] GhostDriver - Main - running on port 64183
[INFO  - 2013-04-26T16:38:56.630Z] Session [c9f2b8e0-ae8f-11e2-a7c1-159b6700bc86
] - CONSTRUCTOR - Desired Capabilities: {"browserName":"phantomjs","version":"",
"platform":"ANY"}
[INFO  - 2013-04-26T16:38:56.649Z] Session [c9f2b8e0-ae8f-11e2-a7c1-159b6700bc86
] - CONSTRUCTOR - Negotiated Capabilities: {"browserName":"phantomjs","version":
"1.9.0","driverName":"ghostdriver","driverVersion":"1.0.3","platform":"windows-7
-32bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"d
atabaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":f
alse,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnab
led":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":
{"proxyType":"direct"}}
[INFO  - 2013-04-26T16:38:56.701Z] SessionManagerReqHand - _postNewSessionComman
d - New Session Created: c9f2b8e0-ae8f-11e2-a7c1-159b6700bc86
[INFO  - 2013-04-26T16:38:59.470Z] ShutdownReqHand - _handle - About to shutdown

But it never does shutdown... Any ideas?

도움이 되었습니까?

해결책 2

I am not able to reproduce this, using the exact same environment. (Run the test through nunit.exe )

Windows 7, PhantomJS 1.9.0, Selenium WebDriver API 2.32.1 and NUnit 2.6.2.12296, .NET 3.5.

As Selenium and PhantomJS have both upgraded to newer versions. I'd suggest you to upgrade yours as well, and see if this issue appears again.

Selenium: selenium-dotnet-2.33.0.zip

PhantomJs: phantomjs-1.9.1-windows.zip

Also a side note, I don't think you need call both Quit() and Dispose(), as from the source code, this is how Quit() method is implemented.

/// <summary>
/// Close the Browser and Dispose of WebDriver
/// </summary>
public void Quit()
{
   this.Dispose();
}

다른 팁

[TestFixture]
public class Driver
{
    [Start]
    public void Start()
    {
       using (var driver = new PhantomJSDriver(@"D:\src\Tests\Drivers"))
       {
          driver.Url = "https://www.google.com";
          Assert.AreEqual("Google", driver.Title);
       }
    }
}

This will fix your problem, just always remember to encapsulate things in using statements when you can or explicitly Call driver.Dispose(); if it's a public variable, you can put Dispose in the deconstructor of the class or something a long those lines if you wanted, when the class is exited the deconstructor will be called and do your lines of code.

Using statements will take care of the cleanup for you.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top