This is my e2e test code:
import { browser, by, element } from 'protractor';
describe('LoginComponent', () => {
beforeEach(() => {
});
it('should show an error message when the email is incorrect', () => {
browser.get(browser.baseUrl + 'login');
const emailValue = 'test@gmail.com';
const email = element(by.id('email'));
email.sendKeys(emailValue);
expect(email.getAttribute('value')).toBe(emailValue);
});
});
Even though I set the value of the text input to be test@gmail.com the expect is unable to fetch and in the console I get error:
- Expected null to be 'test@gmail.com'.
What am I doing wrong?
I also tried this:
import { browser, by, element, Key } from 'protractor';
describe('LoginComponent', () => {
beforeEach(() => {
});
it('should show an error message when the email is incorrect', () => {
browser.get(browser.baseUrl + 'login');
const emailValue = 'test@gmail.com';
const email = element(by.id('email'));
email.sendKeys(emailValue);
browser.sleep(2000);
email.sendKeys(Key.TAB);
expect(email.getAttribute('value')).toBe(emailValue);
});
});
Html is pretty simple:
<input id="email"/>
Now if I change the html to <input id="email" value=""/>
then the error changes to
- Expected '' to be 'test@gmail.com'.