-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from nabim777/yogest-feature-file
login feature and createResource feature
- Loading branch information
Showing
7 changed files
with
247 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const util = require('util'); | ||
const { filesToDelete } = require('../../../../testHelper/helper.js'); | ||
|
||
class HomePage{ | ||
|
||
constructor(){ | ||
this.dialogInputSelector = '//input[@class="input input--block"]'; | ||
this.lastNavaigatedFolderSelector = '//div[@class="breadcrumbs"]/span[last()]/a' | ||
this.contentEditorSelector = '//textarea[@class="ace_text-input"]' | ||
this.editorContent = '//div[@class="ace_line"]' | ||
this.buttonSelector =`//button[@title="%s"]` | ||
this.fileSelector = `//div[@aria-label="%s"]` | ||
this.cardActionSelector = '//div[@class="card-action"]/button[@title="%s"]' | ||
} | ||
|
||
async createNewFolder(folderName){ | ||
await page.click( util.format(this.buttonSelector,'New folder')) | ||
await page.fill(this.dialogInputSelector, folderName) | ||
await page.click(util.format(this.cardActionSelector,'Create')) | ||
} | ||
|
||
async createFileWithContent(filename, content){ | ||
await page.click(util.format(this.buttonSelector,'New file')) | ||
await page.fill(this.dialogInputSelector, filename) | ||
await page.click(util.format(this.cardActionSelector,'Create')) | ||
await page.fill(this.contentEditorSelector, content) | ||
await page.click( util.format(this.buttonSelector,'Save')) | ||
await page.click(util.format(this.buttonSelector,'Close')) | ||
|
||
//saving the file info into global array to delete later | ||
filesToDelete.push(filename) | ||
} | ||
|
||
async renameFile(oldfileName,newfileName){ | ||
await page.click(util.format(this.fileSelector,oldfileName)) | ||
await page.click(util.format(this.buttonSelector,'Rename')) | ||
await page.fill(this.dialogInputSelector, newfileName) | ||
await page.click(util.format(this.cardActionSelector,'Rename')) | ||
const fileToSwapIndex = filesToDelete.findIndex((file) => file == oldfileName); | ||
filesToDelete[fileToSwapIndex] = newfileName; | ||
} | ||
|
||
async deleteFile(filename){ | ||
await page.click(util.format(this.fileSelector,filename)) | ||
await page.click(util.format(this.buttonSelector,'Delete')) | ||
await page.click(util.format(this.cardActionSelector,'Delete')) | ||
} | ||
} | ||
|
||
exports.HomePage = HomePage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class LoginPage { | ||
constructor() { | ||
this.usernameSelector = '//input[@type="text"]' | ||
this.passwordSelector = '//input[@type="password"]' | ||
this.loginButton = '//input[@type="submit"]' | ||
this.wrongCredentialsDivSelector = '//div[@class="wrong"]' | ||
this.baseURL = "http://localhost:8080/" | ||
} | ||
|
||
async navigateToLoginPage() { | ||
await page.goto(this.baseURL + 'login') | ||
} | ||
|
||
async loginWithUsernameAndPassword(username, password) { | ||
await page.fill(this.usernameSelector, username); | ||
await page.fill(this.passwordSelector, password); | ||
await page.click(this.loginButton); | ||
} | ||
|
||
async loginBasedOnRole(role) { | ||
this.navigateToLoginPage() | ||
switch (role) { | ||
case 'admin': | ||
await this.loginWithUsernameAndPassword('admin', 'admin') | ||
break; | ||
case 'user': | ||
await this.loginWithUsernameAndPassword('user', 'user') | ||
break; | ||
default: | ||
throw new Error(`Invalid role ${role} passed`) | ||
} | ||
} | ||
} | ||
|
||
exports.LoginPage=LoginPage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Feature: Create a new resource | ||
As a admin | ||
I want to be able to create a new files and folders | ||
So that I can organize my files | ||
|
||
Background: | ||
Given "admin" has logged in | ||
And admin has navigated to the homepage | ||
|
||
|
||
Scenario: Create a new folder | ||
When admin creates a new folder named "myFolder" | ||
Then admin should be able to see a folder named "myFolder" | ||
|
||
|
||
Scenario: Create a new file with content | ||
When admin creates a new file named "myFile.txt" with content "Hello World" | ||
Then admin should be able to see a file named "myFile.txt" with content "Hello World" | ||
|
||
|
||
Scenario: Rename a file | ||
Given admin has created a file named "oldfile.txt" with content "Hello World" | ||
When admin renames a file "oldfile.txt" to "newfile.txt" | ||
Then admin should be able to see file with "newfile.txt" name | ||
|
||
|
||
Scenario: Delete a file | ||
Given admin creates a new file named "delMyFile.txt" using API | ||
When admin deletes a file named "delMyFile.txt" | ||
Then admin shouln't see "delMyFile" in the UI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Feature: Login | ||
As an admin | ||
I want to login into the application | ||
So I can manage my files | ||
|
||
Background: | ||
Given admin has browsed to the login page | ||
|
||
|
||
Scenario: admin logs in with correct credentials | ||
When admin logs in with username as 'admin' and password as 'admin' | ||
Then admin should be navigated to homescreen | ||
|
||
|
||
Scenario Outline: admin logs in with incorrect credentials | ||
When admin logs in with username as "<username>" and password as "<password>" | ||
Then admin should see "Wrong credentials" message | ||
Examples: | ||
| username | password | | ||
| jankari | admin | | ||
| admin | jankari | | ||
| | admin | | ||
| admin | | | ||
| | | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const { Given, When, Then } = require('@cucumber/cucumber') | ||
const assert = require('assert'); | ||
const util = require('util') | ||
const {expect} = require('@playwright/test') | ||
|
||
const { HomePage } = require("../PageObject/HomePage"); | ||
const { LoginPage } = require('../PageObject/LoginPage'); | ||
const { createFile } = require('../../../../testHelper/helper'); | ||
|
||
const login = new LoginPage() | ||
const homepage = new HomePage() | ||
|
||
Given('{string} has logged in', async function (role) { | ||
await login.loginBasedOnRole(role) | ||
}); | ||
|
||
Given('admin has navigated to the homepage', async function () { | ||
await expect(page).toHaveURL(login.baseURL + 'files/') | ||
}); | ||
|
||
When('admin creates a new folder named {string}', async function (folderName) { | ||
await homepage.createNewFolder(folderName) | ||
}); | ||
|
||
Then('admin should be able to see a folder named {string}', async function (folderName) { | ||
const userCreatedFolderName = await page.innerHTML(homepage.lastNavaigatedFolderSelector) | ||
assert.equal(userCreatedFolderName, folderName, `Expected "${folderName}" but recieved message "${userCreatedFolderName}" from UI`) | ||
}); | ||
|
||
Given('admin has created a file named {string} with content {string}',async function (filename,content){ | ||
await homepage.createFileWithContent(filename, content) | ||
await expect(page.locator(util.format(homepage.fileSelector,filename))).toBeVisible() | ||
}) | ||
|
||
When('admin creates a new file named {string} with content {string}', async function (filename, content) { | ||
await homepage.createFileWithContent(filename, content) | ||
}); | ||
|
||
Given('admin creates a new file named {string} using API', async function (filename) { | ||
await createFile(filename) | ||
await page.reload() | ||
await expect(page.locator(util.format(homepage.fileSelector,filename))).toBeVisible() | ||
}); | ||
|
||
|
||
Then('admin should be able to see a file named {string} with content {string}', async function (filename, content) { | ||
await expect(page.locator(util.format(homepage.fileSelector,filename))).toBeVisible() | ||
await page.dblclick(util.format(homepage.fileSelector,filename)); | ||
const fileContent = await page.innerHTML(homepage.editorContent) | ||
assert.equal(fileContent, content, `Expected content as "${content}" but recieved "${fileContent}"`) | ||
}); | ||
|
||
When('admin renames a file {string} to {string}',async function(oldfileName,newfileName){ | ||
await homepage.renameFile(oldfileName,newfileName) | ||
}) | ||
|
||
Then('admin should be able to see file with {string} name',async function(newfileName){ | ||
await expect(page.locator(util.format(homepage.fileSelector,newfileName))).toBeVisible() | ||
}) | ||
|
||
When('admin deletes a file named {string}',async function(filename){ | ||
await homepage.deleteFile(filename) | ||
}) | ||
|
||
Then('admin shouln\'t see {string} in the UI',async function(filename){ | ||
await expect(page.locator(util.format(homepage.fileSelector,filename))).toBeHidden() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const { Given, When, Then } = require('@cucumber/cucumber') | ||
const { expect } = require('@playwright/test'); | ||
const assert = require('assert'); | ||
|
||
const { LoginPage } = require('../PageObject/LoginPage'); | ||
|
||
const login = new LoginPage() | ||
|
||
Given('admin has browsed to the login page', async () => { | ||
await login.navigateToLoginPage() | ||
await expect(page).toHaveURL(login.baseURL + 'login') | ||
}); | ||
|
||
When('admin logs in with username as {string} and password as {string}', async (username, password) => { | ||
await login.loginWithUsernameAndPassword(username,password) | ||
}); | ||
|
||
Then('admin should be navigated to homescreen', async function () { | ||
await expect(page).toHaveURL(login.baseURL + "files/"); | ||
}); | ||
|
||
Then('admin should see {string} message', async function (expectedMessage) { | ||
const errorMessage = await page.innerHTML(login.wrongCredentialsDivSelector) | ||
assert.equal(errorMessage, expectedMessage, `Expected message string "${expectedMessage}" but received message "${errorMessage}" from UI`) | ||
}); |