D0uble0
D0uble0

Reputation: 175

Protractor does not recognize function

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

Upvotes: 0

Views: 206

Answers (2)

Yevhen Laichenkov
Yevhen Laichenkov

Reputation: 8662

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

Upvotes: 0

Zohair
Zohair

Reputation: 268

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.

Upvotes: 0

Related Questions