Focus problems make tests fail

I am using osx 10.9.2, protractor 0.21.0, selenium-server-standalone 2.40.0 and chromedriver 2.9.

I am having problems that (I believe) are caused by the window focusing issue.

When I run my e2e test using a protractor, a browser window will be displayed, but my terminal will still be in the spotlight. This can be seen from the “Terminal”, which is still displayed in my menu bar, and not “Chrome” (osx behavior indicating which application is in focus).

I tried to correct the situation by doing this to no avail:

browser.driver.getAllWindowHandles().then(function(handles) {
  console.log(handles[0]);
  browser.driver.switchTo().window(handles[0]);
});

This situation causes some of my tests to fail. For example, tests involving clicking on a field using bootstrap datepicker will not show the calendar, and my test will not be able to interact with the datepicker calendar.

The situation is even worse on firefox. Firefox will not even show a drop-down menu when clicked if the browser is not in focus.

It's funny when I click the browser window manually after it is first shown, the tests will work fine.

When I tried a different approach: Running a test on a newly installed debian linux still does not work. The behavior is similar to that described above.

These are my configuration files: https://gist.github.com/giosakti/ca24a13705d15f4374b0

+4
source share
2 answers

! http://google-chrome.en.uptodown.com/mac/old, .. ( firefox).

" 34 " Google, , . : https://productforums.google.com/forum/#!topic/chrome/pN5pYf2kolc

, chrome 34. Google Updater Chrome 33.

-2

, IE Firefox , . / .

, :

// Needs an element to make sure we are on the correct popup
var waitForPopUpHandle = function(elm, errorMessage) {
    if (errorMessage == null) {
        errorMessage = 'Expected a new browser tab or window to pop up';
    };
    if (elm == null) {
        throw 'waitForPopUpHandle needs an element to wait for!';
    };

    browser.ignoreSynchronization = true; // not a protractor page
    // IE & Firefox don't ensure the windows handlers order, so we need iterate them.
    // First wait to have more that 1 browser tab
    browser.manage().timeouts().implicitlyWait(300); // a reasonable wait-retry time
    var i = 0;
    var popUpHandle = browser.driver.wait(function() {
        return browser.getAllWindowHandles().then(function(handles) {
            if (handles.length > 1) {
                return browser.switchTo().window(handles[i]).then(function() {
                    return browser.driver.isElementPresent(elm).then(function(result) {
                        if (result) {
                            return handles[i];
                        } else {
                            browser.sleep(400); // give it a break
                            i = i + 1;
                            if (i >= handles.length) {
                                i = 0;
                            };
                            return false;
                        };
                    });
                });
            } else {
                browser.sleep(400); // give it a break
                return false;
            };
        });
    }, browser.params.timeouts.pageLoadTimeout, errorMessage);
    // restore implicit wait
    browser.manage().timeouts().implicitlyWait(0); //restore

    return popUpHandle;
};

var popUpHandle = waitForPopUpHandle(by.css('div.some-element-unique-to-that-popup'));
browser.switchTo().window(popUpHandle).then(function() {
    browser.ignoreSynchronization = true; // not an angular page
    browser.driver.findElement(by.css('div.some-element-unique-to-that-popup')); // wait for the elm
    // your expect() go here ...
    // ...
    browser.close().then(function() {
        // This close() promise is necessary on IE and probably on Firefox too
        var mainTab = waitForMainWindow();
        expect(browser.switchTo().window(mainTab).then(function() {
            browser.ignoreSynchronization = false; // restore if main window is an angular page
            // Ensure we are back on the main window
            // ....
            return true;
        })).toBe(true);
    });
});

, , waitForMainWindow

var waitForMainWindow = function(errorMessage) {
    if (errorMessage == null) {
        errorMessage = 'Expected main browser window to be available';
    };

    browser.ignoreSynchronization = true; // not an angular page
    return browser.driver.wait(function() {
        return browser.getAllWindowHandles().then(function(handles) {
            if (handles.length > 1) {
                var hnd = handles[handles.length - 1];
                return browser.switchTo().window(hnd).then(function() {
                    return browser.close().then(function() {
                        browser.sleep(400); // wait for close
                        return false;
                    });
                });
            } else {
                return handles[0];
            };
        });
    }, 5000, errorMessage);
};
+3

Source: https://habr.com/ru/post/1536714/


All Articles