diff --git a/README.md b/README.md index 89345f2..b7eb1e8 100644 --- a/README.md +++ b/README.md @@ -29,4 +29,10 @@ cd jest && npm install && npm test `protractor` directory ``` cd protractor && npm install && npm test +``` + +# Protractor Mocha Sample +`protractor-mocha` directory +``` +cd protractor-mocha && npm install && npm test ``` \ No newline at end of file diff --git a/protractor-mocha/package.json b/protractor-mocha/package.json new file mode 100644 index 0000000..a144c58 --- /dev/null +++ b/protractor-mocha/package.json @@ -0,0 +1,29 @@ +{ + "name": "testops-protractor-mocha-sample", + "version": "1.0.0", + "description": "TestOps Protractor Mocha sample", + "scripts": { + "build": "tsc", + "pretest": "npm run cleanup && npm run build && npm run update-webdriver", + "test": "protractor", + "cleanup": "rimraf dist", + "update-webdriver": "webdriver-manager update" + }, + "author": "Katalon, LLC. (https://www.katalon.com)", + "license": "ISC", + "dependencies": { + "@katalon/testops-mocha": "latest", + "@katalon/testops-protractor": "latest", + "chai": "^4.3.4", + "chai-as-promised": "^7.1.1" + }, + "devDependencies": { + "@tsconfig/node10": "^1.0.7", + "@types/chai": "^4.2.14", + "@types/chai-as-promised": "^7.1.3", + "@types/mocha": "^8.2.2", + "mocha": "^8.2.1", + "rimraf": "^3.0.2", + "typescript": "^4.1.3" + } +} diff --git a/protractor-mocha/protractor.conf.js b/protractor-mocha/protractor.conf.js new file mode 100644 index 0000000..590a44f --- /dev/null +++ b/protractor-mocha/protractor.conf.js @@ -0,0 +1,18 @@ + +exports.config = { + framework: "mocha", + specs: ["./dist/tests/*.js"], + capabilities: { + browserName: "chrome", + args: ["--headless", "--disable-dev-shm-usage", "--no-sandbox"], + }, + plugins: [ + { + package: "@katalon/testops-protractor", + }, + ], + mochaOpts: { + timeout: "20s", + reporter: "@katalon/testops-mocha", + }, +}; diff --git a/protractor-mocha/testops-config.json b/protractor-mocha/testops-config.json new file mode 100644 index 0000000..ed175f3 --- /dev/null +++ b/protractor-mocha/testops-config.json @@ -0,0 +1,6 @@ +{ + "apiKey": "", + "basePath": "", + "projectId": "", + "reportFolder": "" +} diff --git a/protractor-mocha/tests/testops.test.ts b/protractor-mocha/tests/testops.test.ts new file mode 100644 index 0000000..7be43c0 --- /dev/null +++ b/protractor-mocha/tests/testops.test.ts @@ -0,0 +1,56 @@ +import { browser, element, by } from "protractor"; +import { ElementFinder } from "protractor/built"; +import chai from "chai"; +import chaiAsPromised from "chai-as-promised" + +chai.use(chaiAsPromised); +const expect = chai.expect; + +describe("slow calculator", function () { + beforeEach(function () { + browser.get("https://juliemr.github.io/protractor-demo/"); + }); + + it("should add numbers", function () { + element(by.model("first")).sendKeys(4); + element(by.model("second")).sendKeys(5); + + element(by.id("gobutton")).click(); + + expect(element(by.binding("latest")).getText()).to.eventually.equal("9"); + }); + + describe("memory", function () { + let first: ElementFinder, second: ElementFinder, goButton: ElementFinder; + beforeEach(function () { + first = element(by.model("first")); + second = element(by.model("second")); + goButton = element(by.id("gobutton")); + }); + + it("should start out with an empty memory", function () { + const memory = element.all(by.repeater("result in memory")); + + expect(memory.count()).to.eventually.equal(0); + }); + + it("should fill the memory with past results", function () { + first.sendKeys(1); + second.sendKeys(1); + goButton.click(); + + first.sendKeys(10); + second.sendKeys(20); + goButton.click(); + + const memory = element.all( + by.repeater("result in memory").column!("result.value") + ); + memory.then(function (arr) { + expect(arr.length).to.equal(2); + expect(arr[0].getText()).to.eventually.equal("30"); // 10 + 20 = 30 + expect(arr[1].getText()).to.eventually.equal("2"); // 1 + 1 = 2 + }); + }); + }); +}); diff --git a/protractor-mocha/tsconfig.json b/protractor-mocha/tsconfig.json new file mode 100644 index 0000000..4fd8dbb --- /dev/null +++ b/protractor-mocha/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "rootDir": ".", + "outDir": "./dist", + + // Include source maps for Jest + "declaration": true, + "declarationMap": true, + "sourceMap": true, + + "allowSyntheticDefaultImports": true, + "allowJs": true + }, + "extends": "@tsconfig/node10/tsconfig.json", + "exclude": [ + "./dist" + ] +}