Skip to content

Commit

Permalink
Inital test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Sijo Cheeran committed Dec 30, 2021
1 parent 2d5e515 commit 4ecb962
Show file tree
Hide file tree
Showing 8 changed files with 3,739 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
4 changes: 4 additions & 0 deletions .testcaferc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"skipJsErrors": true,
"skipUncaughtErrors": true
}
3,640 changes: 3,640 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "testcafe-example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/sijosyn/testcafe-example.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/sijosyn/testcafe-example/issues"
},
"homepage": "https://github.com/sijosyn/testcafe-example#readme",
"dependencies": {
"testcafe": "^1.18.1"
}
}
10 changes: 10 additions & 0 deletions pages/account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Selector } from 'testcafe';

class accountPage {

myAccount = Selector('[title="MY ACCOUNT"]');
emailAddress = Selector('[name="EMAIL_ADDRESS"]')

}

export let account = new accountPage();
13 changes: 13 additions & 0 deletions pages/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Selector } from 'testcafe';

class searchPage {

searchIcon = Selector('.js-esearch-open-icon');
searchTextBox = Selector('[name=search]');
searchSuggestionItem = Selector('.search-suggestions__item');
productResults = Selector('.product-results');
esearchProduct = Selector('.esearch-product');
searchNoResults = Selector('.search-no-results');
}

export let search = new searchPage();
10 changes: 10 additions & 0 deletions tests/account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { account } from '../pages/account';

fixture`Account functionality fixture`
.page`https://www.darphin.com/`;

test('Check account sign up functionality', async t => {
// Click search icon and search for milk
await t.click(account.myAccount);

});
39 changes: 39 additions & 0 deletions tests/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { search } from '../pages/search';

fixture`Search functionality fixture`
.page`https://www.darphin.com/`;

test('Check search suggestion works and matches search result items', async t => {
// Click search icon and search for milk
await t.click(search.searchIcon);
await t.typeText(search.searchTextBox, 'milk');

// Check the product results suggestion box is visible
await t.expect(search.productResults.visible).ok();

// Extract the number of search result items from search suggestion
let text = await search.searchSuggestionItem.textContent;
let itemNumber =text.replace(/\D/g,"")

// Hit enter key to navigate to search results page
await t.pressKey('enter');

// Verify the search results shows the expected number of items
await t.expect(search.esearchProduct.count).eql(parseInt(itemNumber));
});


test('Check search returns no matching items', async t => {
// Click search icon and search for milk
await t.click(search.searchIcon);
await t.typeText(search.searchTextBox, 'honey');

// Check the product results suggestion box is not shown
await t.expect(search.productResults.visible).notOk();

// Hit enter key to navigate to search results page
await t.pressKey('enter');

// Verify no items found matching text is displayed
await t.expect(search.searchNoResults.textContent).contains('No items found matching');
});

0 comments on commit 4ecb962

Please sign in to comment.