Skip to content

Commit

Permalink
adjust the element and implementations to work for mobile breadcrumb
Browse files Browse the repository at this point in the history
  • Loading branch information
jasson99 committed Sep 22, 2021
1 parent f9efcb0 commit ec404ec
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 44 deletions.
11 changes: 6 additions & 5 deletions tests/acceptance/features/webUIFiles/breadcrumb.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ Feature: access breadcrumb
And user "Alice" has logged in using the webUI
When the user opens folder "simple-folder" using the webUI
And the user opens folder "subfolder" using the webUI
Then clickable breadcrumb for folder "simple-folder" should be displayed on the webUI
And non-clickable breadcrumb for folder "subfolder" should be displayed on the webUI
Then breadcrumb for folder "simple-folder" should be displayed on the webUI
And breadcrumb for folder "subfolder" should be displayed on the webUI
And non-clickable breadcrumb for folder "subfolder" should be present on the webUI


Scenario: Select breadcrumb inside folder with problematic name
Expand All @@ -35,15 +36,15 @@ Feature: access breadcrumb
Then no message should be displayed on the webUI



Scenario: breadcrumb for double quotes
Given user "Alice" has created folder "\'single-double quotes\""
And user "Alice" has created folder "\'single-double quotes\"/\"inner\" double quotes"
And user "Alice" has logged in using the webUI
When the user opens folder "\'single-double quotes\"" using the webUI
And the user opens folder "\"inner\" double quotes" using the webUI
Then clickable breadcrumb for folder "\'single-double quotes\"" should be displayed on the webUI
And non-clickable breadcrumb for folder "\"inner\" double quotes" should be displayed on the webUI
Then breadcrumb for folder "\'single-double quotes\"" should be displayed on the webUI
And breadcrumb for folder "\"inner\" double quotes" should be displayed on the webUI
And non-clickable breadcrumb for folder "\"inner\" double quotes" should be present on the webUI


