Skip to content

Commit ca6a69f

Browse files
committed
Merge branch 'master' of github.com:krausest/js-framework-benchmark
2 parents 198a67f + a487f25 commit ca6a69f

File tree

8 files changed

+96
-105
lines changed

8 files changed

+96
-105
lines changed

webdriver-ts-results/src/results.ts

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

webdriver-ts-results/table.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

webdriver-ts/results.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

webdriver-ts/src/benchmarkRunner.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,16 @@ if (process.env.HOST) {
284284
async function main() {
285285
let runBenchmarksArgs: string[] = (args.benchmark && args.benchmark.length > 0) ? args.benchmark : [""];
286286
let runBenchmarks: Array<BenchmarkInfo> = benchmarkInfos.filter((b) =>
287+
// afterframe currently only targets CPU benchmarks
288+
(config.BENCHMARK_RUNNER !== BENCHMARK_RUNNER.WEBDRIVER_AFTERFRAME || b.type == BenchmarkType.CPU) &&
287289
runBenchmarksArgs.some((name) => b.id.toLowerCase().indexOf(name) > -1)
288290
);
289291

290292

291293
let runFrameworks: FrameworkData[];
292294
let matchesDirectoryArg = (directoryName: string) =>
293295
frameworkArgument.length == 0 || frameworkArgument.some((arg: string) => arg == directoryName);
294-
runFrameworks = await initializeFrameworks(matchesDirectoryArg);
296+
runFrameworks = (await initializeFrameworks(matchesDirectoryArg)).filter(f => f.keyed || config.BENCHMARK_RUNNER !== BENCHMARK_RUNNER.WEBDRIVER_AFTERFRAME);
295297

296298
console.log("ARGS.smotest", args.smoketest)
297299
if (args.smoketest) {

webdriver-ts/src/benchmarksWebdriverAfterframe.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { config, FrameworkData } from "./common.js";
55
import {
66
clickElementById,
77
clickElementByXPath,
8+
findById,
89
findByXPath,
910
getTextByXPath, mainRoot, retry, testClassContains, testElementLocatedById, testElementLocatedByXpath,
1011
testElementNotLocatedByXPath, testTextContains
@@ -92,15 +93,15 @@ async function measureClickForElement(driver: WebDriver, elem: WebElement) {
9293
}
9394

9495
async function measureClickElementById(driver: WebDriver, id: string, isInButtonArea: boolean) {
95-
let elem = await mainRoot(driver, isInButtonArea);
96-
elem = await elem.findElement(By.id(id));
97-
measureClickForElement(driver, elem);
96+
let elem = await findById(driver, id, isInButtonArea);
97+
console.log("measureClickElementById: ", elem);
98+
await measureClickForElement(driver, elem);
9899
}
99100

100101
async function measureClickElementByXPath(driver: WebDriver, xpath: string, isInButtonArea: boolean) {
101102
let elem = await findByXPath(driver, xpath, isInButtonArea);
102103
if (!elem) throw `measureClickElementById ${xpath} failed. Element was not found.`;
103-
measureClickForElement(driver, elem);
104+
await measureClickForElement(driver, elem);
104105
}
105106

106107

webdriver-ts/src/forkedBenchmarkRunnerWebdriver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { BenchmarkType, DurationMeasurementMode } from "./benchmarksCommon.js";
99
let config: TConfig = defaultConfig;
1010

1111
// necessary to launch without specifiying a path
12-
require("chromedriver");
12+
import "chromedriver";
1313

1414
interface Timingresult {
1515
type: string;

webdriver-ts/src/forkedBenchmarkRunnerWebdriverAfterframe.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,33 @@ async function runCPUBenchmark(
5454
console.log("benchmarking ", framework, benchmark.benchmarkInfo.id);
5555
let driver: WebDriver = null;
5656
try {
57+
// let driver = buildDriver(benchmarkOptions);
5758
let driver = await new Builder()
5859
.forBrowser(benchmarkOptions.browser)
5960
.build();
61+
console.log(`using afterframe measurement with ${benchmarkOptions.browser}`)
6062
await driver.manage().window().maximize();
6163

6264
for (let i = 0; i < benchmarkOptions.batchSize; i++) {
6365
setUseShadowRoot(framework.useShadowRoot);
6466
setUseRowShadowRoot(framework.useRowShadowRoot);
6567
setShadowRootName(framework.shadowRootName);
6668
setButtonsInShadowRoot(framework.buttonsInShadowRoot);
69+
console.log("runCPUBenchmark: before loading page")
6770
// must be run with an IP adress otherwise Safari crashes with an error.
6871
// Use the HOST env variable to set the HOST to an IP adress for safari!
6972
await driver.get(`http://${benchmarkOptions.HOST}:${benchmarkOptions.port}/${framework.uri}/index.html`);
73+
// Needed for Firefox
74+
await driver.sleep(50);
75+
console.log("runCPUBenchmark: initBenchmark")
7076
await initBenchmark(driver, benchmark, framework);
77+
console.log("runCPUBenchmark: runBenchmark")
7178
await runBenchmark(driver, benchmark, framework);
79+
console.log("runCPUBenchmark: getAfterframeDurations")
7280
results.push(...getAfterframeDurations());
81+
console.log("runCPUBenchmark: loop end")
7382
}
74-
console.log("quit");
83+
console.log("runCPUBenchmark: driver.quit");
7584
await driver.quit();
7685
return { error, warnings, result: results };
7786
} catch (e) {

webdriver-ts/src/webdriverAccess.ts

Lines changed: 39 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ export function setButtonsInShadowRoot(val: boolean) {
2828
buttonsInShadowRoot = val;
2929
}
3030

31-
function convertPath(path: string): Array<PathPart> {
31+
function convertPath(path: string): string {
3232
let parts = path.split(/\//).filter((v) => !!v);
33-
let res: Array<PathPart> = [];
33+
let res = [];
3434
for (let part of parts) {
3535
let components = part.split(/\[|]/).filter((v) => !!v);
3636
let tagName = components[0];
@@ -44,54 +44,29 @@ function convertPath(path: string): Array<PathPart> {
4444
} else {
4545
index = 1;
4646
}
47-
res.push({ tagName, index });
47+
res.push(`${tagName}:nth-of-type(${index})`);
4848
}
49-
return res;
49+
return res.join(" ");
5050
}
5151

52-
async function shadowRoot(driver: WebDriver, selector: string): Promise<WebElement> {
53-
const el = await driver.findElement(By.css(selector));
54-
return driver.executeScript(`return arguments[0].shadowRoot`, el);
52+
export async function findById(driver: WebDriver, id: string, isInButtonArea: boolean): Promise<WebElement>
53+
{
54+
let root= mainRoot(driver, isInButtonArea);
55+
if (config.LOG_DEBUG) console.log("findById selector ", `${root}.querySelector('#${id}')`);
56+
return await (driver.executeScript(`return ${root}.querySelector('#${id}')`) as Promise<WebElement>)
5557
}
5658

5759
// Fake findByXPath for simple XPath expressions to allow usage with shadow dom
5860
export async function findByXPath(driver: WebDriver, path: string, isInButtonArea: boolean): Promise<WebElement> {
59-
let root = await mainRoot(driver, isInButtonArea);
6061
let paths = convertPath(path);
61-
let n = root;
62+
let root = mainRoot(driver, isInButtonArea);
6263
try {
63-
for (let p of paths) {
64-
let elem;
65-
if (useRowShadowRoot && p.tagName === "tr") {
66-
try {
67-
const shadowHost = await shadowRoot(driver, `benchmark-row:nth-of-type(${p.index})`);
68-
elem = await shadowHost.findElement(By.tagName("tr"));
69-
if (elem === null) {
70-
return null;
71-
}
72-
} catch (err) {
73-
return null;
74-
}
75-
} else {
76-
let elems = await n.findElements(By.css(p.tagName + ":nth-of-type(" + p.index + ")"));
77-
if (elems == null || elems.length == 0) {
78-
return null;
79-
}
80-
elem = elems[0];
81-
}
82-
83-
n = elem;
84-
}
64+
if (config.LOG_DEBUG) console.log("findByXPath: selector = ", `return ${root}.querySelector('${paths}')`);
65+
return await driver.executeScript(`return ${root}.querySelector('${paths}')`)
8566
} catch (e) {
8667
//can happen for StaleElementReferenceError
8768
return null;
8869
}
89-
return n;
90-
}
91-
92-
function elemNull(v: any) {
93-
console.log("*** ELEMENT WAS NULL");
94-
return false;
9570
}
9671

9772
function waitForCondition(driver: WebDriver) {
@@ -107,6 +82,7 @@ export async function testTextContains(driver: WebDriver, xpath: string, text: s
10782
`testTextContains ${xpath} ${text}`,
10883
async function (driver) {
10984
try {
85+
if (config.LOG_DEBUG) console.log("testTextContains", xpath);
11086
let elem = await findByXPath(driver, xpath, isInButtonArea);
11187
if (elem == null) return false;
11288
let v = await elem.getText();
@@ -119,8 +95,8 @@ export async function testTextContains(driver: WebDriver, xpath: string, text: s
11995
);
12096
}
12197

122-
export function testTextNotContained(driver: WebDriver, xpath: string, text: string, timeout = config.TIMEOUT, isInButtonArea: boolean) {
123-
return waitForCondition(driver)(
98+
export async function testTextNotContained(driver: WebDriver, xpath: string, text: string, timeout = config.TIMEOUT, isInButtonArea: boolean) {
99+
return await waitForCondition(driver)(
124100
`testTextNotContained ${xpath} ${text}`,
125101
async function (driver) {
126102
try {
@@ -136,8 +112,8 @@ export function testTextNotContained(driver: WebDriver, xpath: string, text: str
136112
);
137113
}
138114

139-
export function testClassContains(driver: WebDriver, xpath: string, text: string, timeout = config.TIMEOUT, isInButtonArea: boolean) {
140-
return waitForCondition(driver)(
115+
export async function testClassContains(driver: WebDriver, xpath: string, text: string, timeout = config.TIMEOUT, isInButtonArea: boolean) {
116+
return await waitForCondition(driver)(
141117
`testClassContains ${xpath} ${text}`,
142118
async function (driver) {
143119
try {
@@ -153,8 +129,8 @@ export function testClassContains(driver: WebDriver, xpath: string, text: string
153129
);
154130
}
155131

156-
export function testElementLocatedByXpath(driver: WebDriver, xpath: string, timeout = config.TIMEOUT, isInButtonArea: boolean) {
157-
return waitForCondition(driver)(
132+
export async function testElementLocatedByXpath(driver: WebDriver, xpath: string, timeout = config.TIMEOUT, isInButtonArea: boolean) {
133+
return await waitForCondition(driver)(
158134
`testElementLocatedByXpath ${xpath}`,
159135
async function (driver) {
160136
try {
@@ -168,12 +144,13 @@ export function testElementLocatedByXpath(driver: WebDriver, xpath: string, time
168144
);
169145
}
170146

171-
export function testElementNotLocatedByXPath(driver: WebDriver, xpath: string, timeout = config.TIMEOUT, isInButtonArea: boolean) {
172-
return waitForCondition(driver)(
147+
export async function testElementNotLocatedByXPath(driver: WebDriver, xpath: string, timeout = config.TIMEOUT, isInButtonArea: boolean) {
148+
return await waitForCondition(driver)(
173149
`testElementNotLocatedByXPath ${xpath}`,
174150
async function (driver) {
175151
try {
176152
let elem = await findByXPath(driver, xpath, isInButtonArea);
153+
if (config.LOG_DEBUG) console.log("testElementNotLocatedByXPath", xpath, elem);
177154
return elem ? false : true;
178155
} catch (err) {
179156
console.log("ignoring error in testElementNotLocatedByXPath for xpath = " + xpath, err.toString().split("\n")[0]);
@@ -183,14 +160,15 @@ export function testElementNotLocatedByXPath(driver: WebDriver, xpath: string, t
183160
);
184161
}
185162

186-
export function testElementLocatedById(driver: WebDriver, id: string, timeout = config.TIMEOUT, isInButtonArea: boolean) {
187-
return waitForCondition(driver)(
163+
export async function testElementLocatedById(driver: WebDriver, id: string, timeout = config.TIMEOUT, isInButtonArea: boolean) {
164+
return await waitForCondition(driver)(
188165
`testElementLocatedById ${id}`,
189166
async function (driver) {
190167
try {
191-
let elem = await mainRoot(driver, isInButtonArea);
192-
elem = await elem.findElement(By.id(id));
193-
return true;
168+
let root= mainRoot(driver, isInButtonArea);
169+
if (config.LOG_DEBUG) console.log("testElementLocatedById selector ",`return ${root}.querySelector('#${id}')`);
170+
let elem = await driver.executeScript(`return ${root}.querySelector('#${id}')`)
171+
return !!elem;
194172
} catch (err) {
195173
// console.log("ignoring error in testElementLocatedById for id = "+id,err.toString().split("\n")[0]);
196174
}
@@ -212,16 +190,16 @@ export async function retry<T>(retryCount: number, driver: WebDriver, fun: (driv
212190

213191
// Stale element prevention. For aurelia even after a testElementLocatedById clickElementById for the same id can fail
214192
// No idea how that can be explained
215-
export function clickElementById(driver: WebDriver, id: string, isInButtonArea: boolean) {
216-
return retry(5, driver, async function (driver) {
217-
let elem = await mainRoot(driver, isInButtonArea);
218-
elem = await elem.findElement(By.id(id));
193+
export async function clickElementById(driver: WebDriver, id: string, isInButtonArea: boolean) {
194+
return await retry(5, driver, async function (driver) {
195+
let elem = await findById(driver, id, isInButtonArea);
196+
if (config.LOG_DEBUG) console.log("clickElementById: ", elem);
219197
await elem.click();
220198
});
221199
}
222200

223-
export function clickElementByXPath(driver: WebDriver, xpath: string, isInButtonArea: boolean) {
224-
return retry(5, driver, async function (driver, count) {
201+
export async function clickElementByXPath(driver: WebDriver, xpath: string, isInButtonArea: boolean) {
202+
return await retry(5, driver, async function (driver, count) {
225203
if (count > 1 && config.LOG_DETAILS) console.log("clickElementByXPath ", xpath, " attempt #", count);
226204
let elem = await findByXPath(driver, xpath, isInButtonArea);
227205
await elem.click();
@@ -238,15 +216,15 @@ export async function getTextByXPath(driver: WebDriver, xpath: string, isInButto
238216
});
239217
}
240218

241-
export async function mainRoot(driver: WebDriver, isInButtonArea: boolean): Promise<WebElement> {
219+
export function mainRoot(driver: WebDriver, isInButtonArea: boolean): string {
242220
if (useShadowRoot) {
243221
if (!buttonsInShadowRoot && isInButtonArea) {
244-
return await driver.findElement(By.tagName("body"));
222+
return "document.querySelector('body')";
245223
} else {
246-
return shadowRoot(driver, shadowRootName);
224+
return `document.querySelector('${shadowRootName}').shadowRoot`
247225
}
248226
} else {
249-
return driver.findElement(By.tagName("body"));
227+
return "document.querySelector('body')"
250228
}
251229
}
252230

@@ -259,6 +237,7 @@ export function buildDriver(benchmarkOptions: BenchmarkDriverOptions): WebDriver
259237
let args = [
260238
"--js-flags=--expose-gc",
261239
"--enable-precise-memory-info",
240+
"--flag-switches-begin","--enable-zero-copy","--enable-features=RawDraw","--flag-switches-end",
262241
// "--enable-gpu-rasterization",
263242
"--no-first-run",
264243
"--disable-background-networking",

0 commit comments

Comments
 (0)