From 3a6dc8ff51c1082c736c74be446fb12ce5cc44cc Mon Sep 17 00:00:00 2001 From: nabim777 Date: Wed, 18 Oct 2023 19:30:14 +0545 Subject: [PATCH] add test for the creation of file --- frontend/cucumber.conf.js | 4 +-- .../acceptance/features/createFile.feature | 12 ++++++++ .../tests/acceptance/features/login.feature | 8 ++--- .../acceptance/pageObjects/CreateFilePage.js | 29 +++++++++++++++++++ .../tests/acceptance/pageObjects/LoginPage.js | 4 +++ .../stepDefinitions/createFileContext.js | 18 ++++++++++++ .../stepDefinitions/loginContext.js | 5 ++++ 7 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 frontend/tests/acceptance/features/createFile.feature create mode 100644 frontend/tests/acceptance/pageObjects/CreateFilePage.js create mode 100644 frontend/tests/acceptance/stepDefinitions/createFileContext.js diff --git a/frontend/cucumber.conf.js b/frontend/cucumber.conf.js index ca374ecf..c3c25106 100644 --- a/frontend/cucumber.conf.js +++ b/frontend/cucumber.conf.js @@ -3,13 +3,13 @@ const { Before, BeforeAll, AfterAll, After, setDefaultTimeout } = require("@cucumber/cucumber"); const { chromium } = require("playwright"); -setDefaultTimeout(60000) +setDefaultTimeout(30000) // launch the browser BeforeAll(async function () { global.browser = await chromium.launch({ headless: false, - slowMo: 1000, + slowMo: 500, }); }); diff --git a/frontend/tests/acceptance/features/createFile.feature b/frontend/tests/acceptance/features/createFile.feature new file mode 100644 index 00000000..945a1b48 --- /dev/null +++ b/frontend/tests/acceptance/features/createFile.feature @@ -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" \ No newline at end of file diff --git a/frontend/tests/acceptance/features/login.feature b/frontend/tests/acceptance/features/login.feature index 60f09668..39b7d29e 100644 --- a/frontend/tests/acceptance/features/login.feature +++ b/frontend/tests/acceptance/features/login.feature @@ -3,7 +3,7 @@ Feature: login I want to login to the system So that I can manage the files and folders - Scenario: login with valid username and valid password - Given the user has browsed to the login page - When user logs in with username "admin" and password "admin" - Then user should redirect to the homepage \ No newline at end of file +Scenario: login with valid username and valid password + Given the user has browsed to the login page + When user logs in with username "admin" and password "admin" + Then user should redirect to the homepage \ No newline at end of file diff --git a/frontend/tests/acceptance/pageObjects/CreateFilePage.js b/frontend/tests/acceptance/pageObjects/CreateFilePage.js new file mode 100644 index 00000000..027d3f70 --- /dev/null +++ b/frontend/tests/acceptance/pageObjects/CreateFilePage.js @@ -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 \ No newline at end of file diff --git a/frontend/tests/acceptance/pageObjects/LoginPage.js b/frontend/tests/acceptance/pageObjects/LoginPage.js index b5815ce4..1b45fec0 100644 --- a/frontend/tests/acceptance/pageObjects/LoginPage.js +++ b/frontend/tests/acceptance/pageObjects/LoginPage.js @@ -20,6 +20,10 @@ class LoginPage { await page.fill(this.passwordSelector, password); await page.click(this.loginSelector); } + + // async assertLoginPageIsOpen() { + // await expect(this.page).toHaveURL(this.loginUrl); + // } } module.exports = LoginPage \ No newline at end of file diff --git a/frontend/tests/acceptance/stepDefinitions/createFileContext.js b/frontend/tests/acceptance/stepDefinitions/createFileContext.js new file mode 100644 index 00000000..9a3eeb0a --- /dev/null +++ b/frontend/tests/acceptance/stepDefinitions/createFileContext.js @@ -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) { + +}); \ No newline at end of file diff --git a/frontend/tests/acceptance/stepDefinitions/loginContext.js b/frontend/tests/acceptance/stepDefinitions/loginContext.js index 9bf40c37..b7b3214b 100644 --- a/frontend/tests/acceptance/stepDefinitions/loginContext.js +++ b/frontend/tests/acceptance/stepDefinitions/loginContext.js @@ -14,6 +14,11 @@ Given('the user has browsed to the login page', async function () { 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) { await loginPage.login(username,password); });