Question

I'm following this tutorial http://engineering.wingify.com/posts/e2e-testing-with-webdriverjs-jasmine/

First part calls for creating testfile.js

var webdriver = require('selenium-webdriver');

var driver = new webdriver.Builder().
    withCapabilities(webdriver.Capabilities.chrome()).
    build();

driver.get('http://www.wingify.com');

I was able to get the browser to run when I run node testfile.js

I create the testfile.js

$ cat testfile.js

var webdriver = require('selenium-webdriver');

var driver = new webdriver.Builder().
    withCapabilities(webdriver.Capabilities.chrome()).
    build();

describe('basic test', function () {
    it('should be on correct page', function () {
        driver.get('http://www.wingify.com');
        driver.getTitle().then(function(title) {
            expect(title).toBe('Wingify');
        });
    });
});

I get to this part where you run jasmine-node

$ jasmine-node testfile.js 

Finished in 0 seconds
0 tests, 0 assertions, 0 failures, 0 skipped

The expected behavior is that it launches the browser but that is not what I am experiencing.

Was it helpful?

Solution 2

You need to increase the timeout value by calling:

jasmine.DEFAULT_TIMEOUT_INTERVAL = 9999999;

Take a look at this example gist (I used WebdriverIO here).

OTHER TIPS

Try jasmine-node --matchall testfile.js or jasmine-node testfile.spec.js, by default jasmine-node searches for files containing "spec" in file name.

I had the same thing. driver.getTitle() is asynchronous, therefore Jasmine completes before anything is returned. I tried several things using driver.wait() but could not get the async right.

In the end I used Jasmine waitsFor - this waits for a true result, or it has it's own custom timeout.

My example below is slightly more complicated, as I load Google, do a search then check the page title on the results.

With this example you don't need to set the global Jasmine timeout, which for me didn't work anyway.

describe('basic test', function () {

    it('should search for webdriver and land on results page', function () {
        var match = 'webdriver - Google Search',
            title = '';

        driver.get("http://www.google.com");
        driver.findElement(webdriver.By.name("q")).sendKeys("webdriver");
        driver.findElement(webdriver.By.name("btnG")).click();

        // wait for page title, we know we are there
        waitsFor(function () {
            driver.getTitle().then(function (_title) {
                title = _title;
            });
            return title === match;
        }, 'Test page title, so we know page is loaded', testTimeout);

        // test title is correct
        runs(function () {
            expect(title).toEqual(match);
        });
    });
});

The waitsFor polls until a true result is returned, at that point the following runs() executes. It seems little long winded for me especially as it doing a comparison twice, once for the waits and again for the jasmine assertion.

I did another example using mocha instead of jasmine, using assert library, did have this problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top