Skip to content

Commit

Permalink
Merge branch 'main' into usb-power
Browse files Browse the repository at this point in the history
  • Loading branch information
gmierz authored May 28, 2024
2 parents 7347d12 + 51b5c86 commit 5a1ca80
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 15 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Browsertime changelog (we do [semantic versioning](https://semver.org))

## 22.2.0 - 2024-05-24
### Added
* New command: Mouse single click on a element with a specific id `commands.mouse.singleClick.byId(id)` and `commands.mouse.singleClick.byIdAndWait(id)` [#2135](https://github.com/sitespeedio/browsertime/pull/2135).
* New command: `commands.wait.byIdAndVisible(id, maxTime)` - wait for an element with id to become visible [#2137](https://github.com/sitespeedio/browsertime/pull/2137).

### Fixed
* Make sure errors are correctly logged if you cannot add text to element [#2136](https://github.com/sitespeedio/browsertime/pull/2136).

## 22.1.0 - 2024-05-20
### Added
* Updated to Edge and Edgedriver 125 [#2132](https://github.com/sitespeedio/browsertime/pull/2132).
Expand Down
35 changes: 30 additions & 5 deletions lib/core/engine/command/addText.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ export class AddText {
await element.clear();
return element.sendKeys(text);
} catch (error) {
log.error('Could not add text %s to id %s', text, id);
log.error(
'Could not add text %s to id %s error:%s',
text,
id,
error.message
);
log.verbose(error);
throw new Error(`Could not add text ${text} to id ${id}`);
}
Expand All @@ -57,7 +62,12 @@ export class AddText {
await element.clear();
return element.sendKeys(text);
} catch (error) {
log.error('Could not add text %s to xpath %s', text, xpath);
log.error(
'Could not add text %s to xpath %s error: %s',
text,
xpath,
error.message
);
log.verbose(error);
throw new Error(`Could not add text ${text} to xpath ${xpath}`);
}
Expand All @@ -81,7 +91,12 @@ export class AddText {
await element.clear();
return element.sendKeys(text);
} catch (error) {
log.error('Could not add text %s to selector %s', text, selector);
log.error(
'Could not add text %s to selector %s error: %s',
text,
selector,
error.message
);
log.verbose(error);
throw new Error(`Could not add text ${text} to selector ${selector}`);
}
Expand All @@ -105,7 +120,12 @@ export class AddText {
await element.clear();
return element.sendKeys(text);
} catch (error) {
log.error('Could not add text %s to class name %s', text, className);
log.error(
'Could not add text %s to class name %s error: %s',
text,
className,
error.message
);
log.verbose(error);
throw new Error(`Could not add text ${text} to class name ${className}`);
}
Expand All @@ -129,7 +149,12 @@ export class AddText {
await element.clear();
return element.sendKeys(text);
} catch (error) {
log.error('Could not add text %s to name attribute %s', text, name);
log.error(
'Could not add text %s to name attribute %s error: %s',
text,
name,
error.message
);
log.verbose(error);
throw new Error(`Could not add text ${text} to name attribute ${name}`);
}
Expand Down
41 changes: 40 additions & 1 deletion lib/core/engine/command/mouse/singleClick.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class SingleClick {

/**
* Clicks on a link whose visible text contains the given substring and waits on the
* page complete checl.
* page complete check.
*
* @async
* @param {string} text - The substring of the visible text of the link to click.
Expand All @@ -247,4 +247,43 @@ export class SingleClick {
throw new Error('Could not find link by partial text ' + text);
}
}

/**
* Clicks on a element with a specific id.
*
* @async
* @param {string} id - The id of the link to click.
* @returns {Promise<void>} A promise that resolves when the click action is performed.
* @throws {Error} Throws an error if the id is not found.
*/
async byId(id) {
try {
const element = await this.browser.getDriver().findElement(By.id(id));
return this.actions.click(element).perform();
} catch (error) {
log.error('Could not find the element with id %s', id);
log.verbose(error);
throw new Error('Could not the element with id ' + id);
}
}

/**
* Clicks on a element with a specific id and wait on the page complete check
*
* @async
* @param {string} id - The id of the link to click.
* @returns {Promise<void>} A promise that resolves when the page has completed.
* @throws {Error} Throws an error if the id is not found.
*/
async byIdAndWait(id) {
try {
const element = await this.browser.getDriver().findElement(By.id(id));
await this.actions.click(element).perform();
return this.browser.extraWait(this.pageCompleteCheck);
} catch (error) {
log.error('Could not find the element with id %s', id);
log.verbose(error);
throw new Error('Could not the element with id ' + id);
}
}
}
26 changes: 25 additions & 1 deletion lib/core/engine/command/wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class Wait {
}

/**
* Waits for an element with a specific ID to appear within a maximum time.
* Waits for an element with a specific ID to be located within a maximum time.
*
* @async
* @param {string} id - The ID of the element to wait for.
Expand All @@ -46,6 +46,30 @@ export class Wait {
}
}

/**
* Waits for an element with a specific ID to be located and visible within a maximum time.
*
* @async
* @param {string} id - The ID of the element to wait for.
* @param {number} maxTime - Maximum time to wait in milliseconds.
* @returns {Promise<void>} A promise that resolves when the element is found or the time times out.
* @throws {Error} Throws an error if the element is not found within the specified time.
*/
async byIdAndVisible(id, maxTime) {
const driver = this.browser.getDriver();
await this.byId(id, maxTime);
try {
await driver.wait(
webdriver.until.elementIsVisible(webdriver.By.id(id)),
maxTime
);
} catch (error) {
log.error('Element by id %s was not visible in %s ms', id, maxTime);
log.verbose(error);
throw new Error(`Element by id ${id} was not located in ${maxTime} ms`);
}
}

/**
* Waits for an element located by XPath to appear within a maximum time.
*
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "browsertime",
"description": "Get performance metrics from your web page using Browsertime.",
"version": "22.1.0",
"version": "22.2.0",
"bin": "./bin/browsertime.js",
"type": "module",
"types": "./types/scripting.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion types/core/engine/command/addText.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion types/core/engine/command/mouse/singleClick.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,31 @@ export class SingleClick {
byPartialLinkText(text: string): Promise<void>;
/**
* Clicks on a link whose visible text contains the given substring and waits on the
* page complete checl.
* page complete check.
*
* @async
* @param {string} text - The substring of the visible text of the link to click.
* @returns {Promise<void>} A promise that resolves when the click action is performed.
* @throws {Error} Throws an error if the link is not found.
*/
byPartialLinkTextAndWait(text: string): Promise<void>;
/**
* Clicks on a element with a specific id.
*
* @async
* @param {string} id - The id of the link to click.
* @returns {Promise<void>} A promise that resolves when the click action is performed.
* @throws {Error} Throws an error if the id is not found.
*/
byId(id: string): Promise<void>;
/**
* Clicks on a element with a specific id and wait on the page complete check
*
* @async
* @param {string} id - The id of the link to click.
* @returns {Promise<void>} A promise that resolves when the page has completed.
* @throws {Error} Throws an error if the id is not found.
*/
byIdAndWait(id: string): Promise<void>;
}
//# sourceMappingURL=singleClick.d.ts.map
2 changes: 1 addition & 1 deletion types/core/engine/command/mouse/singleClick.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion types/core/engine/command/wait.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Wait {
*/
private pageCompleteCheck;
/**
* Waits for an element with a specific ID to appear within a maximum time.
* Waits for an element with a specific ID to be located within a maximum time.
*
* @async
* @param {string} id - The ID of the element to wait for.
Expand All @@ -24,6 +24,16 @@ export class Wait {
* @throws {Error} Throws an error if the element is not found within the specified time.
*/
byId(id: string, maxTime: number): Promise<void>;
/**
* Waits for an element with a specific ID to be located and visible within a maximum time.
*
* @async
* @param {string} id - The ID of the element to wait for.
* @param {number} maxTime - Maximum time to wait in milliseconds.
* @returns {Promise<void>} A promise that resolves when the element is found or the time times out.
* @throws {Error} Throws an error if the element is not found within the specified time.
*/
byIdAndVisible(id: string, maxTime: number): Promise<void>;
/**
* Waits for an element located by XPath to appear within a maximum time.
*
Expand Down
2 changes: 1 addition & 1 deletion types/core/engine/command/wait.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5a1ca80

Please sign in to comment.