Created
June 5, 2018 05:41
-
-
Save nickhodge/b7d04b2b652a69a5f8f3ed26920ac4b9 to your computer and use it in GitHub Desktop.
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
import { Builder, Capabilities, By, until, ThenableWebDriver } from 'selenium-webdriver'; | |
import { expect, should } from 'chai'; | |
should(); // this inits the chai should above up. for some reason | |
import { chaiWebDriver } from 'chai-webdriver'; | |
import { spawn } from 'cross-spawn-async'; | |
import 'mocha'; | |
let iisPath = "C:\\Program Files (x86)\\IIS Express\\iisexpress.exe"; | |
var webserver; | |
var webbrowser : ThenableWebDriver; | |
let webserverurlbase = "http://localhost:52322/"; // comes from debug port settings | |
describe("Test Base", () => { | |
before(async () => { | |
webserver = spawn(iisPath, ['/path:C:\\work\\xxx\\yyy\\', '/port:52322']); // points to asp.net 4.x project to launch | |
var chromeCapabilities = Capabilities.chrome(); | |
var chromeOpts = { "args": ["--log-level=3"] }; // turn off any chromedriver messages | |
chromeCapabilities.set('chromeOptions', chromeOpts); | |
webbrowser = new Builder().withCapabilities(chromeCapabilities).build(); | |
}); | |
after(() => { | |
spawn("taskkill", ["/pid", webserver.pid, '/f', '/t']); //this nice code that kills the iisexpress server, dead (on Windows of course) | |
webbrowser.quit(); | |
}); | |
it('should be redirected OK', async () => { | |
await webbrowser.get(webserverurlbase); | |
const title = await webbrowser.getTitle(); | |
title.should.equal("xxx"); | |
}); | |
it('should be login OK', async () => { | |
await webbrowser.get(webserverurlbase); | |
const title = await webbrowser.getTitle(); | |
title.should.equal("xxx"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a part of package.json
.... "dependencies": { "@types/es6-promise": "^3.3.0", "@types/es6-shim": "^0.31.37", "@types/selenium-webdriver": "^3.0.8", "chromedriver": "^2.38.3", "selenium": "^2.20.0", "selenium-webdriver": "^4.0.0-alpha.1" }, "devDependencies": { "@types/chai": "^4.1.3", "@types/mocha": "^5.2.0", "chai": "^4.1.2", "chai-webdriver": "^1.2.0", "chrome-driver-standalone": "^2.37.0", "cross-spawn-async": "^2.2.5", "mocha": "^5.2.0", "ts-node": "^6.0.5", "typescript": "^2.9.1" }, "scripts": { "test": "mocha --require ts-node/register --lib ['es6'] --strict false ./test/*.spec.ts" },