Skip to content

Commit 01a6ff9

Browse files
committed
updated webdriver + chromedriver, updated table.html
1 parent dc760a2 commit 01a6ff9

File tree

9 files changed

+39
-49
lines changed

9 files changed

+39
-49
lines changed

webdriver-ts/package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
8-
"postinstall": "typings install && tsc",
98
"compile": "tsc",
109
"build-prod": "tsc",
1110
"selenium": "node dist/benchmarkRunner.js",
@@ -17,16 +16,19 @@
1716
"author": "",
1817
"license": "Apache-2.0",
1918
"devDependencies": {
20-
"typescript": "2.0.3",
21-
"typings": "1.4.0"
19+
"@types/lodash": "^4.14.55",
20+
"@types/node": "^7.0.8",
21+
"@types/selenium-webdriver": "^3.0.0",
22+
"@types/yargs": "^6.6.0",
23+
"typescript": "2.2.1"
2224
},
2325
"dependencies": {
24-
"chromedriver": "2.27.2",
25-
"dot": "1.0.3",
26+
"chromedriver": "2.28.0",
27+
"dot": "1.1.1",
2628
"jstat": "1.5.3",
27-
"lodash": "4.16.4",
29+
"lodash": "4.17.4",
2830
"rgba-convert": "0.3.0",
29-
"selenium-webdriver": "^2.53.3",
30-
"yargs": "6.0.0"
31+
"selenium-webdriver": "^3.3.0",
32+
"yargs": "7.0.2"
3133
}
3234
}

