Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor: open window and test url

I'm trying to test a link in a table that opens a new window. I want to test the url of the new window.

What I have so far is this:

    it('Should verify new window url', function () {
    page.list.get(0).click().then(function () {
        browser.getAllWindowHandles().then(function (handles) {
            newWindowHandle = handles[1];
            browser.switchTo().window(newWindowHandle).then(function () {
                expect(browser.getCurrentUrl()).toMatch(/\/url/);
            });
        });
    });
});

Error: Error while waiting for Protractor to sync with the page: {}

Works if I remove the expect....I am confused about promises, can someone guide me in right direction please?

like image 765
Thibs Avatar asked Apr 15 '14 19:04

Thibs


People also ask

How do I navigate to URL in Protractor?

Purpose: The to() method is used to navigate to a new URL. Parameter: This command accepts one parameter i.e URL to be navigated. Basically, this URL is a string. Returns: This command returns a promise that will be resolved as URL as loaded.

How do you open a new window with a Protractor?

Get the GU ID of the current (parent) window using getWindowHandle() method present in the protractor and store the value in a String. 3. Click on the Open 3 New Window button, application open new window with google page.

Is Protractor deprecated?

As Protractor approaches the end of its life, find out what this means for you and your testing team, and how we can help! As the development team of Protractor ceases to maintain the open-source automated testing tool, we see the end of an era of sorts.

Is Protractor a test runner?

Protractor is an open-source automation testing framework that is written using NodeJS. It offers combined end to end testing for web applications that are built using AngularJS. It supports both Angular and Non-Angular applications.


1 Answers

Turns out that the new page does not have angular on it, therefore I had to use the underlying driver.

expect(browser.driver.getCurrentUrl()).toMatch(/\/url/);
like image 110
Thibs Avatar answered Sep 19 '22 21:09

Thibs