Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CFSelenium " Failed to start new browser session"

I’m having problems getting going with CFSelenium/TestBox. I’m developing on a Windows 7 VM, Coldfusion 10. I’ve downloaded a fresh copy of cfselenium from https://github.com/teamcfadvance/CFSelenium/archive/master.zip.

My file structure is

wwwroot |
  cfselenium |
    Selenium-RC |
        Selenium-server-standalone-2.46.0.jar
    Selenium.cfc
    Server.cfc
  Testbox |
    … various testbox files
   MySite |
    Tests|
        Specs |
            … my test files
            seleniumtest.cfc
        Application.cfc
        Index.cfm

MySite/Test/Application.cfc includes mappings for both testbox/ and cfselenium/.

The test suite, seleniumtest.cfc extends testbox.system.BaseSpec, and its beforeAll() and afterAll() functions instantiate selenium, start it, and tear it down:

component extends="testbox.system.BaseSpec" {

function beforeAll( ){
        // create Selenium class
        selenium = new cfselenium.Selenium();
        // Start it up.
        selenium.start( "mysite", "*chrome" );
    }

    // executes after all suites+specs in the run() method
    function afterAll(){
        selenium.stop();
        selenium.stopServer();
    }

function run( testResults, testBox ){
    describe('selenium', function(){
        // hello world equivalent
        describe('equality', function(){
            it('true should be true', function(){
                expect( true ).toBe(true);
            });
        });
    });
}
}

New behavior: when passing the following to selenium.start():

selenium.start( "https://www.google.com", "*googlechrome" );

I get the following error:

The Response of the Selenium RC is invalid: Failed to start new browser session: java.lang.RuntimeException: org.openqa.selenium.os.WindowsRegistryException: Problem while managing the registry, OS Version '6.1', regVersion1 = false Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03' System info: host: 'myhostname', ip: 'myvm_ip_address', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_67' Driver info: driver.version: unknown

For all other url or browser versions I pass to selenium.start() (I've tried '*chrome', '*firefox', '*iexplore', '*iexploreproxy'), I get the following error:

The Response of the Selenium RC is invalid: Failed to start new browser session: org.openqa.selenium.server.RemoteCommandException: Error while launching browser

From the stack trace, I can see that it fails at selenium.DoCommand().

From another SO post, it was suggested that if port 4444 was currently in use, it could interfere with the selenium-RC server. I restarted my VM and verified that port 4444 was not in use by running

Netstat –an | find “4444”

After again running the test suite, running netstat with the same command showed

TCP    0.0.0.0:4444           0.0.0.0:0              LISTENING
TCP    127.0.0.1:4444         127.0.0.1:49209        ESTABLISHED
TCP    127.0.0.1:49209        127.0.0.1:4444         ESTABLISHED
TCP    [::]:4444              [::]:0                 LISTENING
TCP    [::1]:4444             [::1]:49208            ESTABLISHED
TCP    [::1]:49208            [::1]:4444             ESTABLISHED

From looking at cf logs, I see the following:

Apr 29, 2016 09:44:23 AM Information [ajp-bio-8012-exec-3] - Starting HTTP request {URL='http://localhost:4444/selenium-server/driver/', method='POST'}

Is there supposed to be a selenium-server folder under wwwroot? Is that the webdriver?

EDIT: Per Dan's answer, I've downloaded chromedriver_win32 from http://chromedriver.storage.googleapis.com/index.html?path=2.21/, extracted to C:\Program Files (x86)\chromedriver, added that to my PATH, and rebooted the VM. After changing the driver from '*googlechrome' to '*chrome', it seems to work... I was able to run the following test successfully:

function testIncludes(){
      selenium.open("https://www.google.com");
      $assert.isEqual("Google", selenium.getTitle());
 }

So I think we're on our way here.

Seem to have IE driver working as well.

like image 684
earachefl Avatar asked Apr 26 '16 13:04

earachefl


People also ask

Can we use Selenium to work with an already open browser session?

We can connect to an already open browser using Selenium webdriver. This can be done using the Capabilities and ChromeOptions classes. The Capabilities class obtains the browser capabilities with the help of the getCapabilities method.

Does Selenium work when minimized?

Since modeling the user experience dictates certain design and technology choices for interacting with elements, it likely won't work if the browser is minimized, since a user cannot interact with the page while the browser window is minimized.

Can we minimize browser?

We can maximize and minimize the browser while we are testing an application in Selenium. For maximizing the browser, maximize() method is to be used. For minimizing the browser, minimize() method is to be used. Both these methods can be used simultaneously in the same program.


1 Answers

Selenium can't launch Chrome without Chrome Driver (as Chrome is no longer part of webkit) and Selenium can only launch webkit browsers by default. You should be able to launch Firefox (if it's installed) without needing any additional binaries.

To get Chrome working you will need to do the following:

  1. Download the chrome driver bin.
  2. Add it to your path.
  3. Selenium should be able to launch the browser.

There may be some other issues in the code, but I feel like the comments have provided enough feedback in that regard.

You can download the driver from: https://sites.google.com/a/chromium.org/chromedriver/downloads

UPDATED

IE requires a driver as well:

The Internet Explorer Driver Server This is required if you want to make use of the latest and greatest features of the WebDriver InternetExplorerDriver. Please make sure that this is available on your $PATH (or %PATH% on Windows) in order for the IE Driver to work as expected.

Download version 2.53.0 for (recommended) 32 Bit Windows IE or 64 bit Windows IE

The above was from: http://www.seleniumhq.org/download/ in regards to driving windows. It seems that the host with the browser needs to run a Selenium Web Driver specifically for IE

Firefox also publishes their own driver:

Firefox driver is included in the selenium-server-stanalone.jar available in the downloads. The driver comes in the form of an xpi (firefox extension) which is added to the firefox profile when you start a new instance of FirefoxDriver.

More details can be found here. It operates similar to the Chrome and IE drivers. The important thing to realize is that because the tests are run in the on one host and browsers are remote to where the tests are executed from you may want to look at Selenium Grid as well.

like image 67
Dan Sabin Avatar answered Oct 19 '22 12:10

Dan Sabin