怎么说量角器等到页面加载?

时间:2022-08-24 17:06:04

My application taking some to page the login page.So protractor trying to enter the user name before page loads.So i need to say protractor to wait till the login page loads.

我的应用程序需要一些页面登录页面。所以量角器试图在页面加载之前输入用户名。所以我需要说量角器等到登录页面加载。

Could you please help me what command I need to use for this and where I need to use?(Please modify my code to add the wait command)

你能帮我解决一下我需要使用哪个命令以及我需要使用的命令吗?(请修改我的代码以添加wait命令)

PFB for my onPrepare and beforeeach function

PFB用于我的onPrepare和之前的功能

onPrepare: function() {  
browser.driver.manage().window().maximize();
jasmine.getEnv().addReporter(new HtmlReporter({

})
}

beforeEach(function() {
       browser.get('https://accounts.google.com/');
       //browser.manage().timeouts().pageLoadTimeout(30000);
       //browser.manage().timeouts().implicitlyWait(5000);
        //browser.sleep( 10000 );
        //browser.waitForAngular();
  });

I used those commented functions,but it didn't work for me.

我使用了这些注释函数,但它对我不起作用。

Please guide me.thanks in advance.

请提前指导我。谢谢。

2 个解决方案

#1


3  

Use the wait command: browser.driver.wait(condition, timeout);

使用wait命令:browser.driver.wait(condition,timeout);

onPrepare: function() {  
    browser.driver.manage().window().maximize();
    jasmine.getEnv().addReporter(new HtmlReporter({
    });
}

beforeEach(function() {
       browser.driver.get('https://accounts.google.com/');
       return browser.driver.wait(function() {
            return browser.driver.getCurrentUrl().then(function (url) {
                return url.indexOf('https://accounts.google.com/') > -1;
            });
        }, 5000);
        //whatever you want after
  });

you can wait for any condition like that. Also, google f.e is not an angular page, so you should use: browser.driver.get instead of protractors browser.get, or it will wait for angular on the page.

你可以等待任何这样的情况。此外,谷歌f.e不是一个角度页面,所以你应该使用:browser.driver.get而不是protractors browser.get,否则它将在页面上等待角度。

#2


2  

Assuming you want to click the Get Started button, wait for the button to become clickable:

假设您要单击“开始”按钮,请等待按钮变为可单击:

var EC = protractor.ExpectedConditions;

var getStarted = element(by.css('button[title="Get started"]'));
browser.wait(EC.elementToBeClickable(getStarted), 5000);
getStarted.click();

#1


3  

Use the wait command: browser.driver.wait(condition, timeout);

使用wait命令:browser.driver.wait(condition,timeout);

onPrepare: function() {  
    browser.driver.manage().window().maximize();
    jasmine.getEnv().addReporter(new HtmlReporter({
    });
}

beforeEach(function() {
       browser.driver.get('https://accounts.google.com/');
       return browser.driver.wait(function() {
            return browser.driver.getCurrentUrl().then(function (url) {
                return url.indexOf('https://accounts.google.com/') > -1;
            });
        }, 5000);
        //whatever you want after
  });

you can wait for any condition like that. Also, google f.e is not an angular page, so you should use: browser.driver.get instead of protractors browser.get, or it will wait for angular on the page.

你可以等待任何这样的情况。此外,谷歌f.e不是一个角度页面,所以你应该使用:browser.driver.get而不是protractors browser.get,否则它将在页面上等待角度。

#2


2  

Assuming you want to click the Get Started button, wait for the button to become clickable:

假设您要单击“开始”按钮,请等待按钮变为可单击:

var EC = protractor.ExpectedConditions;

var getStarted = element(by.css('button[title="Get started"]'));
browser.wait(EC.elementToBeClickable(getStarted), 5000);
getStarted.click();