Skip to content

Commit d46b249

Browse files
committed
refactored webdriver-ts DOM access and remove benchmark
1 parent 362ffe7 commit d46b249

File tree

3 files changed

+52
-23
lines changed

3 files changed

+52
-23
lines changed

webdriver-ts/src/benchmarkRunner.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,17 @@ function buildDriver() {
7373
}
7474

7575
function reduceBenchmarkResults(benchmark: Benchmark, results: Timingresult[][]): number[] {
76-
if (config.LOG_DETAILS) console.log("data for reduceBenchmarkResults", results);
7776
if (benchmark.type === BenchmarkType.CPU) {
77+
if (results.some(val => val[0]==null || val[1]==null)) {
78+
console.log("data for CPU reduceBenchmarkResults", results);
79+
throw `Data wasn't extracted from timeline as expected for ${benchmark.id}. Make sure that your browser was window all the time the benchmark was running!`;
80+
}
7881
return results.reduce((acc: number[], val: Timingresult[]): number[] => acc.concat((val[1].end - val[0].ts)/1000.0), []);
7982
} else {
83+
if (results.some(val => val[2]==null)) {
84+
console.log("data for MEM reduceBenchmarkResults", results);
85+
throw `Data wasn't extracted from timeline as expected for ${benchmark.id}. Make sure that your browser was window all the time the benchmark was running!`;
86+
}
8087
return results.reduce((acc: number[], val: Timingresult[]): number[] => acc.concat([val[2].mem]), []);
8188
}
8289
}
@@ -158,6 +165,17 @@ function runBench(frameworkNames: string[], benchmarkNames: string[], dir: strin
158165
.then(() => initBenchmark(driver, benchmark, framework.name))
159166
.then(() => clearLogs(driver))
160167
.then(() => runBenchmark(driver, benchmark, framework.name))
168+
.thenCatch((e) => {
169+
console.error("Benchmark failed",e);
170+
driver.takeScreenshot().then(
171+
function(image) {
172+
require('fs').writeFileSync('error-'+framework+'-'+benchmark.id+'.png', image, 'base64', function(err:any) {
173+
console.log(err);
174+
});
175+
throw e;
176+
}
177+
);
178+
});
161179
})
162180
.then(results => reduceBenchmarkResults(benchmark, results))
163181
.then(results => {

webdriver-ts/src/benchmarks.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,18 @@ const benchRemove: Benchmark = {
101101
.then(() => clickElementById(driver, 'run'))
102102
.then(() => testElementLocatedByXpath(driver, "//tbody/tr[1]/td[2]/a"))
103103
.then(() => forProm(0, config.WARMUP_COUNT, (i) => {
104-
let text = '';
105-
return getTextByXPath(driver, `//tbody/tr[${config.WARMUP_COUNT-i+4}]/td[2]/a`)
106-
.then(val => text = val )
104+
return testTextContains(driver, `//tbody/tr[${config.WARMUP_COUNT-i+4}]/td[1]`, (config.WARMUP_COUNT-i+4).toString())
107105
.then(() => clickElementByXPath(driver, `//tbody/tr[${config.WARMUP_COUNT-i+4}]/td[3]/a/span[1]`))
108-
.then(() => testTextNotContained(driver, `//tbody/tr[${config.WARMUP_COUNT-i+4}]/td[2]/a`, text));
109-
// return clickElementByXPath(driver, `//tbody/tr[${config.WARMUP_COUNT-i+4}]/td[3]/a`)
110-
}
111-
)),
106+
.then(() => testTextContains(driver, `//tbody/tr[${config.WARMUP_COUNT-i+4}]/td[1]`, '10'));
107+
}))
108+
.then(() =>
109+
testTextContains(driver, '//tbody/tr[5]/td[1]', '10')
110+
.then(() => testTextContains(driver, '//tbody/tr[4]/td[1]', '4'))
111+
),
112112
run: (driver: WebDriver) => {
113-
let text = '';
114-
return getTextByXPath(driver, "//tbody/tr[4]/td[2]/a")
115-
.then(val => text = val)
116-
.then(() => clickElementByXPath(driver, "//tbody/tr[4]/td[3]/a/span[1]"))
117-
.then(() => testTextNotContained(driver, "//tbody/tr[4]/td[2]/a", text));
113+
let text = '';
114+
return clickElementByXPath(driver, "//tbody/tr[4]/td[3]/a/span[1]")
115+
.then(() => testTextContains(driver, '//tbody/tr[4]/td[1]', '10'));
118116
}
119117
}
120118

webdriver-ts/src/webdriverAccess.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,30 @@ function convertPath(path: string): Array<PathPart> {
3737
// Fake findByXPath for simple XPath expressions to allow usage with shadow dom
3838
function findByXPath(node: webdriver.WebElement, path: string): webdriver.promise.Promise<webdriver.WebElement> {
3939
// if there wasn't polymer with it's shadow dom useage one would like to use:
40-
// return node.findElement(By.xpath(path));
41-
let paths = convertPath(path);
42-
let n = promise.fulfilled(node);
43-
for (let p of paths) {
44-
// n = n.then(nd => nd.findElements(By.tagName(p.tagName))).then(elems => { // costly since it fetches all elements
45-
n = n.then(nd => nd.findElements(By.css(p.tagName+":nth-child("+(p.index)+")"))).then(elems => {
46-
if (elems.length==0) { console.log("not found"); return null}; //throw "Element not found "+p.tagName+"["+p.index+"]";
47-
return elems[0];
48-
});
40+
if (!useShadowRoot) {
41+
return node.findElements(By.xpath(path)).then(nodes => {
42+
if (nodes.length === 0) {
43+
return null;
44+
} else {
45+
return nodes[0];
46+
}
47+
})
48+
} else {
49+
let paths = convertPath(path);
50+
let n = promise.fulfilled(node);
51+
for (let p of paths) {
52+
n = n.then(nd => nd.findElements(By.tagName(p.tagName))).then(elems => { // costly since it fetches all elements
53+
if (elems.length < p.index) { console.log("not found"); return null}; //throw "Element not found "+p.tagName+"["+p.index+"]";
54+
return elems[p.index-1];
55+
});
56+
// n = n.then(nd => nd.findElements(By.css(p.tagName+":nth-child("+(p.index)+")"))).then(elems => {
57+
// console.log("*", elems.length);
58+
// if (elems.length==0) { console.log("not found"); return null}; //throw "Element not found "+p.tagName+"["+p.index+"]";
59+
// return elems[0];
60+
// });
61+
}
62+
return n;
4963
}
50-
return n;
5164
}
5265

5366
// driver.findElement(By.xpath("//tbody/tr[1]/td[1]")).getText().then(...) can throw a stale element error:

0 commit comments

Comments
 (0)