jeudi 3 août 2017

Unable to find element using protractor/jasmine, possibly because sendKey error

I'm getting Failed: No element found using locator no matter how I program the locator (I've tried by css, by xpath, by ID.. nothing)

The webpage I'm using: http://ift.tt/2v1Upjq

I should be able to get an error message after entering an incorrect username and password. The error message is stored in the CSS selector .alert.alert-danger.text-center. The error displayed is 'Login Details Incorrect. Please try again.'

No matter how I format this, I get the same element not found issue, but also when invoking sendKeys, it seems to work. That is, if I take out the offending line of code for the error message, the rest of the program passes with no errors, and thus sendKeys should be working, but when running the program I don't observe anything actually being entered in the input boxes (Unless it's entering the sendKey information and clicking the button so fast I can't see it? But then why isn't the rest of the program lightning fast?). So I'm not sure if this is actually an element not found or a sendKey error. Also, I've looked through several answers on here and there are several Wait type libraries, but when I try to use that information in my program I just get more errors.

Here is my code:

// newSpec.js

browser.waitForAngularEnabled(false);

describe('Protractor Demo App', function() {
it('should have a title', function() {
browser.get('http://ift.tt/2hGWzhW');

expect(browser.getTitle()).toEqual('PHPTRAVELS | Demo');
});
});

describe('Login function', function() {
it('should be able to login', function() {
browser.findElement(by.linkText('Login')).click();
expect(element(by.xpath('//div[@class="login"]')).isPresent());

}); 
});



describe('Enter name', function() {
var inputEmail = element(by.css('#inputEmail'));
var inputPassword = element(by.css('#inputPassword'));  
var goButton = element(by.css('#login'));

it('should be able to enter user name', function() {
browser.get('http://ift.tt/2v24Qnj');

     inputEmail.sendKeys('Test Test');
     inputPassword.sendKeys('Password123');


     browser.sleep(500); 
 goButton.click();
     browser.sleep(500); 

 var errorMessage = element(by.id('#.alert.alert-danger.text-center'));
 expect(errorMessage.getText()).toEqual('   Login Details Incorrect. Please        try again. ');

 });
});

Aucun commentaire:

Enregistrer un commentaire