Scenario: Check breadCrumb for home folder
Expand Down
26 changes: 5 additions & 21 deletions tests/acceptance/pageObjects/personalPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = {
* @param {string} resource
*/
navigateToBreadcrumb: function(resource) {
const breadcrumbElement = this.elements.resourceBreadcrumbClickable
const breadcrumbElement = this.elements.resourceBreadcrumb
const resourceXpath = util.format(
breadcrumbElement.selector,
xpathHelper.buildXpathLiteral(resource)
Expand All @@ -53,29 +53,13 @@ module.exports = {
* @returns {null|{locateStrategy: string, selector: string}}
*/
getBreadcrumbSelector: function(clickable, nonClickable) {
if (clickable && nonClickable) {
if (clickable) {
return this.elements.resourceBreadcrumb
} else if (clickable) {
return this.elements.resourceBreadcrumbClickable
} else if (nonClickable) {
return this.elements.resourceBreadcrumbNonClickable
}
return null
},
/**
* Check if the breadcrumb element is visible or not
*
* @returns Promise
*/
checkBreadcrumbVisibility: async function(resourceBreadcrumbXpath) {
await this.useXpath()
.waitForElementVisible({
selector: resourceBreadcrumbXpath,
abortOnFailure: false
})
.useCss()
return this
},
/**
* Create a folder with the given name
*
Expand Down Expand Up @@ -369,12 +353,12 @@ module.exports = {
selector: '//span[@class="oc-breadcrumb-drop-label-text" and text()=%s]',
locateStrategy: 'xpath'
},
resourceBreadcrumb: {
breadcrumbMobileReferencedToOpenSidebarButton: {
selector:
'//nav[@id="files-breadcrumb"]//*[(self::a or self::span or self::button) and contains(text(),%s)]',
'//button[@aria-label="Open sidebar to view details"]/ancestor::div//span[@class="oc-breadcrumb-drop-label-text" and text()=%s]',
locateStrategy: 'xpath'
},
resourceBreadcrumbClickable: {
resourceBreadcrumb: {
selector:
'//nav[@id="files-breadcrumb"]//*[(self::a or self::button) and contains(text(),%s)]',
locateStrategy: 'xpath'
Expand Down
94 changes: 76 additions & 18 deletions tests/acceptance/stepDefinitions/filesContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,10 @@ Then('there should be no breadcrumb displayed on the webUI', function() {
return assertBreadCrumbIsNotDisplayed()
})

Then('non-clickable breadcrumb for folder {string} should be displayed on the webUI', function(
Then('non-clickable breadcrumb for folder {string} should be present on the webUI', function(
resource
) {
return assertBreadcrumbIsDisplayedFor(resource, false, true)
})

Then('clickable breadcrumb for folder {string} should be displayed on the webUI', function(
resource
) {
return assertBreadcrumbIsDisplayedFor(resource, true, false)
return assertBreadcrumbIsPresentFor(resource, false, true)
})

Then('breadcrumb for folder {string} should be displayed on the webUI', function(resource) {
Expand Down Expand Up @@ -725,31 +719,95 @@ const assertBreadcrumbIsDisplayedFor = async function(resource, clickable, nonCl
abortOnFailure: false
})

await client.page.personalPage().checkBreadcrumbVisibility(resourceBreadcrumbXpath)
try {
await client.waitForElementVisible({
selector: resourceBreadcrumbXpath,
locateStrategy: 'xpath'
})
isBreadcrumbVisible = true
} catch (e) {
isBreadcrumbVisible = false
}

// Try to look for a mobile breadcrumbs in case it has not been found
if (!isBreadcrumbVisible) {
await appSideBar.closeSidebarIfOpen()
const mobileBreadcrumbMobileXpath = util.format(
client.page.personalPage().elements.breadcrumbMobileReferencedToOpenSidebarButton.selector,
xpathHelper.buildXpathLiteral(resource)
)

await client.element('xpath', resourceBreadcrumbXpath, result => {
if (result.status > -1) {
try {
await client.waitForElementVisible({
selector: mobileBreadcrumbMobileXpath,
locateStrategy: 'xpath'
})
isBreadcrumbVisible = true
} catch (e) {
isBreadcrumbVisible = false
}
}

return client.assert.strictEqual(
isBreadcrumbVisible,
true,
`Resource ${resourceBreadcrumbXpath} expected to be visible but is not visible .`
)
}

/**
*
* @param {string} resource
* @param {boolean} clickable
* @param {boolean} nonClickable
*/
const assertBreadcrumbIsPresentFor = async function(resource, clickable, nonClickable) {
const breadcrumbElement = client.page
.personalPage()
.getBreadcrumbSelector(clickable, nonClickable)
const resourceBreadcrumbXpath = util.format(
breadcrumbElement.selector,
xpathHelper.buildXpathLiteral(resource)
)
let isBreadcrumbPresent = false

// lets hope that the breadcrumbs would not take longer than the "NEW" button
await client.waitForElementPresent({
selector: client.page.personalPage().elements.newFileMenuButtonAnyState.selector,
abortOnFailure: false
})

try {
await client.waitForElementPresent({
selector: resourceBreadcrumbXpath,
locateStrategy: 'xpath'
})
isBreadcrumbPresent = true
} catch (e) {
isBreadcrumbPresent = false
}

// Try to look for a mobile breadcrumbs in case it has not been found
if (!isBreadcrumbVisible) {
if (!isBreadcrumbPresent) {
await appSideBar.closeSidebarIfOpen()
const mobileBreadcrumbMobileXpath = util.format(
client.page.personalPage().elements.breadcrumbMobile.selector,
xpathHelper.buildXpathLiteral(resource)
)

await client.element('xpath', mobileBreadcrumbMobileXpath, result => {
if (result.status > -1) {
isBreadcrumbVisible = true
}
})
try {
await client.waitForElementPresent({
selector: mobileBreadcrumbMobileXpath,
locateStrategy: 'xpath'
})
isBreadcrumbPresent = true
} catch (e) {
isBreadcrumbPresent = false
}
}

return client.assert.strictEqual(
isBreadcrumbVisible,
isBreadcrumbPresent,
true,
`Resource ${resourceBreadcrumbXpath} expected to be visible but is not visible .`
)
Expand Down

0 comments on commit ec404ec

Please sign in to comment.