diff --git a/frontend/www/scripts/tests.js b/frontend/www/scripts/tests.js new file mode 100644 index 0000000000000000000000000000000000000000..eb25843b434680dbce447a7821180e673ec4bc4c --- /dev/null +++ b/frontend/www/scripts/tests.js @@ -0,0 +1,71 @@ +//single_test.js:Jest testing tutorial for Selenium JavaScript Testing +/** + * @jest-environment jest-environment-webdriver + */ +const webdriver = require('selenium-webdriver'); + +const script = require('jest'); + +const url = 'https://www.selenium.dev/' + +const getElementXpath = async (driver, xpath, timeout = 3000) => { + const el = await driver.wait(until.elementLocated(By.xpath(xpath)), timeout); + return await driver.wait(until.elementIsVisible(el), timeout); +}; + + +const getElementName = async (driver, name, timeout = 3000) => { + const el = await driver.wait(until.elementLocated(By.name(name)), timeout); + return await driver.wait(until.elementIsVisible(el), timeout); +}; + +const getElementId = async (driver, id, timeout = 3000) => { + const el = await driver.wait(until.elementLocated(By.id(id)), timeout); + return await driver.wait(until.elementIsVisible(el), timeout); +}; + +// declaring the test group This is our test case scenario that we will execute from our first test script. +describe('executing test scenario on the website www.selenium.dev', () => { + + let driver; + + driver = new webdriver().build(); + + // func to get the cloud driver eslint disable next line no undef + await driver.get( + ‘https://www.selenium.dev’, + ); + }, 10000); + + afterAll(async () => { + await driver.quit(); + }, 15000); + + test('it performs a validation of title on the home page', async () => { + await browser.get(url) + const title = await browser.findElement(by.tagName('h1')).getText() + expect(title).toContain('SeleniumHQ Browser Automation') + }) + + test('it performs a validation of the search box on the page', async () => { + const foundAndLoadedCheck = async () => { + await until.elementLocated(by.id('search')) + const value = await browser.findElement(by.id('search')).getText() + return value !== '~' + } + + await browser.wait(foundAndLoadedCheck, 3000) + const search = await browser.findElement(by.id('search')).getText() + expect(search).toEqual('') + }) + +// declaring the test group + + describe('it captures a screenshot of the current page on the browser', () => { + test('snap a picture by taking the screenshot', async () => { + // files saved in ./reports/screenshots by default + await browser.get(url) + await browser.takeScreenshot() + }) + }) +}) \ No newline at end of file diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000000000000000000000000000000000000..f610376794b9bcadc8915485a457e63b46f7f140 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,132 @@ +//Jest testing tutorial for Selenium JavaScript Testing +// This configuration properties are taken from the official Jest documentation which is available at https://jestjs.io/docs/en/configuration.html +//const {default} = require('jest-config'); +module.exports = { + // It indicates that each one imported modules in the tests must be mocked automatically + automock: false, + // It indicates that it must prevent running the assessments after the primary failure is encountered + bail: false, + // It indicates the "browser" field in package.Json when resolving modules + browser: false, + // It indicates the listing where Jest must save the cached dependency details gathered from all throughout the tests + cacheDirectory: "/var/folders/jest_dx", + // It suggests that the framework must automatically clean mock calls and instances between each test + clearMocks: true, + // It shows whether or not it have to have the coverage data collected while executing the test + collectCoverage: false, + // It indicates that each one imported modules in the tests must be mocked automatically +// It indicates that an array of record extensions our modules should be using + moduleFileExtensions: [ + "js", + "json", + "jsx", + "node" + ], + // It suggests the Jest to have an enum that specifies notification mode. Requires notify: true + notifyMode: "always", + // It indicates the framework to have a preset this is used as a base for Jest's configuration + preset: null, + // It suggests to run tests from one or extra projects + projects: null, + // This indicates using the configuration to add custom newshounds to Jest + reporters: undefined, + // This configuration shows the Jest to routinely reset mock state between every test + resetMocks: false, + // This property suggests Jest to reset the module registry earlier than walking each person test + resetModules: false, + // This configuration indicates Jest testing framework to the course of a custom resolver + resolver: null, + // This configuration indicates Jest to the course of a custom resolver + // This configuration indicates the Jest to allows us to apply a custom runner in preference to Jest's default inbuilt Jest test runner + runner: "jest-runner", + // This configuration factors to the trails to modules that run a few code to configure or installation the test environment before each test run + setupFiles: [], + // This configuration indicates the Jest to the direction to a module that runs some code to configure or installation the testing framework before than each test run + setupFilesAfterEnv: null, + // This configuration factors the Jest to the list of paths of the snapshot serializer modules that Jest must use for each of the snapshot testing + snapshotSerializers: [], + // This configuration suggests the Jest to allow using a custom outcome or the result processor + testResultsProcessor: null, + // This configuration shows the Jest to permit the usage of a new custom test runner instead of the default + testRunner: "jasmine2", + // This configuration shows the Jest testing framework to assign the URL for the jsdom environment. It is shown in properties and configuration like the location.Href testURL: "http://localhost", + testURL: "http://localhost", + // This property points to the setting of the price to "faux" lets in the use of fake timers for capabilities which includes "setTimeout" + timers: "real", + // This property suggests the Jest to a map from regular expressions to paths to transformers + transform: null, + // This configuration shows the Jest to an array of regex expression sample strings which are matched towards all source record paths, matched documents will pass transformation + transformIgnorePatterns: [ + "/node_modules/" + ], + // It suggests that a map from ordinary regex to module names that permit to stub out assets with a single module + moduleNameMapper: {}, + // It suggests that an array of regex expression sample strings, matched against all module paths before considered 'visible' to the module loader + modulePathIgnorePatterns: [], + // It suggests the Jest to prompt notifications for take a look at results + notify: false, + // This configuration indicates the Jest which take a look at test environment it need to use for the testing run + testEnvironment: "jest-environment-jsdom", + // This configuration shows the Jest to the options so one can be passed to the testEnvironment + testEnvironmentOptions: {}, + // This configuration shows the Jest to add a location field to test the outcome of the run + testLocationInResults: false, + // This configuration factors to the glob patterns Jest uses to detect test files + testMatch: [ + "**/__tests__/**/*.js?(x)", + "**/?(*.)+(spec|test).js?(x)" + ], + // This configuration indicates the Jest to an array of regexp pattern strings that are matched towards all test paths, matched tests are skipped + testPathIgnorePatterns: [ + "/node_modules/" + ], + // This configuration points to the regexp sample Jest makes use of to detect test files + testRegex: "", + // This configuration shows the Jest to routinely restore mock state among every tests that are executed + restoreMocks: false, + // This configuration suggests framework to the root listing that Jest should check for the test cases and modules inside them + rootDir: null, + // This configuration shows the Jest framework to the list of paths to directories that Jest ought to use to look for files inside them + roots: [ + "<rootDir>" + ], + // It indicates that an array of glob patterns indicating a hard and fast of files for which insurance statistics ought to be collected + collectCoverageFrom: null, + // It indicates the directory in which Jest ought to output its coverage documents and test files + coverageDirectory: 'coverage', + // This property shows that an array of regexp sample strings used to skip the test coverage collection + coveragePathIgnorePatterns: [ + "/node_modules/" + ], + // It indicates that a list of reporter names that Jest makes use of whilst writing coverage reports + coverageReporters: [ + "json", + "text", + "lcov", + "clover" + ], + // This property shows that an item that configures minimal threshold enforcement for coverage reports + coverageThreshold: null, + // This property shows that framework have to make call of deprecated APIs and throw helpful errors messages + errorOnDeprecated: false, + // This property indicates the Jest testing framework to force insurance collection from ignored files using a array of glob patterns + forceCoverageMatch: [], + // It suggests the route to a module which exports an async characteristic this is triggered as soon as earlier than all test suites + globalSetup: null, + // It shows the course of the module which exports an async function that is brought on as soon as after all test suites + globalTeardown: null, + // It suggests the set of world variables that are required to be available in all test environments + globals: {}, + // It indicates an array of directory names to be searched recursively up from the requiring module's location + moduleDirectories: [ + "node_modules" + ], + // This configuration shows the Jest testing framework to an array of regexp sample strings which might be matched against all modules earlier than the module loader will mechanically return a mock data for the test case + unmockedModulePathPatterns: undefined, + // This configuration shows the Jest testing framework whether or not each separate test cases should be reported during the executed test run + verbose: true, + // This configuration shows the Jest testing framework to an array of regexp patterns which might be matched against all source document paths before re-running tests in watch mode + watchPathIgnorePatterns: [], + // This configuration shows the Jest testing framework whether or not the watchman should be used for document crawling + watchman: true, + }; \ No newline at end of file diff --git a/package.json b/package.json index 824db299bd90a67db0734d957792a22a70ae9003..276ccea10f5c639a669e1134ff1ef9620a3cdb1e 100644 --- a/package.json +++ b/package.json @@ -10,5 +10,57 @@ "cordova-browser": "6.0.0", "cordova-plugin-whitelist": "^1.3.4", "selenium-webdriver": "^4.0.0-beta.1" +<<<<<<< HEAD +======= + }, + + "name": "Jest-Selenium-Webdriver-Test", + "version": "0.1.0", + "description": "Executing Our First Jest Automation Test Script with Selenium JavaScript Testing on Lambdatest", + "keywords": [ + "javascript", + "selenium", + "tdd", + "local", + "test", + "jest" + ], + + "scripts": { + "test": "jest" + }, + + "author": "rohit", + "license": "MIT", + "devDependencies": { + "babel-eslint": "^10.0.1", + "babel-jest": "^24.8.0", + "babel-plugin-external-helpers": "^6.22.0", + "babel-plugin-transform-object-rest-spread": "^6.26.0", + "babel-preset-env": "^1.7.0", + "chromedriver": "^74.0.0", + "eslint": "^5.16.0", + "eslint-config-airbnb-base": "^13.1.0", + "eslint-config-prettier": "^4.3.0", + "eslint-plugin-import": "^2.17.3", + "eslint-plugin-jest": "^22.6.4", + "eslint-plugin-prettier": "^3.1.0", + "jasmin": "0.0.2", + "jasmine": "^3.4.0", + "jest": "^24.8.0", + "jest-environment-webdriver": "^0.2.0", + "jsdom": "^15.1.1", + "prettier": "^1.17.1", + "rimraf": "^2.6.3", + "selenium-webdriver": "^4.0.0-alpha.1" + }, + + "jest": { + "setupTestFrameworkScriptFile": "./jest.config.js", + "testEnvironment": "jest-environment-webdriver", + "testEnvironmentOptions": { + "browser": "chrome" + } +>>>>>>> b6940eff2a3f78a8377c1ce0a3f5b2b42f4d44fe } -} +} \ No newline at end of file