2

I have node.js installed and protractor installed. I have experience with selenium-webdriver but Protractor is driving me nuts!!! I am also not that familiar with javascript.

This is what my code looks like:

describe('My app', function() {

    var result = element(by.id('result-name'));
    var enterBtn = element(by.id('enter'));
    var clearFieldBtn = element(by.id('clear-field'); 

    it('should bring up components on load', function() {
        browser.get(`http://localhost:${process.env.PORT}`);
        browser.wait(until.titleContains('Sample App'), 500);
        browser.wait(until.presenceOf(browser.element(by.id('my-test-app'))), 500);

        expect(enterBtn).isPresent;
      });

    it('result should equal username', function () {
        browser.get(`http://localhost:${process.env.PORT}`);

        expect(clearFieldBtn).isPresent;
        expect(result.getText()).toEqual('John Smith'); //both tests pass without this line of code   

    });

});

The last line "expect(result.getText()).toEqual('John Smith');" throws me an error. I get:

expect(...).toEqual is not a function

Any help would be much appreciated. I have spent a couple of hours trying to find a solution and trying different things.

I also wanted to implement the isPresent function how it's done in the api docs which is like this: expect($('.item').isPresent()).toBeTruthy();

I tried to do:

expect(clearFieldBtn).isPresent().toBeTruthy();

But I get that isPresent is not a function...

2
  • Your title is misleading. The question/error isn't about getText(), its about your jasmine functions toEqual, toContain etc. Commented Apr 27, 2017 at 14:55
  • Also can you please post your config, what test library are you using? Commented Apr 27, 2017 at 14:57

2 Answers 2

3

The expect above that line seems poor. It should read

expect(clearFieldBtn.isPresent()).toBeTruthy();

not sure if that is causing the weird error on the line below...just thought I would throw it out there. All your protractor APIs need be be called within the expect because isPresent is not a attribute of expect

Sign up to request clarification or add additional context in comments.

14 Comments

also noticed that your element for clearFieldBtn is missing a parenthesis
if you just run expect(true).toBeTruthy() in its own it-block, what do you get
Yea, sounds like you don't even has Jasmine installed if you can't access those functions
Protractor is just a test framework, you need a test library to go along with it. getText and the Protractor functions are fine, but you need a library (jasmine) to use toEqual, toContain etc. Protractor is supposed to use Jasmine by default, but you should declare one in your config to be sure, i.e. framework: 'jasmine'
Actually, I guess describe and it also come from jasmine, so maybe that's not the issue since those aren't throwing errors.... this is a weird issue.
|
2

Have you tried these lines:

    clearFieldBtn.isPresent().then(function(bln) {
         expect(bln).toBe(true);
    });

    result.getText().then(function(tmpText) {
         expect(tmpText).toBe('John Smith');
    });

If you still get an error on result.getText(), please check the presence of the result object.

Comments

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.