1

I faced with strange problem after my tests refactor. I deprecated everywhere beforeEach/afterEach blocks in order to significantly decrease execution time and now I have problems to run even simple specs one after another. I have create simple config and specs.

Config:

 exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
    specs: [
        'googleSpec.js',
        'forgotPasswordPageTestSuite.js'
        ],
    capabilities:
    {
        browserName: 'chrome'
        //shardTestFiles: true,
        //maxInstances: 2
    },
    jasmineNodeOpts: {
        defaultTimeoutInterval: 360000
    }
}

Spec 1:

describe("Google Spec", function()
{

    browser.ignoreSynchronization = true;
    browser.get('http://google.com');

    browser.wait(function () {
        return element(by.name('q')).isDisplayed();
    }, 15000);

    it('Verify search inout is presented', function()
    {
        expect(browser.isElementPresent(element(by.name('q'))).toBe(true);
    });
});

Spec 2:

describe("Yandex spec", function()
{
    browser.ignoreSynchronization = true;
    browser.get('http://www.yandex.ru');

    browser.wait(function () {
             return element(by.id('text')).isDisplayed();
        }, 15000);
    });

    it('Verify that search input is presented', function()
    {
        expect(browser.isElementPresent(by.id('text'))).toBe(true);
    });
});

If I execute them separately of using

shardTestFiles: true,
maxInstances: 2

it is just ok, but when I have above config I have such exception:

[launcher] Running 1 instances of WebDriver F.

Failures:

1) Google Spec Verify search inout is presented Message: Expected false to be true. Stacktrace: Error: Failed expectation at [object Object]. (/Users/sergeyteplyakov/WebstormProjects/e2eMPP20/googleSpec.js:13:54)

Finished in 6.339 seconds 2 tests, 2 assertions, 1 failure

[launcher] 0 instance(s) of WebDriver still running [launcher] chrome

1 failed 1 test(s) [launcher] overall: 1 failed spec(s) [launcher] Process exited with error code 1

Process finished with exit code 1

In my real tests I have the same issue, when my spec is similar to what I have provided. When I look what is really happening for some reason .get(url) method from 2nd spec started executing before 1st spec is getting finished. I guess I am missing something core and significant, could anyone point me please)

Sergey Teplyakov
  • 603
  • 8
  • 18

1 Answers1

3

I think that with this setup there is no guarantee that protractor would perform that wait() call and wait for the results before executing it().

If you want some code being executed before all of the it blocks in the spec, use beforeAll() (built-in in Jasmine 2, available as a third-party for Jasmine 1.x):

describe("Google Spec", function()
{
    beforeAll(function () {
        browser.ignoreSynchronization = true;
        browser.get('http://google.com');

        browser.wait(function () {
            return element(by.name('q')).isDisplayed();
        }, 15000);
    });

    it('Verify search inout is presented', function()
    {
        expect(browser.isElementPresent(element(by.name('q'))).toBe(true);
    });
});

Also note that you can use Expected Conditions to simplify that wait() block:

var EC = protractor.ExpectedConditions;
var elm = element(by.name('q'));

browser.wait(EC.visibilityOf(elm), 15000);
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • I tried to include beforeAll blocks, but they have not helped. Also when in my real test I just put in the 2nd suite all code before 1st 'it' block in beforeEach it start working, this is really weird – Sergey Teplyakov Apr 08 '15 at 19:12
  • @SergeyTeplyakov thanks, what if you move `browser.ignoreSynchronization = true;` to `onPrepare()`? – alecxe Apr 08 '15 at 19:20