Test for projects page added

This commit is contained in:
piotrpekala7 2020-02-26 13:43:30 +01:00
parent fce7241bb2
commit 36a5596d33
9 changed files with 121 additions and 11 deletions

View File

@ -1,7 +1,22 @@
import { browser, by, element } from 'protractor';
import { ServersPage } from './server.po';
export class TestHelper {
sleep(value: number) {
browser.sleep(value);
}
waitForLoading() {
browser.waitForAngular();
}
async asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}
getCurrentUrl() {
return browser.getCurrentUrl();
}
}

View File

20
e2e/helpers/project.po.ts Normal file
View File

@ -0,0 +1,20 @@
import { TestHelper } from "./common.po"
import { browser, by } from "protractor";
export class ProjectsPage {
helper = new TestHelper();
async openAddProjectDialog() {
let addButton = await browser.driver.findElement(by.css('button.add-button'));
await addButton.click();
}
async createProject() {
let today = new Date();
let inputs = await browser.driver.findElements(by.css('input.mat-input-element'));
await inputs[1].sendKeys('test project ' + today.getUTCMilliseconds());
this.helper.sleep(2000);
let dialogButton = await browser.driver.findElement(by.css('button.add-project-button'));
await dialogButton.click();
}
}

View File

@ -1,6 +1,9 @@
import { browser, by, element } from 'protractor';
import { TestHelper } from './common.po';
export class ServersPage {
helper = new TestHelper;
maximizeWindow() {
browser.driver.manage().window().maximize();
}
@ -11,7 +14,6 @@ export class ServersPage {
getAddServerNotificationText() {
return browser.driver.findElement(by.className('mat-card-content')).getText();
// return element(by.className('mat-card-content')[0]).getText();
}
async clickAddServer() {
@ -22,4 +24,15 @@ export class ServersPage {
checkServersTable() {
return browser.driver.findElements(by.css('mat-cell'));
}
async navigateToServerProjects() {
this.helper.sleep(2000);
let hyperlinks = await browser.driver.findElements(by.css('a.table-link'));
let serverLink;
await this.helper.asyncForEach(hyperlinks, async element => {
let text = await element.getText();
if (text === '127.0.0.1') serverLink = element;
});
await serverLink.click();
}
}

View File

@ -0,0 +1,34 @@
import { ServersPage } from './helpers/server.po';
import { TestHelper } from './helpers/common.po';
import { element } from 'protractor';
import { ProjectsPage } from './helpers/project.po';
fdescribe('Project map page', () => {
let serversPage: ServersPage;
let projectsPage: ProjectsPage;
let helper: TestHelper;
beforeEach(async () => {
serversPage = new ServersPage();
projectsPage = new ProjectsPage();
helper = new TestHelper();
serversPage.maximizeWindow();
await serversPage.navigateToServersPage();
await serversPage.clickAddServer();
await serversPage.navigateToServerProjects();
await projectsPage.openAddProjectDialog();
helper.sleep(2000);
await projectsPage.createProject();
helper.sleep(2000);
});
it('user should have possibility to add nodes to map', async () => {
// arrange
//act
//assert
expect(true).toBe(true);
});
});

34
e2e/projects.e2e-spec.ts Normal file
View File

@ -0,0 +1,34 @@
import { ServersPage } from './helpers/server.po';
import { TestHelper } from './helpers/common.po';
import { element } from 'protractor';
import { ProjectsPage } from './helpers/project.po';
describe('Projects page', () => {
let serversPage: ServersPage;
let projectsPage: ProjectsPage;
let helper: TestHelper;
beforeEach(() => {
serversPage = new ServersPage();
projectsPage = new ProjectsPage();
helper = new TestHelper();
});
it('user should have possibility to create new project', async () => {
// arrange
serversPage.maximizeWindow();
await serversPage.navigateToServersPage();
await serversPage.clickAddServer();
await serversPage.navigateToServerProjects();
helper.sleep(2000);
//act
await projectsPage.openAddProjectDialog();
helper.sleep(2000);
await projectsPage.createProject();
helper.sleep(2000);
//assert
expect(helper.getCurrentUrl()).toMatch('server/1/project/');
});
});

View File

@ -2,7 +2,7 @@ import { ServersPage } from './helpers/server.po';
import { TestHelper } from './helpers/common.po';
import { element } from 'protractor';
fdescribe('gns3-web-ui App', () => {
describe('Servers page', () => {
let page: ServersPage;
let helper: TestHelper;
@ -11,12 +11,6 @@ fdescribe('gns3-web-ui App', () => {
helper = new TestHelper();
});
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
};
it('user should have possibility to add server', async () => {
// arrange
page.maximizeWindow();
@ -39,7 +33,7 @@ fdescribe('gns3-web-ui App', () => {
// act
let firstRowOfServersTable = await page.checkServersTable();
let serverData = [];
await asyncForEach(firstRowOfServersTable, async element => {
await helper.asyncForEach(firstRowOfServersTable, async element => {
serverData.push(await element.getText());
});

View File

@ -18,6 +18,6 @@
</mat-form-field>
<div mat-dialog-actions>
<button mat-button (click)="onNoClick()" color="accent">Cancel</button>
<button mat-button (click)="onAddClick()" tabindex="2" mat-raised-button color="primary">Add project</button>
<button mat-button (click)="onAddClick()" tabindex="2" class="add-project-button" mat-raised-button color="primary">Add project</button>
</div>
</form>

View File

@ -2,6 +2,6 @@
<div class="title"> Do you want to navigate to {{projectMessage}}?</div>
<div>
<button mat-button (click)="onNoClick()">No</button>
<button mat-button (click)="onYesClick()">Yes</button>
<button class="confirmButton" mat-button (click)="onYesClick()">Yes</button>
</div>
</div>