add test for the creation of file

This commit is contained in:
nabim777 2023-10-18 19:30:14 +05:45
parent a02f9899ca
commit 3a6dc8ff51
No known key found for this signature in database
GPG Key ID: BD68084BD2B283E7
7 changed files with 74 additions and 6 deletions

View File

@ -3,13 +3,13 @@
const { Before, BeforeAll, AfterAll, After, setDefaultTimeout } = require("@cucumber/cucumber"); const { Before, BeforeAll, AfterAll, After, setDefaultTimeout } = require("@cucumber/cucumber");
const { chromium } = require("playwright"); const { chromium } = require("playwright");
setDefaultTimeout(60000) setDefaultTimeout(30000)
// launch the browser // launch the browser
BeforeAll(async function () { BeforeAll(async function () {
global.browser = await chromium.launch({ global.browser = await chromium.launch({
headless: false, headless: false,
slowMo: 1000, slowMo: 500,
}); });
}); });

View File

@ -0,0 +1,12 @@
Feature: Create a file
As a user
I want to manage a file
So that I can save it
Background:
Given the user has browsed to the login page
And the user has logged in with username "admin" and password "admin"
Scenario: create a file
When user has added file "demo.txt" with content "hello world"
Then for user there should contain files "file.txt"

View File

@ -3,7 +3,7 @@ Feature: login
I want to login to the system I want to login to the system
So that I can manage the files and folders So that I can manage the files and folders
Scenario: login with valid username and valid password Scenario: login with valid username and valid password
Given the user has browsed to the login page Given the user has browsed to the login page
When user logs in with username "admin" and password "admin" When user logs in with username "admin" and password "admin"
Then user should redirect to the homepage Then user should redirect to the homepage

View File

@ -0,0 +1,29 @@
class CreateFilePage {
constructor() {
//url
this.url = 'http://localhost:8080'
this.loginUrl = 'http://localhost:8080/login'
this.fileUrl = this.url + '/files/'
//define selectors
this.uploadButtonSelector = '//button[@title="Upload"]/i';
this.newFileLabelSelector = '//button[@aria-label="New file"]';
this.writeNewFileInputSelector = '//input[@class="input input--block"]';
this.createButtonSelector = '//button[contains(text(),"Create")]';
this.contentBoxSelector = '//textarea[@class="ace_text-input"]';
this.saveIconSelector = '//i[contains(text(),"save")]';
this.closeIconSelector = '//i[contains(text(),"close")]';
}
async createNewFile(filename,content) {
await page.click(this.newFileLabelSelector);
await page.fill(this.writeNewFileInputSelector, filename);
await page.click(this.createButtonSelector);
// await page.getByRole('textbox').fill(content);
await page.fill(this.contentBoxSelector,content);
await page.click(this.saveIconSelector);
await page.click(this.closeIconSelector);
}
}
module.exports = CreateFilePage

View File

@ -20,6 +20,10 @@ class LoginPage {
await page.fill(this.passwordSelector, password); await page.fill(this.passwordSelector, password);
await page.click(this.loginSelector); await page.click(this.loginSelector);
} }
// async assertLoginPageIsOpen() {
// await expect(this.page).toHaveURL(this.loginUrl);
// }
} }
module.exports = LoginPage module.exports = LoginPage

View File

@ -0,0 +1,18 @@
const {Given, When, Then} = require('@cucumber/cucumber')
// import expect for assertion
const { expect } = require("@playwright/test");
//import assert
const assert = require("assert")
//import page
const CreateFilePage = require("../pageObjects/CreateFilePage.js");
const createFilePage = new CreateFilePage;
When('user has added file {string} with content {string}', async function (filename,content) {
await createFilePage.createNewFile(filename,content)
});
Then('for user there should contain files {string}', async function (string) {
});

View File

@ -14,6 +14,11 @@ Given('the user has browsed to the login page', async function () {
await expect(page).toHaveURL(loginPage.loginUrl); await expect(page).toHaveURL(loginPage.loginUrl);
}); });
Given('the user has logged in with username {string} and password {string}', async function (username, password) {
await loginPage.login(username,password);
await expect(page).toHaveURL(loginPage.fileUrl);
});
When('user logs in with username {string} and password {string}', async function (username, password) { When('user logs in with username {string} and password {string}', async function (username, password) {
await loginPage.login(username,password); await loginPage.login(username,password);
}); });