Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const puppeteer = require('puppeteer');
- const expect = require('expect');
- (() => {
- describe('Test of Currency Page: ', () => {
- let browser;
- let page;
- let screenshots = {
- width: 1920,
- height: 1080
- };
- let currencyImage;
- let loginAddress;
- let username;
- let password;
- let loginButton;
- let currencyAddress;
- it('Puppeteer should be opened in the browser', async () => {
- try {
- browser = await puppeteer.launch({
- headless: false,
- ignoreHTTPSErrors: true
- });
- expect(browser).toExist();
- } catch (e) {
- console.log(e.message);
- }
- });
- it('New page should be created in the browser', async () => {
- try {
- page = await browser.newPage();
- expect(page).toExist();
- } catch (e) {
- console.log(e.message);
- }
- });
- it('Screenshots settings should be created', async () => {
- try {
- await page.setViewport(screenshots);
- expect(page).toExist();
- } catch (e) {
- console.log(e.message);
- }
- });
- it('Screenshots should be created', async () => {
- try {
- currencyImage = {
- path: './test/images/currency/currency1.png'
- };
- await page.screenshot(currencyImage);
- expect(page).toExist();
- } catch (e) {
- console.log(e.message);
- }
- });
- it('Login Page should be loaded', async () => {
- try {
- loginAddress = 'https://localhost:8150/login';
- await page.goto(loginAddress);
- expect(loginAddress).toBeA('string');
- } catch (e) {
- console.log(e.message);
- }
- });
- it('Screenshots should be created', async () => {
- try {
- currencyImage = {
- path: './test/images/currency/currency2.png'
- };
- await page.screenshot(currencyImage);
- expect(page).toExist();
- } catch (e) {
- console.log(e.message);
- }
- });
- it('Username should be string', async () => {
- try {
- username = 'kris';
- await page.type('#username', username);
- expect(username).toBeA('string');
- } catch (e) {
- console.log(e.message);
- }
- });
- it('Screenshots should be created', async () => {
- try {
- currencyImage = {
- path: './test/images/currency/currency3.png'
- };
- await page.screenshot(currencyImage);
- expect(page).toExist();
- } catch (e) {
- console.log(e.message);
- }
- });
- it('Password should be string', async () => {
- try {
- password = 'test';
- await page.type('#password', password);
- expect(password).toBeA('string');
- } catch (e) {
- console.log(e.message);
- }
- });
- it('Screenshots should be created', async () => {
- try {
- currencyImage = {
- path: './test/images/currency/currency4.png'
- };
- await page.screenshot(currencyImage);
- expect(page).toExist();
- } catch (e) {
- console.log(e.message);
- }
- });
- it('Login Button should be clicked', async () => {
- try {
- loginButton = '#loginButton';
- await page.click(loginButton);
- expect(loginButton).toBeA('string');
- } catch (e) {
- console.log(e.message);
- }
- });
- it('Screenshots should be created', async () => {
- try {
- currencyImage = {
- path: './test/images/currency/currency5.png'
- };
- await page.screenshot(currencyImage);
- expect(page).toExist();
- } catch (e) {
- console.log(e.message);
- }
- });
- it('Currency Page should be loaded', async () => {
- try {
- currencyAddress = 'https://localhost:8150/dashboard/currency';
- await page.goto(currencyAddress);
- expect(currencyAddress).toBeA('string');
- } catch (e) {
- console.log(e.message);
- }
- });
- it('Screenshots should be created', async () => {
- try {
- currencyImage = {
- path: './test/images/currency/currency6.png'
- };
- await page.screenshot(currencyImage);
- expect(page).toExist();
- } catch (e) {
- console.log(e.message);
- }
- });
- it('JSON Currency Page should be loaded', async () => {
- try {
- await page.goto(`${currencyAddress}/1`);
- let innerText = await page.evaluate(() => {
- return JSON.parse(document.querySelector("body").innerText);
- });
- // console.log(innerText);
- expect(innerText.success[0].id).toEqual(1).toBeA('number');
- } catch (e) {
- console.log(e.message);
- }
- });
- it('Screenshots should be created', async () => {
- try {
- currencyImage = {
- path: './test/images/currency/currency7.png'
- };
- await page.screenshot(currencyImage);
- expect(page).toExist();
- } catch (e) {
- console.log(e.message);
- }
- });
- it('Browser should be closed', async () => {
- try {
- page = await browser.close();
- expect(page).toNotExist();
- } catch (e) {
- console.log(e.message);
- }
- });
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement