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

docu: update locators #148

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/usage/locators.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,28 @@ element(by.control({
}
}));
```
### Common usecases

#### Working with responsive toolbars
A responsive toolbar may have overflowing content, depending on the screen size.
This content will be moved to a popover which is open by pressing a toggle button in the toolbar.
A toggle button will be shown only when there is overflowing content. This is a problem for tests because they should only try to press the button when it's visible and interactable. One way to solve this is to always start the application under test with with a fixed screen size. Another way is to first look for any toggle button - with no restriction on visibility, and then press on it only if it exists:
```javascript
var button = element(by.control({
Copy link
Contributor

Choose a reason for hiding this comment

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

have you tested this (why not add а test) ? IMHO this won't work because we have an implicit visible: true selector and so button will be null in case the toggle button is not displayed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tested

controlType: "sap.m.ToggleButton",
ancestor: {
viewNamespace: "appUnderTest.view.",
viewName : "Main",
id: "toolbar-overflow"
}
}));

button.isPresent().then(function (isPresent) {
if (isPresent) {
button.click();
}
});
```

## DOM Locators
All standart `by.` locators from [WebDriverJs](https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_By.html) are supported.
Expand Down
75 changes: 70 additions & 5 deletions e2e/browser/fixture/apps/browser/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module.exports = {
search.attachSearch(function (oEvent) {
searchQuery.setText(oEvent.getSource().getValue());
});

var page1 = new sap.m.Page("page1", {
title: "Page 1",
content : [
Expand Down Expand Up @@ -50,11 +49,77 @@ module.exports = {
new sap.m.Button({
id : "hide-nav-btn",
text : "hide Nav Button",
press : function() {
page1.setShowNavButton(false);
}
press : function() {
page1.setShowNavButton(false);
}
}),
searchQuery,
new sap.m.OverflowToolbar({
id: "toolbar-fit",
width: "600px",
content: [
new sap.m.Button({
text: "Always Visible",
press: "onToolbarButtonPress",
layoutData: [
new sap.m.OverflowToolbarLayoutData({
priority: "NeverOverflow"
})
]
}),
new sap.m.Button({
text: "Mostly Visible",
press: "onToolbarButtonPress",
layoutData: [
new sap.m.OverflowToolbarLayoutData({
priority: "High"
})
]
}),
new sap.m.Button({
text: "Should Overflow",
press: "onToolbarButtonPress",
layoutData: [
new sap.m.OverflowToolbarLayoutData({
priority: "Low"
})
]
})
]
}),
new sap.m.OverflowToolbar({
id: "toolbar-overflow",
width: "300px",
content: [
new sap.m.Button({
text: "Always Visible",
press: "onToolbarButtonPress",
layoutData: [
new sap.m.OverflowToolbarLayoutData({
priority: "NeverOverflow"
})
]
}),
new sap.m.Button({
text: "Mostly Visible",
press: "onToolbarButtonPress",
layoutData: [
new sap.m.OverflowToolbarLayoutData({
priority: "High"
})
]
}),
searchQuery
new sap.m.Button({
text: "Overflowing",
press: "onToolbarButtonPress",
layoutData: [
new sap.m.OverflowToolbarLayoutData({
priority: "Low"
})
]
})
]
})
],
subHeader: new sap.m.Bar({
contentMiddle: [search]
Expand Down
46 changes: 45 additions & 1 deletion e2e/browser/specs/by_control.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,49 @@ describe("by_control", function () {
}));

expect(list.getAttribute("id")).toContain("ListPage1");
})
});

it("should interact with overflow toolbars", function () {
var presentToggleButton = element(by.control({
controlType: "sap.m.ToggleButton",
ancestor: {
id: "toolbar-overflow"
},
visible: false
}));
var overflowingButton = element(by.control({
controlType: "sap.m.Button",
properties: {
text: "Overflowing"
}
}));

presentToggleButton.isPresent().then(function (isPresent) {
if (isPresent) {
presentToggleButton.click();
}
});

// toggle button should be pressed and overflowing buttons should be shown
expect(overflowingButton.isPresent()).toBeTruthy();

var hiddenToggleButton = element(by.css("#toolbar-fit button[title='More']"));
var toolbarButton = element(by.control({
controlType: "sap.m.Button",
properties: {
text: "Always Visible"
}
}));

hiddenToggleButton.isPresent().then(function (isPresent) {
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO:

  1. try with isDisplayed,isEnabled
  2. try with executeScript and jq inside the browser => export as some helper on browser object

if (isPresent) {
// should not get here as the button is not present
hiddenToggleButton.click();
}
});

// toggle button should not be visible and therefore not pressed. non-overflowing buttons should be shown
expect(toolbarButton.isPresent()).toBeTruthy();

});
});