Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Descargando archivos #23

Merged
merged 4 commits into from Aug 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added resources/fondo-de-escritorio.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions src/page/IFrame.page.ts
Expand Up @@ -15,4 +15,16 @@ export class IFramePage {
return await this.getiFrame1.getAttribute('height');
}

public get getTitlePage(): ElementFinder {
return element(by.id('content')).element(by.tagName('h1'));
}

public async switchToFrame1() {
await browser.switchTo().frame(this.getiFrame1.getWebElement());
}

public async switchToInitialContext() {
await browser.switchTo().defaultContent();
}

}
37 changes: 36 additions & 1 deletion src/page/PersonalInformation.page.ts
@@ -1,4 +1,7 @@
import { ElementFinder, element, by } from 'protractor';
import { DownloadService } from '../service/Download.service';

const downloadService: DownloadService = new DownloadService();

export class PersonalInformationPage {

Expand Down Expand Up @@ -42,6 +45,35 @@ export class PersonalInformationPage {
return element(by.cssContainingText('button', 'Button'));
}

public get inputChooseFile(): ElementFinder {
return element(by.id('photo'));
}

private async submitFile(filePath: string) {
const path = require('path');
const absolutePath = path.resolve(__dirname, filePath);
await this.inputChooseFile.sendKeys(absolutePath);
}

public async clickButton() {
await this.button.click();
}

private get downloadLink(): ElementFinder {
return element(by.linkText('Test File to Download'));
}

private async download(fileName: string) {

const link = await this.downloadLink.getAttribute('href');
return await downloadService.downloadFile(link, fileName);

}

public checkDownload(fileName: string) {
return downloadService.readFileFromTemp(fileName);
}

public async fillForm(formData: any): Promise<void> {
await this.inputForFirstName.sendKeys(formData.firstName);
await this.inputForLastName.sendKeys(formData.lastName);
Expand All @@ -65,6 +97,9 @@ export class PersonalInformationPage {
await this.getCommand(command).click();
}

await this.button.click();
if (formData.file) {
await this.submitFile(formData.file); }

await this.download(formData.downloadFileName);
}
}
19 changes: 19 additions & 0 deletions src/service/Download.service.ts
@@ -0,0 +1,19 @@
import { readFileSync, existsSync, mkdirSync, writeFileSync } from 'fs';
import { resolve } from 'path';
import * as fetch from 'node-fetch';

export class DownloadService {
path = `${__dirname}/../../../temp`;
public async downloadFile(link: string, filename): Promise<void> {

if (!existsSync(this.path)) {
mkdirSync(this.path);
}
const file = fetch(link).then((response: any) => response.buffer());
writeFileSync(resolve(this.path, filename), file);
}

public readFileFromTemp(filename: string): Buffer {
return readFileSync(resolve(this.path, filename));
}
}
1 change: 1 addition & 0 deletions temp/fileDownloaded.xlsx
@@ -0,0 +1 @@
[object Promise]
22 changes: 21 additions & 1 deletion test/IFrame.spec.ts
Expand Up @@ -13,7 +13,27 @@ describe('Buy a t-shirt', () => {
});
it('La altura debió ser modificada', async () => {
await expect(iFramePage.getHeight()).toBe("600");
})
});
it('Verifica el título principal', async () => {
await expect(iFramePage.getTitlePage.getText()).toBe('Sample Iframe page');
});

describe('Cambiar de iFrame', () => {
beforeAll(async () => {
await iFramePage.switchToFrame1();
});
it('Verificado el título principal del iFrame', async () => {
await expect(iFramePage.getTitlePage.getText()).toBe('Practice Automation Form');
});
describe('Volver al contexto principal', () => {
beforeAll(async () => {
await iFramePage.switchToInitialContext();
});
it('Verificado el título del contexto principal al volver', async () => {
await expect(iFramePage.getTitlePage.getText()).toBe('Sample Iframe page');
});
});
});
});
});
});
32 changes: 28 additions & 4 deletions test/Locators.spec.ts
@@ -1,13 +1,20 @@
import { browser, protractor } from 'protractor';
import { PersonalInformationPage } from '../src/page';
import { DownloadService } from '../src/service/Download.service';

describe(' Llenar Formulario', () => {
const fileName = 'fileDownloaded.xlsx';

describe('Abrir página en el navegador', () => {

beforeAll(async () => {
await browser.get('http://toolsqa.com/automation-practice-form/');
});

const personalInformationPage: PersonalInformationPage = new PersonalInformationPage();
const downloadService: DownloadService = new DownloadService();
describe('Ingresar datos', () => {

beforeAll(async () => {
const expectedCondition = protractor.ExpectedConditions;
const condition = expectedCondition
Expand All @@ -26,12 +33,29 @@ describe(' Llenar Formulario', () => {
'Navigation Commands',
'Switch Commands',
'Wait Commands',
'WebElement Commands']
'WebElement Commands'],
file: '../../../resources/fondo-de-escritorio.jpg',
downloadFiles: true,
downloadFileName: fileName
});
});
it('el formulario debió ser completado', async () => {
await expect(personalInformationPage.getFormHeader.getText())
.toBe('Practice Automation Form');
it('la imágen debe estar cargada', async () => {
await expect(personalInformationPage.inputChooseFile.getAttribute('value')).toBe('C:\\fakepath\\fondo-de-escritorio.jpg');
});

it('Se debió descargar el archivo', async () => {
await expect(downloadService.readFileFromTemp(fileName).byteLength).toBeGreaterThan(0);
});

describe(' seleccionar botón Button luego de llenar datos', () => {

beforeAll(async () => {
await personalInformationPage.clickButton();
});
it('el formulario debió ser completado', async () => {
await expect(personalInformationPage.getFormHeader.getText())
.toBe('Practice Automation Form');
});
});
});
});
Expand Down