0
votes

When running my test I receive the error:

browser.setlocation is not a function. 

The protractor website lists browser.setLocation() as a function, why does it not recognize my use of it?

I have tried multiple variations of accessing a url i.e. window.location... but to no avail.

it('login', function() {

    browser.setLocation('http://localhost') 
        .waitForElementVisible('wrap')
        .setValue("#username", "username1") 
        .setValue("#password", "Password2"); 

    element(by.id('loginBtn')).click();
    browser.waitForAngular();

});

Test should go to login page, enter username and password and click login

2
Have you tried window.location.href? If that doesn't work try waiting for angular first, as would be suggested by stackoverflow.com/a/36441352/10965456. - ecc521
@ecc521 yes, that does not work - D0uble0
have you tried 'browser.driver.get()' ? - Bill P

2 Answers

0
votes

You can use

browser.get('website link');
element(by.css('locator for username')).sendkeys('test');
element(by.css('locator for password')).sendkeys('test');
element(by.id('locator for login button')).click();

This is the simple way to access url and log in to application.

0
votes

Firstly the browser.setLocation('http://localhost').waitForElementVisible('wrap')... is not valid syntax.

The browser.setLocation method uses for browse to another page using in-page navigation.

browser.get('http://angular.github.io/protractor/#/tutorial');
browser.setLocation('api'); // Current url is 'http://angular.github.io/protractor/#/api'

Also, I don't know what do the waitForElementVisible and setValue methods do, but you have to call then to chain methods in protractor.

If you want to navigate/open the page use the browser.get(url) method.

Worked solution:

it('login', async () => {
  await browser.get('http://localhost') 
  await browser.wait(ExpectedConditions.visibilityOf($('wrap')), 5000);
  await element(by.id("username")).sendKeys("username1");
  await element(by.id("password")).sendKeys("Password2");
  await element(by.id('loginBtn')).click();
  await browser.waitForAngular();
});