Skip to content

Commit

Permalink
Merge pull request #85 from katalon-studio-samples/TO-1429
Browse files Browse the repository at this point in the history
[TO-1429] Create protractor mocha sample
  • Loading branch information
thongmgnguyen authored Apr 28, 2021
2 parents e4a98d8 + c204640 commit 90c993f
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
29 changes: 29 additions & 0 deletions protractor-mocha/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
18 changes: 18 additions & 0 deletions protractor-mocha/protractor.conf.js
Original file line number Diff line number Diff line change
@@ -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",
},
};
6 changes: 6 additions & 0 deletions protractor-mocha/testops-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"apiKey": "",
"basePath": "",
"projectId": "",
"reportFolder": ""
}
56 changes: 56 additions & 0 deletions protractor-mocha/tests/testops.test.ts
Original file line number Diff line number Diff line change
@@ -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
});
});
});
});
18 changes: 18 additions & 0 deletions protractor-mocha/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}

0 comments on commit 90c993f

Please sign in to comment.