2017-02-22 18:13:21 +00:00
|
|
|
import { browser, element, by } from 'protractor';
|
|
|
|
|
2020-07-30 13:03:13 +03:00
|
|
|
describe('Forms Tests', () => {
|
2017-02-22 18:13:21 +00:00
|
|
|
|
2020-11-23 20:17:10 +02:00
|
|
|
beforeEach(() => browser.get(''));
|
2017-02-22 18:13:21 +00:00
|
|
|
|
2020-11-23 20:17:10 +02:00
|
|
|
it('should display correct title', async () => {
|
|
|
|
expect(await element.all(by.css('h1')).get(0).getText()).toEqual('Hero Form');
|
2017-02-22 18:13:21 +00:00
|
|
|
});
|
|
|
|
|
2020-11-23 20:17:10 +02:00
|
|
|
it('should not display message before submit', async () => {
|
2020-07-30 13:03:19 +03:00
|
|
|
const ele = element(by.css('h2'));
|
2020-11-23 20:17:10 +02:00
|
|
|
expect(await ele.isDisplayed()).toBe(false);
|
2017-02-22 18:13:21 +00:00
|
|
|
});
|
|
|
|
|
2020-11-23 20:17:10 +02:00
|
|
|
it('should hide form after submit', async () => {
|
2020-07-30 13:03:19 +03:00
|
|
|
const ele = element.all(by.css('h1')).get(0);
|
2020-11-23 20:17:10 +02:00
|
|
|
expect(await ele.isDisplayed()).toBe(true);
|
|
|
|
|
2020-07-30 13:03:19 +03:00
|
|
|
const b = element.all(by.css('button[type=submit]')).get(0);
|
2020-11-23 20:17:10 +02:00
|
|
|
await b.click();
|
|
|
|
expect(await ele.isDisplayed()).toBe(false);
|
2017-02-22 18:13:21 +00:00
|
|
|
});
|
|
|
|
|
2020-11-23 20:17:10 +02:00
|
|
|
it('should display message after submit', async () => {
|
2020-07-30 13:03:19 +03:00
|
|
|
const b = element.all(by.css('button[type=submit]')).get(0);
|
2020-11-23 20:17:10 +02:00
|
|
|
await b.click();
|
|
|
|
expect(await element(by.css('h2')).getText()).toContain('You submitted the following');
|
2017-02-22 18:13:21 +00:00
|
|
|
});
|
|
|
|
|
2020-11-23 20:17:10 +02:00
|
|
|
it('should hide form after submit', async () => {
|
2020-07-30 13:03:19 +03:00
|
|
|
const alterEgoEle = element.all(by.css('input[name=alterEgo]')).get(0);
|
2020-11-23 20:17:10 +02:00
|
|
|
expect(await alterEgoEle.isDisplayed()).toBe(true);
|
|
|
|
|
2020-07-30 13:03:19 +03:00
|
|
|
const submitButtonEle = element.all(by.css('button[type=submit]')).get(0);
|
2020-11-23 20:17:10 +02:00
|
|
|
await submitButtonEle.click();
|
|
|
|
expect(await alterEgoEle.isDisplayed()).toBe(false);
|
2017-02-22 18:13:21 +00:00
|
|
|
});
|
|
|
|
|
2020-11-23 20:17:10 +02:00
|
|
|
it('should reflect submitted data after submit', async () => {
|
2020-07-30 13:03:19 +03:00
|
|
|
const alterEgoEle = element.all(by.css('input[name=alterEgo]')).get(0);
|
2020-11-23 20:17:10 +02:00
|
|
|
const value = await alterEgoEle.getAttribute('value');
|
|
|
|
const test = 'testing 1 2 3';
|
|
|
|
const newValue = value + test;
|
|
|
|
|
|
|
|
await alterEgoEle.sendKeys(test);
|
|
|
|
expect(await alterEgoEle.getAttribute('value')).toEqual(newValue);
|
|
|
|
|
|
|
|
const b = element.all(by.css('button[type=submit]')).get(0);
|
|
|
|
await b.click();
|
|
|
|
|
|
|
|
const alterEgoTextEle = element(by.cssContainingText('div', 'Alter Ego'));
|
|
|
|
expect(await alterEgoTextEle.isPresent()).toBe(true, 'cannot locate "Alter Ego" label');
|
|
|
|
const divEle = element(by.cssContainingText('div', newValue));
|
|
|
|
expect(await divEle.isPresent()).toBe(true, `cannot locate div with this text: ${newValue}`);
|
2017-02-22 18:13:21 +00:00
|
|
|
});
|
|
|
|
});
|