1

I'm trying to use variables from a file in a test script, however I'm experiencing an issue Failed: web.proceedButton.isPresent is not a function.

My code looks like this:

describe('Navigator homepage', function() {
    it('should proceed to login', function() {
        var web = require('../example/webObjectVariables.json');
        web.proceedButton.isPresent();
        web.proceedButton.click();
        web.loginField.sendKeys("login");
        web.passwordField.sendKeys("password");
        web.logInButton.click();

        browser.driver.sleep(1000);

Json file looks like this:

{
   "proceedButton":"auth-login-page-button",
   "loginField":"login_username",
   "passwordField":"login_password",
   "logInButton":"auth-login-page-button"
}

What am I doing wrong here? Thanks in advance.

4
  • 1
    can paste the json here? Commented Oct 23, 2017 at 11:50
  • Added json file contents. Commented Oct 23, 2017 at 11:59
  • are the locator values in css ? Commented Oct 23, 2017 at 12:53
  • Those are IDs and not CSS. Commented Oct 23, 2017 at 13:11

1 Answer 1

3

web.proceedButton is a "auth-login-page-button" string which does not have isPresent() or click() or other methods that protractor's ElementFinder has.

I think you forgot to actually locate the element using this locator, assuming auth-login-page-button is an id:

var loginPageButton = element(by.id(web.proceedButton));
loginPageButton.click();

Note that a line like loginPageButton.isPresent() would not do anything by itself, did you mean to wait for the presence of the button?

var EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(loginPageButton), 5000);

loginPageButton.click();
Sign up to request clarification or add additional context in comments.

3 Comments

I was doing this before within one file. Assigning value to a variable like: const proceedButton = element(by.id('auth-login-page-button')); and then using it as proceedButton.click(). Then I wanted to remove them from the script and store them in a file with the rest web objects to make them global. Didn't know I have to assign that value to another variable in test to make it accessible. Is it the only way to do that?
@Qucu generally speaking, a common way to organize tests in a modular way - separating test logic and element locators would be to use Page Objects.
This way seems messy if there is a lot of steps in a test suite and if another test uses a particular object, it needs to be assigned again instead of accessing it from a file. Anyway thank you for clearing things up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.