how to have protractor take over browser in the middle of an application

扶醉桌前 提交于 2020-01-02 09:56:12

问题


I have written an angular project that utilizes require js, so most javascript will not be loaded prior to landing on a particular set of pages. (including angular.js)

when writing flows, I had to use browser.driver in place of ptor, and this worked well until angular components came rolling in. Now I am trying to find a way to squeeze the initialization of ptor into the browser.driver and roll in the angular after a particular flow. So I have something like this

        browser.driver.getCurrentUrl().then(function(url){
            ptor = protractor.getInstance();
            // ptor.ignoreSynchronization = true;
            ptor.get(url);
        })
        ptor.sleep(2000);

which seems to be getting ptor undefined after the statement even if i timeout. how should i do the swap here. and do a constructor of protractor with the url. without reloading.

--------------addon--------- ok so this is what i had

        searchInput = browser.driver.findElement(by.css('#searchstring')); 
        searchInput.sendKeys('logan airport');
        searchInput.sendKeys(protractor.Key.ENTER)//.perform();
        browser.driver.sleep(6000);

        browser.driver.wait(function(){ //angular loads here
            return browser.driver.getCurrentUrl(function(url){
                searchUrl = url;
                return /screwdriver/.test(url);
            });
        }, 10000)
        browser.driver.sleep(2000);
        /*UNEXECUTED CODE HERE: Error while waiting for angular to sync with your page*/
        firstItem =  element.all(by.css('.itemContainer')).get(1).click();
        browser.driver.sleep(10000);

and this is what i am doing right now...

            searchInput = ptor.findElement(protractor.By.css('#searchstring'));
            searchInput.sendKeys('logan airport');
            searchInput.sendKeys(protractor.Key.ENTER)//.perform();
            ptor.sleep(6000);

            ptor.wait(function(){ //this page loads angular, but stuck on white page, which with previous version this is fluent, it says angular cannot be found on the page
                return ptor.driver.getCurrentUrl().then(function(url){
                    searchUrl = url;
                    return /screwdriver/.test(url);
                });
            }, 10000)

            ptor.sleep(2000);

            /*NOT EXECUTED: Error while waiting for angular to sync with your page*/
            foundItems = ptor.findElement(protractor.By.css('.itemContainer')); 
            firstItem = foundItems.get(1).click();
            ptor.sleep(2000);

both doesn't seem to work, one is angular not sync, other is angular not found, but the actual page will have angular to be exist if u hit f12 and type in angular.


回答1:


You don't actually have to construct ptor using the new syntax (in the new syntax, ptor ~= browser). ptor.url means 'load this page', not 'make a protractor for this page'. You probably want something like:

browser.driver.get(yourUrl);
browser.driver.wait(function() {
   // Put in some test here that returns true when Angular is ready to go.
});
element(by.id('foo')); // Start using protractor here!


来源:https://stackoverflow.com/questions/20204264/how-to-have-protractor-take-over-browser-in-the-middle-of-an-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!