Skip to content

Commit

Permalink
feat: add elementStatus (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuineng authored Sep 14, 2023
1 parent cadba4b commit 4d75567
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ controllers.setFrame = async function(frame) {
logger.debug(`Entering into web frame: '${result.WINDOW}'`);
this.frame = result.WINDOW;
return null;

};

/**
Expand All @@ -182,6 +181,14 @@ controllers.setFrame = async function(frame) {
*/
controllers.click = async function(elementId) {
const element = this.elements[elementId];
if (!element) {
logger.error('click Element is not found');
return null;
}
if (!element.isVisible()) {
logger.error('click Element is not visible');
return null;
}
await element.click({
timeout: 1E3,
});
Expand Down
16 changes: 16 additions & 0 deletions lib/next-actions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const logger = require('./logger');
const nextActions = {};

nextActions.fileChooser = async function(filePath) {
Expand All @@ -16,4 +17,19 @@ nextActions.mouse = async function({ type, args }) {
return true;
};

nextActions.elementStatus = async function(elementId) {
const element = this.elements[elementId];
if (!element) {
logger.error('click Element is not found');
return null;
}
return {
disabled: await element.isDisabled(),
editable: await element.isEditable(),
enabled: await element.isEnabled(),
hidden: await element.isHidden(),
visible: await element.isVisible(),
};
};

module.exports = nextActions;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "macaca-playwright",
"version": "1.9.1",
"version": "1.9.2",
"description": "Macaca Playwright driver",
"keywords": [
"playwright",
Expand Down
10 changes: 10 additions & 0 deletions test/macaca-playwright.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ describe('test/macaca-playwright.test.js', function() {
assert.equal(res, true);
});

it('elementStatus', async () => {
const button = await driver.findElement('id', 'input');
res = await driver.elementStatus(button.ELEMENT);
assert(res.disabled === false);
assert(res.editable === true);
assert(res.enabled === true);
assert(res.hidden === false);
assert(res.visible === true);
});

it('getRect', async () => {
const button = await driver.findElement('id', 'input');
res = await driver.getRect(button.ELEMENT);
Expand Down

0 comments on commit 4d75567

Please sign in to comment.