Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable special characters in UI5 control ids #159

Merged
merged 9 commits into from
Mar 4, 2022
39 changes: 39 additions & 0 deletions examples/ui5-js-app/webapp/test/e2e/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,43 @@ describe("ui5 basic", () => {
const title = await browser.getTitle()
expect(title).toEqual("Sample UI5 Application")
})

// #118
it('should use a control selector with dots and colons', async () => {
const selector = {
selector: {
id: 'Title::NoAction.h1',
viewName: "test.Sample.view.Main"
}
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please apply prettier formatting on the file :)


// ui5
const titleWUi5 = await browser.asControl(selector).getText();

// working webdriver example with xpath id selector
const titleElement = await $('//*[@id="container-Sample---Main--Title::NoAction.h1"]');
const titleWwdio = await titleElement.getText();

expect(titleWUi5).toEqual('UI5 demo');
expect(titleWwdio).toEqual('UI5 demo');
});

it.only('check for invalid control selector', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm .only

const selector1 = {
selector_: {
test: "some.test.string"
}
};

const selector2 = {
id: "some.test.string"
};

const invalidControl1 = await browser.asControl(selector1)
const invalidControl2 = await browser.asControl(selector2)

expect(invalidControl1).toEqual("specified selector is not valid -> abort")
expect(invalidControl2).toEqual("specified selector is not valid -> abort")

});
})
1 change: 1 addition & 0 deletions examples/ui5-js-app/webapp/view/Main.view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
justifyContent="Center"
height="100%">
<Title level="H1"
id="Title::NoAction.h1"
titleStyle="H1"
text="{i18n>startPage.title.text}"
width="100%"
Expand Down
14 changes: 14 additions & 0 deletions src/lib/wdi5-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ function _createWdioUI5KeyFromSelector(selector: wdi5Selector): string {

export async function addWdi5Commands() {
browser.addCommand("_asControl", async (wdi5Selector: wdi5Selector) => {
if (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i suggest to outsource this in a separate function.

  1. there will be more conditional checks in the future (e.g. controlType && viewName OR only id)
  2. we should be more specific with the error, e.g. selector is missing the "selector" object

!(
wdi5Selector.hasOwnProperty("selector") &&
(wdi5Selector.selector.hasOwnProperty("id") ||
wdi5Selector.selector.hasOwnProperty("viewName") ||
wdi5Selector.selector.hasOwnProperty("bindingPath") ||
wdi5Selector.selector.hasOwnProperty("controlType") ||
wdi5Selector.selector.hasOwnProperty("properties"))
)
) {
Logger.error("specified selector is not valid -> abort")
return "specified selector is not valid -> abort"
}

const internalKey = wdi5Selector.wdio_ui5_key || _createWdioUI5KeyFromSelector(wdi5Selector)
// either retrieve and cache a UI5 control
// or return a cached version
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wdi5-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export class WDI5Control {
// save the webdriver representation by control id
if (result[2]) {
// only if the result is valid
this._webdriverRepresentation = await $(`#${result[2]}`)
this._webdriverRepresentation = await $(`//*[@id="${result[2]}"]`)
}

this.writeResultLog(result, "getControl()")
Expand Down