如何让量角器在应用程序中间接管浏览器 [英] how to have protractor take over browser in the middle of an application

查看:48
本文介绍了如何让量角器在应用程序中间接管浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个使用 require js 的 angular 项目,因此大多数 javascript 不会在登陆特定页面集之前加载.(包括 angular.js)

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)

在编写流程时,我不得不使用 browser.driver 代替 ptor,这一直运行良好,直到 angular 组件出现.现在我试图找到一种方法将 ptor 的初始化压缩到 browser.driver 和在特定流动后以角度滚动.所以我有这样的事情

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);

即使我超时,它似乎在语句之后也未定义 ptor.我应该如何在这里进行交换.并用 url 做一个量角器的构造函数.无需重新加载.

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);

两者似乎都不起作用,一个是 angular 不同步,另一个是 angular 未找到,但如果您按 f12 并输入 angular,实际页面将有 angular 存在.

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.

推荐答案

您实际上不必使用新语法构造 ptor(在新语法中, ptor ~= browser).ptor.url 表示加载此页面",而不是为此页面制作量角器".你可能想要这样的东西:

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!

这篇关于如何让量角器在应用程序中间接管浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