webdriver-ts/src/benchmarkRunner.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ function buildDriver() {
6969
options = options.addArguments("--js-flags=--expose-gc");
7070
options = options.setLoggingPrefs(logPref);
7171
options = options.setPerfLoggingPrefs(<any>{enableNetwork: false, enablePage: false, enableTimeline: false, traceCategories: "v8,blink.console,disabled-by-default-devtools.timeline,devtools.timeline,blink.user_timing", bufferUsageReportingInterval: 10000});
72-
7372
return new Builder()
7473
.forBrowser('chrome')
7574
.setChromeOptions(options)
@@ -119,7 +118,7 @@ function initBenchmark(driver: WebDriver, benchmark: Benchmark, framework: Frame
119118
}
120119
})
121120
.then(() => clearLogs(driver))
122-
.thenCatch( (err) => {
121+
.catch((err:any) => {
123122
console.log(`error in initBenchmark ${framework} ${benchmark.id}`);
124123
throw err;
125124
});
@@ -160,7 +159,7 @@ function runMemOrCPUBenchmark(framework: FrameworkData, benchmark: Benchmark) :
160159
return driver.get(`http://localhost:8080/${framework.uri}/`)
161160
.then(() => initBenchmark(driver, benchmark, framework))
162161
.then(() => runBenchmark(driver, benchmark, framework))
163-
.thenCatch((e) => {
162+
.catch((e) => {
164163
console.error("Benchmark failed",e);
165164
driver.takeScreenshot().then(
166165
function(image) {
@@ -174,7 +173,7 @@ function runMemOrCPUBenchmark(framework: FrameworkData, benchmark: Benchmark) :
174173
})
175174
.then(results => reduceBenchmarkResults(benchmark, results))
176175
.then(results => writeResult({framework: framework, results: results, benchmark: benchmark}, dir))
177-
.thenFinally(() => {console.log("QUIT"); driver.quit();})
176+
.then(() => {console.log("QUIT"); driver.quit();}, () => {console.log("QUIT after error"); driver.quit();})
178177
}
179178

180179
function runStartupBenchmark(framework: FrameworkData, benchmark: Benchmark) : promise.Promise<any> {
@@ -189,18 +188,19 @@ function runStartupBenchmark(framework: FrameworkData, benchmark: Benchmark) : p
189188
// Check what we measured. Results are pretty similar, though we are measuring a bit longer until the final repaint happened.
190189
// .then(() => driver.executeScript("return window.performance.timing.loadEventEnd - window.performance.timing.navigationStart"))
191190
// .then((duration) => console.log(duration, typeof duration))
192-
.thenCatch((e) => {
191+
.then(() => {console.log("QUIT"); driver.quit();},
192+
(e) => {
193193
console.error("Benchmark failed",e);
194194
driver.takeScreenshot().then(
195195
function(image) {
196196
(<any>fs).writeFileSync('error-'+framework+'_startup.png', image, 'base64', function(err:any) {
197197
console.log(err);
198+
console.log("QUIT after error"); driver.quit();
198199
});
199200
throw e;
200201
}
201202
);
202203
})
203-
.thenFinally(() => {console.log("QUIT"); driver.quit();})
204204
})
205205
.then(() => reduceBenchmarkResults(benchmark, results))
206206
.then(results => writeResult({framework: framework, results: results, benchmark: benchmark}, dir))

webdriver-ts/src/benchmarks.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {testTextContains, testTextNotContained, testClassContains, testElementLocatedByXpath, testElementNotLocatedByXPath, testElementLocatedById, clickElementById, clickElementByXPath, getTextByXPath, forProm} from './webdriverAccess'
2-
import {WebDriver} from 'selenium-webdriver'
2+
import {Builder, WebDriver, promise, logging} from 'selenium-webdriver'
33
import {config, FrameworkData} from './common'
44

55
export enum BenchmarkType { CPU, MEM, STARTUP };
@@ -9,8 +9,8 @@ export interface Benchmark {
99
type: BenchmarkType;
1010
label: string;
1111
description: string;
12-
init(driver: WebDriver, framework: FrameworkData) : webdriver.promise.Promise<any>;
13-
run(driver: WebDriver, framework: FrameworkData) : webdriver.promise.Promise<any>;
12+
init(driver: WebDriver, framework: FrameworkData) : promise.Promise<any>;
13+
run(driver: WebDriver, framework: FrameworkData) : promise.Promise<any>;
1414
}
1515

1616
const benchRun: Benchmark = {

webdriver-ts/src/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface JSONResult {
66

77
export let config = {
88
REPEAT_RUN: 10,
9-
DROP_WORST_RUN: 4,
9+
DROP_WORST_RUN: 0,
1010
WARMUP_COUNT: 5,
1111
TIMEOUT: 60 * 1000,
1212
LOG_PROGRESS: true,

webdriver-ts/src/nonKeyed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ function runBench(frameworkNames: string[]) {
154154
console.log("ERROR: Framework "+framework.name+" is not correctly categorized in commons.ts");
155155
}
156156
})
157-
.thenFinally(() => {driver.quit();})
157+
.then(() => {driver.quit();}, () => {driver.quit();})
158158
})
159159
}
160160

webdriver-ts/src/webdriverAccess.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as chrome from 'selenium-webdriver/chrome'
2-
import {By, until, Builder, WebDriver, Locator, promise} from 'selenium-webdriver'
2+
import {By, until, Builder, WebDriver, Locator, promise, WebElement, Condition} from 'selenium-webdriver'
33
import {config} from './common'
44

55
interface PathPart {
@@ -35,7 +35,7 @@ function convertPath(path: string): Array<PathPart> {
3535
}
3636

3737
// Fake findByXPath for simple XPath expressions to allow usage with shadow dom
38-
function findByXPath(node: webdriver.WebElement, path: string): webdriver.promise.Promise<webdriver.WebElement> {
38+
function findByXPath(node: WebElement, path: string): promise.Promise<WebElement> {
3939
// if there wasn't polymer with it's shadow dom useage one would like to use:
4040

4141
let paths = convertPath(path);
@@ -45,7 +45,7 @@ function findByXPath(node: webdriver.WebElement, path: string): webdriver.promis
4545
n = n.then(nd => nd.findElements(By.css(p.tagName+":nth-child("+(p.index)+")"))).then(elems => {
4646
if (elems==null || elems.length==0) { console.log("not found"); return null};
4747
return elems[0];
48-
}).thenCatch(e => {console.log("REJECTED PROMISE",e); return null;});
48+
}).catch(e => {console.log("REJECTED PROMISE",e); return null;});
4949
}
5050
return n;
5151

@@ -83,7 +83,7 @@ function elemNull(v: any) {
8383
// driver.findElement(By.xpath("//tbody/tr[1]/td[1]")).getText().then(...) can throw a stale element error:
8484
// thus we're using a safer way here:
8585
export function testTextContains(driver: WebDriver, xpath: string, text: string) {
86-
return driver.wait(new until.Condition<boolean>(`testTextContains ${xpath} ${text}`,
86+
return driver.wait(new Condition<boolean>(`testTextContains ${xpath} ${text}`,
8787
(driver) => shadowRoot(driver).then(elem => findByXPath(elem, xpath))
8888
.then(elem => elem==null ? elemNull(false) : elem.getText().then(
8989
v => v && v.indexOf(text)>-1,
@@ -93,7 +93,7 @@ export function testTextContains(driver: WebDriver, xpath: string, text: string)
9393
}
9494

9595
export function testTextNotContained(driver: WebDriver, xpath: string, text: string) {
96-
return driver.wait(new until.Condition<boolean>(`testTextNotContained ${xpath} ${text}`,
96+
return driver.wait(new Condition<boolean>(`testTextNotContained ${xpath} ${text}`,
9797
(driver) => shadowRoot(driver).then(elem => findByXPath(elem, xpath))
9898
.then(elem => elem==null ? elemNull(false) : elem.getText().then(
9999
v => v && v.indexOf(text)==-1,
@@ -103,7 +103,7 @@ export function testTextNotContained(driver: WebDriver, xpath: string, text: str
103103
}
104104

105105
export function testClassContains(driver: WebDriver, xpath: string, text: string) {
106-
return driver.wait(new until.Condition<boolean>(`testClassContains ${xpath} ${text}`,
106+
return driver.wait(new Condition<boolean>(`testClassContains ${xpath} ${text}`,
107107
(driver) => shadowRoot(driver).then(elem => findByXPath(elem, xpath))
108108
.then(elem => elem==null ? elemNull(false) : elem.getAttribute("class").then(
109109
v => v && v.indexOf(text)>-1,
@@ -114,7 +114,7 @@ export function testClassContains(driver: WebDriver, xpath: string, text: string
114114

115115
export function testElementLocatedByXpath(driver: WebDriver, xpath: string) {
116116
// return driver.wait(until.elementLocated(By.xpath(xpath)), 3000);
117-
return driver.wait(new until.Condition<boolean>(`testElementLocatedByXpath ${xpath}`, (driver) =>
117+
return driver.wait(new Condition<boolean>(`testElementLocatedByXpath ${xpath}`, (driver) =>
118118
shadowRoot(driver).then(elem =>
119119
elem==null ? elemNull(false) : findByXPath(elem, xpath).then(
120120
(v:any) => v,
@@ -125,23 +125,23 @@ export function testElementLocatedByXpath(driver: WebDriver, xpath: string) {
125125

126126
export function testElementNotLocatedByXPath(driver: WebDriver, xpath: string)
127127
{
128-
return driver.wait(new until.Condition<boolean>(`testElementNotLocatedByXPath ${xpath}`,
128+
return driver.wait(new Condition<boolean>(`testElementNotLocatedByXPath ${xpath}`,
129129
(driver) => shadowRoot(driver).then(elem => findByXPath(elem, xpath)).then(
130130
v => !v,
131131
err => console.log("ignoring error in testElementNotLocatedByXPath for xpath = "+xpath,err.toString().split("\n")[0]))
132132
), config.TIMEOUT);
133133
}
134134

135135
export function testElementLocatedById(driver: WebDriver, id: string) {
136-
return driver.wait(new until.Condition<boolean>(`testElementLocatedById ${id}`,
137-
(driver) => shadowRoot(driver).then(elem => elem.isElementPresent(By.id(id))).then(
136+
return driver.wait(new Condition<boolean>(`testElementLocatedById ${id}`,
137+
(driver) => shadowRoot(driver).then(elem => elem.findElement(By.id(id))).then(
138138
v => true,
139139
err => console.log("ignoring error in testElementLocatedById for id = "+id,err.toString().split("\n")[0]))
140140
)
141141
, config.TIMEOUT);
142142
}
143143

144-
function retry<T>(retryCount: number, driver: WebDriver, fun : (driver: WebDriver) => webdriver.promise.Promise<T>): webdriver.promise.Promise<T> {
144+
function retry<T>(retryCount: number, driver: WebDriver, fun : (driver: WebDriver) => promise.Promise<T>): promise.Promise<T> {
145145
return fun(driver).then(
146146
val => { return val;},
147147
err => { console.log("retry failed");
@@ -154,16 +154,16 @@ function retry<T>(retryCount: number, driver: WebDriver, fun : (driver: WebDriv
154154
);
155155
}
156156

157-
export function forPromRec(priorResults : any[], from: number, to: number, fun : (idx: number) => webdriver.promise.Promise<any>): webdriver.promise.Promise<any[]> {
157+
export function forPromRec(priorResults : any[], from: number, to: number, fun : (idx: number) => promise.Promise<any>): promise.Promise<any[]> {
158158
if (from >= to) throw "fromProm from (="+from+") >=to (="+to+")";
159159
else if (from < to-1) return fun(from).then(val => forPromRec(priorResults.concat([val]), from+1, to, fun));
160160
else return fun(from).then(val => priorResults.concat([val]));
161161
}
162162

163-
export function forProm(from: number, to: number, fun : (idx: number) => webdriver.promise.Promise<any>): webdriver.promise.Promise<any[]> {
163+
export function forProm(from: number, to: number, fun : (idx: number) => promise.Promise<any>): promise.Promise<any[]> {
164164
return forPromRec([], from, to, fun);
165165
}
166-
// export function forProm(from: number, to: number, fun : (idx: number) => webdriver.promise.Promise<any>): webdriver.promise.Promise<any[]> {
166+
// export function forProm(from: number, to: number, fun : (idx: number) => promise.Promise<any>): promise.Promise<any[]> {
167167
// let res: any[] = [];
168168
// let p = fun(from);
169169
// for (let i=from+1; i<to; i++) {
@@ -195,7 +195,7 @@ export function clickElementByXPath(driver: WebDriver, xpath: string) {
195195
// return to(driver.findElement(By.xpath(xpath)).click());
196196
}
197197

198-
export function getTextByXPath(driver: WebDriver, xpath: string): webdriver.promise.Promise<string> {
198+
export function getTextByXPath(driver: WebDriver, xpath: string): promise.Promise<string> {
199199
let count = 0;
200200
return retry(5, driver, (driver) => { count++;
201201
if (count>1 && config.LOG_DETAILS) console.log("getTextByXPath ",xpath," attempt #",count);
@@ -206,6 +206,6 @@ export function getTextByXPath(driver: WebDriver, xpath: string): webdriver.prom
206206
// return to(driver.findElement(By.xpath(xpath)).getText());
207207
}
208208

209-
function shadowRoot(driver: WebDriver) : webdriver.promise.Promise<webdriver.WebElement> {
209+
function shadowRoot(driver: WebDriver) : promise.Promise<WebElement> {
210210
return useShadowRoot ? driver.executeScript('return document.querySelector("main-element").shadowRoot') : driver.findElement(By.tagName("body"));
211211
}

webdriver-ts/table.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

webdriver-ts/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"allowJs": false
1111
},
1212
"files": [
13-
"typings/index.d.ts",
1413
"./src/common.ts",
1514
"./src/benchmarks.ts",
1615
"./src/webdriverAccess.ts",

webdriver-ts/typings.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)