mirror of https://github.com/nextcloud/server.git
chore(cypress): Migrate apps acceptance tests to Cypress
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>pull/41303/head
parent
81a9e19ace
commit
54c934b910
@ -0,0 +1,151 @@
|
||||
/**
|
||||
* @copyright Copyright (c) 2023 Ferdinand Thiessen <opensource@fthiessen.de>
|
||||
*
|
||||
* @author Ferdinand Thiessen <opensource@fthiessen.de>
|
||||
*
|
||||
* @license AGPL-3.0-or-later
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import { User } from '@nextcloud/cypress'
|
||||
import { handlePasswordConfirmation } from './usersUtils'
|
||||
|
||||
const admin = new User('admin', 'admin')
|
||||
|
||||
describe('Settings: App management', { testIsolation: true }, () => {
|
||||
beforeEach(() => {
|
||||
// disable QA if already enabled
|
||||
cy.runOccCommand('app:disable -n testing')
|
||||
// enable notification if already disabled
|
||||
cy.runOccCommand('app:enable -n updatenotification')
|
||||
|
||||
// I am logged in as the admin
|
||||
cy.login(admin)
|
||||
// I open the Apps management
|
||||
cy.visit('/settings/apps')
|
||||
})
|
||||
|
||||
it('Can enable an installed app', () => {
|
||||
cy.get('#apps-list').should('be.visible')
|
||||
.contains('tr', 'QA testing')
|
||||
.should('exist')
|
||||
.find('.actions')
|
||||
// I enable the "QA testing" app
|
||||
.contains('button', 'Enable')
|
||||
.click({ force: true })
|
||||
|
||||
handlePasswordConfirmation(admin.password)
|
||||
|
||||
// Change to enabled apps view
|
||||
cy.get('#app-category-enabled a').click({ force: true })
|
||||
cy.url().should('match', /settings\/apps\/enabled$/)
|
||||
// I see that the "QA testing" app has been enabled
|
||||
cy.get('.apps-list-container').contains('tr', 'QA testing')
|
||||
})
|
||||
|
||||
it('Can disable an installed app', () => {
|
||||
cy.get('#apps-list').should('be.visible')
|
||||
.contains('tr', 'Update notification')
|
||||
.should('exist')
|
||||
.find('.actions')
|
||||
// I disable the "Update notification" app
|
||||
.contains('button', 'Disable')
|
||||
.click({ force: true })
|
||||
|
||||
handlePasswordConfirmation(admin.password)
|
||||
|
||||
// Change to disabled apps view
|
||||
cy.get('#app-category-disabled a').click({ force: true })
|
||||
cy.url().should('match', /settings\/apps\/disabled$/)
|
||||
// I see that the "Update notification" app has been disabled
|
||||
cy.get('.apps-list-container').contains('tr', 'Update notification')
|
||||
})
|
||||
|
||||
it('Browse enabled apps', () => {
|
||||
// When I open the "Active apps" section
|
||||
cy.get('#app-category-enabled a')
|
||||
.should('contain', 'Active apps')
|
||||
.click({ force: true })
|
||||
// Then I see that the current section is "Active apps"
|
||||
cy.url().should('match', /settings\/apps\/enabled$/)
|
||||
cy.get('#app-category-enabled').find('.active').should('exist')
|
||||
// I see that there are only enabled apps
|
||||
cy.get('#apps-list')
|
||||
.should('be.visible')
|
||||
.find('tr .actions')
|
||||
.each(($action) => {
|
||||
cy.wrap($action).should('not.contain', 'Enable')
|
||||
})
|
||||
})
|
||||
|
||||
it('Browse disabled apps', () => {
|
||||
// When I open the "Active apps" section
|
||||
cy.get('#app-category-disabled a')
|
||||
.should('contain', 'Disabled apps')
|
||||
.click({ force: true })
|
||||
// Then I see that the current section is "Active apps"
|
||||
cy.url().should('match', /settings\/apps\/disabled$/)
|
||||
cy.get('#app-category-disabled').find('.active').should('exist')
|
||||
// I see that there are only disabled apps
|
||||
cy.get('#apps-list')
|
||||
.should('be.visible')
|
||||
.find('tr .actions')
|
||||
.each(($action) => {
|
||||
cy.wrap($action).should('not.contain', 'Disable')
|
||||
})
|
||||
})
|
||||
|
||||
it('Browse app bundles', () => {
|
||||
// When I open the "App bundles" section
|
||||
cy.get('#app-category-your-bundles a')
|
||||
.should('contain', 'App bundles')
|
||||
.click({ force: true })
|
||||
// Then I see that the current section is "App bundles"
|
||||
cy.url().should('match', /settings\/apps\/app-bundles$/)
|
||||
cy.get('#app-category-your-bundles').find('.active').should('exist')
|
||||
// I see the app bundles
|
||||
cy.get('#apps-list').contains('tr', 'Enterprise bundle')
|
||||
cy.get('#apps-list').contains('tr', 'Education Edition')
|
||||
// I see that the "Enterprise bundle" is disabled
|
||||
cy.get('#apps-list').contains('tr', 'Enterprise bundle').contains('button', 'Download and enable all')
|
||||
})
|
||||
|
||||
it('View app details', () => {
|
||||
// When I click on the "QA testing" app
|
||||
cy.get('#apps-list').contains('tr', 'QA testing').click({ force: true })
|
||||
// I see that the app details are shown
|
||||
cy.get('#app-sidebar-vue')
|
||||
.should('be.visible')
|
||||
.find('.app-sidebar-header__info')
|
||||
.should('contain', 'QA testing')
|
||||
cy.get('#app-sidebar-vue').contains('a', 'View in store').should('exist')
|
||||
cy.get('#app-sidebar-vue').find('input[type="button"][value="Enable"]').should('be.visible')
|
||||
cy.get('#app-sidebar-vue').find('input[type="button"][value="Remove"]').should('be.visible')
|
||||
cy.get('#app-sidebar-vue .app-version').contains(/\d+\.\d+\.\d+/)
|
||||
})
|
||||
|
||||
/*
|
||||
* TODO: Improve testing with app store as external API
|
||||
* The following scenarios require the files_antivirus and calendar app
|
||||
* being present in the app store with support for the current server version
|
||||
* Ideally we would have either a dummy app store endpoint with some test apps
|
||||
* or even an app store instance running somewhere to properly test this.
|
||||
* This is also a requirement to properly test updates of apps
|
||||
*/
|
||||
// TODO: View app details for app store apps
|
||||
// TODO: Install an app from the app store
|
||||
// TODO: Show section from app store
|
||||
})
|
@ -1,19 +0,0 @@
|
||||
{
|
||||
"config": {
|
||||
"platform": {
|
||||
"php": "7.4"
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"behat/behat": "3.11.*",
|
||||
"behat/mink": "1.10.*",
|
||||
"behat/mink-extension": "2.3.*",
|
||||
"behat/mink-selenium2-driver": "1.6.*",
|
||||
"phpunit/phpunit": "9.5.19"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"": ["features/bootstrap", "features/core"]
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,99 +0,0 @@
|
||||
default:
|
||||
suites:
|
||||
default:
|
||||
paths:
|
||||
- "%paths.base%/../features"
|
||||
contexts:
|
||||
- ActorContext
|
||||
- NextcloudTestServerContext
|
||||
|
||||
- AppNavigationContext
|
||||
- AppSettingsContext
|
||||
- AppsManagementContext
|
||||
- CommentsAppContext
|
||||
- ContactsMenuContext
|
||||
- DialogContext
|
||||
- FeatureContext
|
||||
- FileListContext
|
||||
- FilesAppContext
|
||||
- FilesAppSharingContext
|
||||
- NotificationsContext
|
||||
- PublicShareContext
|
||||
- SearchContext
|
||||
- SettingsContext
|
||||
- SettingsMenuContext
|
||||
- ToastContext
|
||||
filters:
|
||||
tags: "~@apache"
|
||||
apache:
|
||||
paths:
|
||||
- "%paths.base%/../features"
|
||||
contexts:
|
||||
- ActorContext
|
||||
- NextcloudTestServerContext:
|
||||
nextcloudTestServerHelper: NextcloudTestServerLocalApacheHelper
|
||||
|
||||
- AppNavigationContext
|
||||
- AppSettingsContext
|
||||
- AppsManagementContext
|
||||
- CommentsAppContext
|
||||
- ContactsMenuContext
|
||||
- DialogContext
|
||||
- FeatureContext
|
||||
- FileListContext
|
||||
- FilesAppContext
|
||||
- FilesAppSharingContext
|
||||
- NotificationsContext
|
||||
- PublicShareContext
|
||||
- SearchContext
|
||||
- SettingsContext
|
||||
- SettingsMenuContext
|
||||
- ToastContext
|
||||
filters:
|
||||
tags: "@apache"
|
||||
extensions:
|
||||
Behat\MinkExtension:
|
||||
sessions:
|
||||
default:
|
||||
selenium2:
|
||||
wd_host: %selenium.server%
|
||||
browser: "chrome"
|
||||
capabilities:
|
||||
extra_capabilities:
|
||||
goog:chromeOptions:
|
||||
args: ["disable-dev-shm-usage"]
|
||||
w3c: false
|
||||
John:
|
||||
selenium2:
|
||||
wd_host: %selenium.server%
|
||||
browser: "chrome"
|
||||
capabilities:
|
||||
extra_capabilities:
|
||||
goog:chromeOptions:
|
||||
args: ["disable-dev-shm-usage"]
|
||||
w3c: false
|
||||
Jane:
|
||||
selenium2:
|
||||
wd_host: %selenium.server%
|
||||
browser: "chrome"
|
||||
capabilities:
|
||||
extra_capabilities:
|
||||
goog:chromeOptions:
|
||||
args: ["disable-dev-shm-usage"]
|
||||
w3c: false
|
||||
Jim:
|
||||
selenium2:
|
||||
wd_host: %selenium.server%
|
||||
browser: "chrome"
|
||||
capabilities:
|
||||
extra_capabilities:
|
||||
goog:chromeOptions:
|
||||
args: ["disable-dev-shm-usage"]
|
||||
w3c: false
|
||||
Rubeus:
|
||||
# Rubeus uses a browser that has CSS grid support.
|
||||
selenium2:
|
||||
wd_host: %selenium.server%
|
||||
capabilities:
|
||||
firefox:
|
||||
profile: %paths.base%/firefox-profiles/css-grid-enabled.zip
|
Binary file not shown.
@ -1,325 +0,0 @@
|
||||
Feature: app-comments
|
||||
|
||||
# Scenario: Writing a comment
|
||||
# Given I am logged in
|
||||
# And I open the details view for "welcome.txt"
|
||||
# And I open the "Comments" tab in the details view
|
||||
# When I create a new comment with "Hello world" as message
|
||||
# Then I see a comment with "Hello world" as message
|
||||
|
||||
# Scenario: open the comments for a different file
|
||||
# Given I am logged in
|
||||
# And I create a new folder named "Folder"
|
||||
# And I open the details view for "welcome.txt"
|
||||
# And I open the "Comments" tab in the details view
|
||||
# And I create a new comment with "Hello world" as message
|
||||
# And I see a comment with "Hello world" as message
|
||||
# When I open the details view for "Folder"
|
||||
# The "Comments" tab should already be opened
|
||||
# Then I see that there are no comments
|
||||
|
||||
Scenario: write a comment in a file right after writing a comment in another file
|
||||
Given I am logged in
|
||||
And I create a new folder named "Folder"
|
||||
And I open the details view for "Folder"
|
||||
And I open the "Comments" tab in the details view
|
||||
And I create a new comment with "Comment in Folder" as message
|
||||
And I see a comment with "Comment in Folder" as message
|
||||
And I open the details view for "welcome.txt"
|
||||
# The "Comments" tab should already be opened
|
||||
When I create a new comment with "Comment in welcome.txt" as message
|
||||
Then I see a comment with "Comment in welcome.txt" as message
|
||||
And I see that there is no comment with "Comment in Folder" as message
|
||||
|
||||
|
||||
|
||||
Scenario: read a comment written by the sharer
|
||||
Given I act as John
|
||||
And I am logged in as the admin
|
||||
And I act as Jane
|
||||
And I am logged in
|
||||
And I act as John
|
||||
And I rename "welcome.txt" to "shared.txt"
|
||||
And I share "shared.txt" with "user0"
|
||||
And I see that the file is shared with "user0"
|
||||
# The details view should already be open
|
||||
And I open the "Comments" tab in the details view
|
||||
And I create a new comment with "Hello world" as message
|
||||
And I see a comment with "Hello world" as message
|
||||
When I act as Jane
|
||||
# The Files app is open again to reload the file list and the comments
|
||||
And I open the Files app
|
||||
And I open the details view for "shared.txt"
|
||||
And I open the "Comments" tab in the details view
|
||||
Then I see a comment with "Hello world" as message
|
||||
|
||||
Scenario: read a comment written by the sharee
|
||||
Given I act as John
|
||||
And I am logged in as the admin
|
||||
And I act as Jane
|
||||
And I am logged in
|
||||
And I act as John
|
||||
And I rename "welcome.txt" to "shared.txt"
|
||||
And I share "shared.txt" with "user0"
|
||||
And I see that the file is shared with "user0"
|
||||
And I act as Jane
|
||||
# The Files app is open again to reload the file list
|
||||
And I open the Files app
|
||||
And I open the details view for "shared.txt"
|
||||
And I open the "Comments" tab in the details view
|
||||
And I create a new comment with "Hello world" as message
|
||||
And I see a comment with "Hello world" as message
|
||||
When I act as John
|
||||
# The Files app is open again to reload the file list and the comments
|
||||
And I open the Files app
|
||||
And I open the details view for "shared.txt"
|
||||
And I open the "Comments" tab in the details view
|
||||
Then I see a comment with "Hello world" as message
|
||||
|
||||
|
||||
|
||||
Scenario: unread comment icon shown for comment written by the sharer in a shared file
|
||||
Given I act as John
|
||||
And I am logged in as the admin
|
||||
And I act as Jane
|
||||
And I am logged in
|
||||
And I act as John
|
||||
And I rename "welcome.txt" to "shared.txt"
|
||||
And I share "shared.txt" with "user0"
|
||||
And I see that the file is shared with "user0"
|
||||
# The details view should already be open
|
||||
And I open the "Comments" tab in the details view
|
||||
And I create a new comment with "Hello world" as message
|
||||
And I see a comment with "Hello world" as message
|
||||
When I act as Jane
|
||||
# The Files app is open again to reload the file list and the comments
|
||||
And I open the Files app
|
||||
Then I see that "shared.txt" has unread comments
|
||||
And I open the unread comments for "shared.txt"
|
||||
And I see that the details view is open
|
||||
And I see a comment with "Hello world" as message
|
||||
|
||||
Scenario: unread comment icon shown for comment written by the sharee in a shared file
|
||||
Given I act as John
|
||||
And I am logged in as the admin
|
||||
And I act as Jane
|
||||
And I am logged in
|
||||
And I act as John
|
||||
And I rename "welcome.txt" to "shared.txt"
|
||||
And I share "shared.txt" with "user0"
|
||||
And I see that the file is shared with "user0"
|
||||
And I act as Jane
|
||||
# The Files app is open again to reload the file list
|
||||
And I open the Files app
|
||||
And I open the details view for "shared.txt"
|
||||
And I open the "Comments" tab in the details view
|
||||
And I create a new comment with "Hello world" as message
|
||||
And I see a comment with "Hello world" as message
|
||||
When I act as John
|
||||
# The Files app is open again to reload the file list and the comments
|
||||
And I open the Files app
|
||||
Then I see that "shared.txt" has unread comments
|
||||
And I open the unread comments for "shared.txt"
|
||||
And I see that the details view is open
|
||||
And I see a comment with "Hello world" as message
|
||||
|
||||
Scenario: unread comment icon shown for comment written by the sharer in a shared folder
|
||||
Given I act as John
|
||||
And I am logged in as the admin
|
||||
And I act as Jane
|
||||
And I am logged in
|
||||
And I act as John
|
||||
And I create a new folder named "Folder"
|
||||
And I share "Folder" with "user0"
|
||||
And I see that the file is shared with "user0"
|
||||
# The details view should already be open
|
||||
And I open the "Comments" tab in the details view
|
||||
And I create a new comment with "Hello world" as message
|
||||
And I see a comment with "Hello world" as message
|
||||
When I act as Jane
|
||||
# The Files app is open again to reload the file list and the comments
|
||||
And I open the Files app
|
||||
Then I see that "Folder" has unread comments
|
||||
And I open the unread comments for "Folder"
|
||||
And I see that the details view is open
|
||||
And I see a comment with "Hello world" as message
|
||||
|
||||
Scenario: unread comment icon shown for comment written by the sharee in a shared folder
|
||||
Given I act as John
|
||||
And I am logged in as the admin
|
||||
And I act as Jane
|
||||
And I am logged in
|
||||
And I act as John
|
||||
And I create a new folder named "Folder"
|
||||
And I share "Folder" with "user0"
|
||||
And I see that the file is shared with "user0"
|
||||
And I act as Jane
|
||||
# The Files app is open again to reload the file list
|
||||
And I open the Files app
|
||||
And I open the details view for "Folder"
|
||||
And I open the "Comments" tab in the details view
|
||||
And I create a new comment with "Hello world" as message
|
||||
And I see a comment with "Hello world" as message
|
||||
When I act as John
|
||||
# The Files app is open again to reload the file list and the comments
|
||||
And I open the Files app
|
||||
Then I see that "Folder" has unread comments
|
||||
And I open the unread comments for "Folder"
|
||||
And I see that the details view is open
|
||||
And I see a comment with "Hello world" as message
|
||||
|
||||
Scenario: unread comment icon shown for comment written by the sharer in a child folder of a shared folder
|
||||
Given I act as John
|
||||
And I am logged in as the admin
|
||||
And I act as Jane
|
||||
And I am logged in
|
||||
And I act as John
|
||||
And I create a new folder named "Folder"
|
||||
And I share "Folder" with "user0"
|
||||
And I see that the file is shared with "user0"
|
||||
And I enter in the folder named "Folder"
|
||||
And I create a new folder named "Child folder"
|
||||
# The details view should already be open
|
||||
And I open the "Comments" tab in the details view
|
||||
And I create a new comment with "Hello world" as message
|
||||
And I see a comment with "Hello world" as message
|
||||
When I act as Jane
|
||||
# The Files app is open again to reload the file list and the comments
|
||||
And I open the Files app
|
||||
And I enter in the folder named "Folder"
|
||||
Then I see that "Child folder" has unread comments
|
||||
And I open the unread comments for "Child folder"
|
||||
And I see that the details view is open
|
||||
And I see a comment with "Hello world" as message
|
||||
|
||||
Scenario: unread comment icon shown for comment written by the sharee in a child folder of a shared folder
|
||||
Given I act as John
|
||||
And I am logged in as the admin
|
||||
And I act as Jane
|
||||
And I am logged in
|
||||
And I act as John
|
||||
And I create a new folder named "Folder"
|
||||
And I share "Folder" with "user0"
|
||||
And I see that the file is shared with "user0"
|
||||
And I act as Jane
|
||||
# The Files app is open again to reload the file list
|
||||
And I open the Files app
|
||||
And I enter in the folder named "Folder"
|
||||
And I create a new folder named "Child folder"
|
||||
# The details view should already be open
|
||||
And I open the "Comments" tab in the details view
|
||||
And I create a new comment with "Hello world" as message
|
||||
And I see a comment with "Hello world" as message
|
||||
When I act as John
|
||||
And I enter in the folder named "Folder"
|
||||
Then I see that "Child folder" has unread comments
|
||||
And I open the unread comments for "Child folder"
|
||||
And I see that the details view is open
|
||||
And I see a comment with "Hello world" as message
|
||||
|
||||
|
||||
|
||||
Scenario: search a comment
|
||||
Given I am logged in
|
||||
And I open the details view for "welcome.txt"
|
||||
And I open the "Comments" tab in the details view
|
||||
And I create a new comment with "Hello world" as message
|
||||
And I see a comment with "Hello world" as message
|
||||
When I search for "hello"
|
||||
# Search results for comments also include the user that wrote the comment.
|
||||
Then I see that the search result 1 is "user0Hello world"
|
||||
And I see that the search result 1 was found in "welcome.txt"
|
||||
|
||||
Scenario: search a comment in a child folder
|
||||
Given I am logged in
|
||||
And I create a new folder named "Folder"
|
||||
And I enter in the folder named "Folder"
|
||||
And I create a new folder named "Child folder"
|
||||
And I open the details view for "Child folder"
|
||||
And I open the "Comments" tab in the details view
|
||||
And I create a new comment with "Hello world" as message
|
||||
And I see a comment with "Hello world" as message
|
||||
# The Files app is open again to reload the file list
|
||||
And I open the Files app
|
||||
When I search for "hello"
|
||||
# Search results for comments also include the user that wrote the comment.
|
||||
Then I see that the search result 1 is "user0Hello world"
|
||||
And I see that the search result 1 was found in "Folder/Child folder"
|
||||
|
||||
Scenario: search a comment by a another user
|
||||
Given I act as John
|
||||
And I am logged in as the admin
|
||||
And I act as Jane
|
||||
And I am logged in
|
||||
And I act as John
|
||||
And I rename "welcome.txt" to "shared.txt"
|
||||
And I share "shared.txt" with "user0"
|
||||
And I see that the file is shared with "user0"
|
||||
And I act as Jane
|
||||
# The Files app is open again to reload the file list
|
||||
And I open the Files app
|
||||
And I open the details view for "shared.txt"
|
||||
And I open the "Comments" tab in the details view
|
||||
And I create a new comment with "Hello world" as message
|
||||
And I see a comment with "Hello world" as message
|
||||
When I act as John
|
||||
And I search for "hello"
|
||||
# Search results for comments also include the user that wrote the comment.
|
||||
Then I see that the search result 1 is "user0Hello world"
|
||||
And I see that the search result 1 was found in "shared.txt"
|
||||
|
||||
Scenario: open a search result for a comment in a file
|
||||
Given I am logged in
|
||||
And I open the details view for "welcome.txt"
|
||||
And I open the "Comments" tab in the details view
|
||||
And I create a new comment with "Hello world" as message
|
||||
And I see a comment with "Hello world" as message
|
||||
# Force the details view to change to a different file before closing it
|
||||
And I create a new folder named "Folder"
|
||||
And I close the details view
|
||||
When I search for "hello"
|
||||
And I open the search result 1
|
||||
Then I see that the details view is open
|
||||
And I see that the file name shown in the details view is "welcome.txt"
|
||||
And I see a comment with "Hello world" as message
|
||||
And I see that the file list is currently in "Home"
|
||||
And I see that the file list contains a file named "welcome.txt"
|
||||
|
||||
Scenario: open a search result for a comment in a folder named like its child folder
|
||||
Given I am logged in
|
||||
And I create a new folder named "Folder"
|
||||
And I open the details view for "Folder"
|
||||
And I open the "Comments" tab in the details view
|
||||
And I create a new comment with "Hello world" as message
|
||||
And I see a comment with "Hello world" as message
|
||||
And I enter in the folder named "Folder"
|
||||
And I create a new folder named "Folder"
|
||||
# The Files app is open again to reload the file list
|
||||
And I open the Files app
|
||||
When I search for "hello"
|
||||
And I open the search result 1
|
||||
Then I see that the details view is open
|
||||
And I see that the file name shown in the details view is "Folder"
|
||||
And I see a comment with "Hello world" as message
|
||||
And I see that the file list is currently in "Home"
|
||||
And I see that the file list contains a file named "welcome.txt"
|
||||
And I see that the file list contains a file named "Folder"
|
||||
|
||||
Scenario: open a search result for a comment in a child folder
|
||||
Given I am logged in
|
||||
And I create a new folder named "Folder"
|
||||
And I enter in the folder named "Folder"
|
||||
And I create a new folder named "Child folder"
|
||||
And I open the details view for "Child folder"
|
||||
And I open the "Comments" tab in the details view
|
||||
And I create a new comment with "Hello world" as message
|
||||
And I see a comment with "Hello world" as message
|
||||
# The Files app is open again to reload the file list
|
||||
And I open the Files app
|
||||
When I search for "hello"
|
||||
And I open the search result 1
|
||||
Then I see that the details view is open
|
||||
And I see that the file name shown in the details view is "Child folder"
|
||||
And I see a comment with "Hello world" as message
|
||||
And I see that the file list is currently in "Home/Folder"
|
||||
And I see that the file list contains a file named "Child folder"
|
@ -1,92 +0,0 @@
|
||||
@apache
|
||||
Feature: apps
|
||||
|
||||
Scenario: enable an installed app
|
||||
Given I act as Jane
|
||||
And I am logged in as the admin
|
||||
And I open the Apps management
|
||||
When I enable the "QA testing" app
|
||||
Then I see that the "QA testing" app has been enabled
|
||||
|
||||
Scenario: disable a installed app
|
||||
Given I act as Jane
|
||||
And I am logged in as the admin
|
||||
And I open the Apps management
|
||||
When I disable the "Update notification" app
|
||||
Then I see that the "Update notification" app has been disabled
|
||||
|
||||
Scenario: Browse enabled apps
|
||||
Given I act as Jane
|
||||
And I am logged in as the admin
|
||||
And I open the Apps management
|
||||
When I open the "Active apps" section
|
||||
Then I see that the current section is "Active apps"
|
||||
And I see that there are only enabled apps
|
||||
|
||||
Scenario: Browse disabled apps
|
||||
Given I act as Jane
|
||||
And I am logged in as the admin
|
||||
And I open the Apps management
|
||||
When I open the "Disabled apps" section
|
||||
Then I see that the current section is "Disabled apps"
|
||||
And I see that there are only disabled apps
|
||||
|
||||
Scenario: Browse app bundles
|
||||
Given I act as Jane
|
||||
And I am logged in as the admin
|
||||
And I open the Apps management
|
||||
When I open the "App bundles" section
|
||||
Then I see that the current section is "App bundles"
|
||||
And I see the app bundles
|
||||
And I see that the "Enterprise bundle" is disabled
|
||||
|
||||
# Enabling an app bundle fails when not all apps have a matching version available
|
||||
# Scenario: Enable an app bundle
|
||||
# Given I act as Jane
|
||||
# And I am logged in as the admin
|
||||
# And I open the Apps management
|
||||
# And I open the "App bundles" section
|
||||
# When I enable all apps from the "Enterprise bundle"
|
||||
# Then I see that the "Auditing / Logging" app has been enabled
|
||||
# And I see that the "LDAP user and group backend" app has been enabled
|
||||
|
||||
Scenario: View app details
|
||||
Given I act as Jane
|
||||
And I am logged in as the admin
|
||||
And I open the Apps management
|
||||
When I click on the "QA testing" app
|
||||
Then I see that the app details are shown
|
||||
|
||||
# TODO: Improve testing with app store as external API
|
||||
# The following scenarios require the files_antivirus and calendar app
|
||||
# being present in the app store with support for the current server version
|
||||
# Ideally we would have either a dummy app store endpoint with some test apps
|
||||
# or even an app store instance running somewhere to properly test this.
|
||||
# This is also a requirement to properly test updates of apps
|
||||
|
||||
Scenario: Show section from app store
|
||||
Given I act as Jane
|
||||
And I am logged in as the admin
|
||||
And I open the Apps management
|
||||
And I see that the current section is "Your apps"
|
||||
#When I open the "Files" section
|
||||
#Then I see that there some apps listed from the app store
|
||||
#And I see that the current section is "Files"
|
||||
|
||||
# Scenario: View app details for app store apps
|
||||
# Given I act as Jane
|
||||
# And I am logged in as the admin
|
||||
# And I open the Apps management
|
||||
# And I open the "Tools" section
|
||||
# When I click on the "Antivirus for files" app
|
||||
# Then I see that the app details are shown
|
||||
|
||||
# Scenario: Install an app from the app store
|
||||
# Given I act as Jane
|
||||
# And I am logged in as the admin
|
||||
# And I open the Apps management
|
||||
# And I open the "Tools" section
|
||||
# And I click on the "Antivirus for files" app
|
||||
# And I see that the app details are shown
|
||||
# Then I download and enable the "Antivirus for files" app
|
||||
# And I see that the "Antivirus for files" app has been enabled
|
@ -1,154 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
* @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
class AppNavigationContext implements Context, ActorAwareInterface {
|
||||
use ActorAware;
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function appNavigation() {
|
||||
return Locator::forThe()->xpath("//*[@id=\"app-navigation\" or contains(@class, 'app-navigation')]")->
|
||||
describedAs("App navigation");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function appNavigationSectionItemFor($sectionText) {
|
||||
return Locator::forThe()->xpath("//li/*[contains(normalize-space(), '$sectionText')]/..")->
|
||||
descendantOf(self::appNavigation())->
|
||||
describedAs($sectionText . " section item in App Navigation");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function appNavigationSectionItemInFor($caption, $sectionText) {
|
||||
return Locator::forThe()->xpath("//li[normalize-space() = '$caption']/following-sibling::li/a[normalize-space() = '$sectionText']/..")->
|
||||
descendantOf(self::appNavigation())->
|
||||
describedAs($sectionText . " section item of the $caption group in App Navigation");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function appNavigationCurrentSectionItem() {
|
||||
return Locator::forThe()->css(".active")->
|
||||
descendantOf(self::appNavigation())->
|
||||
describedAs("Current section item in App Navigation");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function buttonForTheSection($class, $section) {
|
||||
return Locator::forThe()->css("." . $class)->
|
||||
descendantOf(self::appNavigationSectionItemFor($section))->
|
||||
describedAs("The $class button on the $section section in App Navigation");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function counterForTheSection($section) {
|
||||
return Locator::forThe()->css(".app-navigation-entry-utils-counter")->
|
||||
descendantOf(self::appNavigationSectionItemFor($section))->
|
||||
describedAs("The counter for the $section section in App Navigation");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I open the :section section
|
||||
*/
|
||||
public function iOpenTheSection($section) {
|
||||
$this->actor->find(self::appNavigationSectionItemFor($section), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I open the :section section of the :caption group
|
||||
*/
|
||||
public function iOpenTheSectionOf($caption, $section) {
|
||||
$this->actor->find(self::appNavigationSectionItemInFor($caption, $section), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I click the :class button on the :section section
|
||||
*/
|
||||
public function iClickTheButtonInTheSection($class, $section) {
|
||||
$this->actor->find(self::buttonForTheSection($class, $section), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the current section is :section
|
||||
*/
|
||||
public function iSeeThatTheCurrentSectionIs($section) {
|
||||
Assert::assertEquals($this->actor->find(self::appNavigationCurrentSectionItem(), 10)->getText(), $section);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the section :section is shown
|
||||
*/
|
||||
public function iSeeThatTheSectionIsShown($section) {
|
||||
if (!WaitFor::elementToBeEventuallyShown(
|
||||
$this->actor,
|
||||
self::appNavigationSectionItemFor($section),
|
||||
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The section $section in the app navigation is not shown yet after $timeout seconds");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the section :section is not shown
|
||||
*/
|
||||
public function iSeeThatTheSectionIsNotShown($section) {
|
||||
if (!WaitFor::elementToBeEventuallyNotShown(
|
||||
$this->actor,
|
||||
self::appNavigationSectionItemFor($section),
|
||||
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The section $section in the app navigation is still shown after $timeout seconds");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the section :section has a count of :count
|
||||
*/
|
||||
public function iSeeThatTheSectionHasACountOf($section, $count) {
|
||||
Assert::assertEquals($this->actor->find(self::counterForTheSection($section), 10)->getText(), $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the section :section does not have a count
|
||||
*/
|
||||
public function iSeeThatTheSectionDoesNotHaveACount($section) {
|
||||
if (!WaitFor::elementToBeEventuallyNotShown(
|
||||
$this->actor,
|
||||
self::counterForTheSection($section),
|
||||
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The counter for section $section is still shown after $timeout seconds");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
* @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
class AppSettingsContext implements Context, ActorAwareInterface {
|
||||
use ActorAware;
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function appSettings() {
|
||||
return Locator::forThe()->id("app-settings")->
|
||||
describedAs("App settings");
|
||||
}
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function appSettingsContent() {
|
||||
return Locator::forThe()->xpath("//div[@id = 'app-settings-content' or @id = 'app-settings__content']")->
|
||||
descendantOf(self::appSettings())->
|
||||
describedAs("App settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function appSettingsOpenButton() {
|
||||
return Locator::forThe()->xpath("//div[@id = 'app-settings-header' or @id = 'app-settings__header']/button")->
|
||||
descendantOf(self::appSettings())->
|
||||
describedAs("The button to open the app settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function checkboxInTheSettings($id) {
|
||||
return Locator::forThe()->xpath("//input[@id = '$id']")->
|
||||
descendantOf(self::appSettingsContent())->
|
||||
describedAs("The $id checkbox in the settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function checkboxLabelInTheSettings($id) {
|
||||
return Locator::forThe()->css("[data-test=\"$id\"]")->
|
||||
descendantOf(self::appSettingsContent())->
|
||||
describedAs("The label for the $id checkbox in the settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I open the settings
|
||||
*/
|
||||
public function iOpenTheSettings() {
|
||||
$this->actor->find(self::appSettingsOpenButton(), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I toggle the :id checkbox in the settings
|
||||
*/
|
||||
public function iToggleTheCheckboxInTheSettingsTo($id) {
|
||||
$this->actor->find(self::checkboxLabelInTheSettings($id), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the settings are opened
|
||||
*/
|
||||
public function iSeeThatTheSettingsAreOpened() {
|
||||
if (!WaitFor::elementToBeEventuallyShown(
|
||||
$this->actor,
|
||||
self::appSettingsContent(),
|
||||
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The app settings are not open yet after $timeout seconds");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,283 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
class AppsManagementContext implements Context, ActorAwareInterface {
|
||||
use ActorAware;
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function appsList() {
|
||||
return Locator::forThe()->xpath("//main[@id='app-content' or contains(@class, 'app-content')]//*[@id='apps-list']")->
|
||||
describedAs("Apps list in Apps Management");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function enableButtonForApp($app) {
|
||||
return Locator::forThe()->button("Enable")->
|
||||
descendantOf(self::rowForApp($app))->
|
||||
describedAs("Enable button in the app list for $app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function enableButtonForAnyApp() {
|
||||
return Locator::forThe()->button("Enable")->
|
||||
descendantOf(self::appsList())->
|
||||
describedAs("Enable button in the app list for any app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function downloadAndEnableButtonForApp($app) {
|
||||
return Locator::forThe()->button("Download and enable")->
|
||||
descendantOf(self::rowForApp($app))->
|
||||
describedAs("Download & enable button in the app list for $app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function disableButtonForApp($app) {
|
||||
return Locator::forThe()->button("Disable")->
|
||||
descendantOf(self::rowForApp($app))->
|
||||
describedAs("Disable button in the app list for $app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function disableButtonForAnyApp() {
|
||||
return Locator::forThe()->button("Disable")->
|
||||
descendantOf(self::appsList())->
|
||||
describedAs("Disable button in the app list for any app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function enableAllBundleButton($bundle) {
|
||||
return Locator::forThe()->xpath("//th[//*[normalize-space() = '$bundle']]//button[normalize-space() = 'Download and enable all']")->
|
||||
descendantOf(self::appsList())->
|
||||
describedAs("Button to enable bundles");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function rowForApp($app) {
|
||||
return Locator::forThe()->xpath("//*[@class='app-name'][normalize-space() = '$app']/..")->
|
||||
descendantOf(self::appsList())->
|
||||
describedAs("Row for app $app in Apps Management");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function emptyAppList() {
|
||||
return Locator::forThe()->xpath("//*[@id='apps-list-empty']")->
|
||||
descendantOf(self::appsList())->
|
||||
describedAs("Empty apps list view");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function appEntries() {
|
||||
return Locator::forThe()->xpath("//div[@class='section']")->
|
||||
descendantOf(self::appsList())->
|
||||
describedAs("Entries in apps list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function disabledAppEntries() {
|
||||
return Locator::forThe()->button("Disable")->
|
||||
descendantOf(self::appEntries())->
|
||||
describedAs("Disable button in the app list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function enabledAppEntries() {
|
||||
return Locator::forThe()->button("Enable")->
|
||||
descendantOf(self::appEntries())->
|
||||
describedAs("Enable button in the app list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function sidebar() {
|
||||
return Locator::forThe()->xpath("//*[@id=\"app-sidebar\" or contains(@class, 'app-sidebar')]")->
|
||||
describedAs("Sidebar in apps management");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @When I enable the :app app
|
||||
*/
|
||||
public function iEnableTheApp($app) {
|
||||
$this->actor->find(self::enableButtonForApp($app), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I download and enable the :app app
|
||||
*/
|
||||
public function iDownloadAndEnableTheApp($app) {
|
||||
$this->actor->find(self::downloadAndEnableButtonForApp($app), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I disable the :app app
|
||||
*/
|
||||
public function iDisableTheApp($app) {
|
||||
$this->actor->find(self::disableButtonForApp($app), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the :app app has been enabled
|
||||
*/
|
||||
public function iSeeThatTheAppHasBeenEnabled($app) {
|
||||
// TODO: Find a way to check if the enable button is removed
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::disableButtonForApp($app), 10)->isVisible()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the :app app has been disabled
|
||||
*/
|
||||
public function iSeeThatTheAppHasBeenDisabled($app) {
|
||||
// TODO: Find a way to check if the disable button is removed
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::enableButtonForApp($app), 10)->isVisible()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^I see that there are no available updates$/
|
||||
*/
|
||||
public function iSeeThatThereAreNoAvailableUpdates() {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::emptyAppList(), 10)->isVisible()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^I see that there some apps listed from the app store$/
|
||||
*/
|
||||
public function iSeeThatThereSomeAppsListedFromTheAppStore() {
|
||||
if (!WaitFor::elementToBeEventuallyShown(
|
||||
$this->actor,
|
||||
self::appEntries(),
|
||||
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The apps from the app store were not shown yet after $timeout seconds");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^I click on the "([^"]*)" app$/
|
||||
*/
|
||||
public function iClickOnTheApp($app) {
|
||||
$this->actor->find(self::rowForApp($app), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given /^I see that there are only disabled apps$/
|
||||
*/
|
||||
public function iSeeThatThereAreOnlyDisabledApps() {
|
||||
try {
|
||||
$this->actor->find(self::disableButtonForAnyApp(), 2);
|
||||
|
||||
Assert::fail("Found enabled apps");
|
||||
} catch (NoSuchElementException $exception) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given /^I see that there are only enabled apps$/
|
||||
*/
|
||||
public function iSeeThatThereAreOnlyEnabledApps() {
|
||||
try {
|
||||
$this->actor->find(self::enableButtonForAnyApp(), 2);
|
||||
|
||||
Assert::fail("Found disabled apps");
|
||||
} catch (NoSuchElementException $exception) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given /^I see the app bundles$/
|
||||
*/
|
||||
public function iSeeTheAppBundles() {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::rowForApp('Auditing / Logging'), 10)->isVisible()
|
||||
);
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::rowForApp('LDAP user and group backend'), 2)->isVisible()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^I enable all apps from the "([^"]*)"$/
|
||||
*/
|
||||
public function iEnableAllAppsFromThe($bundle) {
|
||||
$this->actor->find(self::enableAllBundleButton($bundle), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given /^I see that the "([^"]*)" is disabled$/
|
||||
*/
|
||||
public function iSeeThatTheIsDisabled($bundle) {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::enableAllBundleButton($bundle), 2)->isVisible()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given /^I see that the app details are shown$/
|
||||
*/
|
||||
public function iSeeThatTheAppDetailsAreShown() {
|
||||
// The sidebar always exists in the DOM, so it has to be explicitly
|
||||
// waited for it to be visible instead of relying on the implicit wait
|
||||
// made to find the element.
|
||||
if (!WaitFor::elementToBeEventuallyShown(
|
||||
$this->actor,
|
||||
self::sidebar(),
|
||||
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The sidebar was not shown yet after $timeout seconds");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,113 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
class CommentsAppContext implements Context, ActorAwareInterface {
|
||||
use ActorAware;
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function newCommentField() {
|
||||
return Locator::forThe()->css("div.newCommentRow .message")->
|
||||
descendantOf(FilesAppContext::detailsView())->
|
||||
describedAs("New comment field in details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function submitNewCommentButton() {
|
||||
return Locator::forThe()->css("div.newCommentRow .submit")->
|
||||
descendantOf(FilesAppContext::detailsView())->
|
||||
describedAs("Submit new comment button in details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function commentList() {
|
||||
return Locator::forThe()->css("ul.comments")->
|
||||
descendantOf(FilesAppContext::detailsView())->
|
||||
describedAs("Comment list in details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function commentWithText($text) {
|
||||
return Locator::forThe()->xpath("//div[normalize-space() = '$text']/ancestor::li")->
|
||||
descendantOf(self::commentList())->
|
||||
describedAs("Comment with text \"$text\" in details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function emptyContent() {
|
||||
return Locator::forThe()->css(".emptycontent")->
|
||||
descendantOf(FilesAppContext::detailsView())->
|
||||
describedAs("Empty content in details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^I create a new comment with "([^"]*)" as message$/
|
||||
*/
|
||||
public function iCreateANewCommentWithAsMessage($commentText) {
|
||||
$this->actor->find(self::newCommentField(), 10)->setValue($commentText);
|
||||
$this->actor->find(self::submitNewCommentButton())->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^I see that there are no comments$/
|
||||
*/
|
||||
public function iSeeThatThereAreNoComments() {
|
||||
if (!WaitFor::elementToBeEventuallyShown(
|
||||
$this->actor,
|
||||
self::emptyContent(),
|
||||
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The no comments message is not visible yet after $timeout seconds");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^I see a comment with "([^"]*)" as message$/
|
||||
*/
|
||||
public function iSeeACommentWithAsMessage($commentText) {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::commentWithText($commentText), 10)->isVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^I see that there is no comment with "([^"]*)" as message$/
|
||||
*/
|
||||
public function iSeeThatThereIsNoCommentWithAsMessage($commentText) {
|
||||
try {
|
||||
Assert::assertFalse(
|
||||
$this->actor->find(self::commentWithText($commentText))->isVisible());
|
||||
} catch (NoSuchElementException $exception) {
|
||||
}
|
||||
}
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) (skjnldsv@protonmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
class ContactsMenuContext implements Context, ActorAwareInterface {
|
||||
use ActorAware;
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function contactsMenuButton() {
|
||||
return Locator::forThe()->xpath("//*[@id = 'header']//*[@id = 'contactsmenu']//*[contains(@class, 'header-menu__trigger')]")->
|
||||
describedAs("Contacts menu button");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function contactsMenu() {
|
||||
return Locator::forThe()->xpath("//*[@id = 'header']//*[@id = 'contactsmenu']//*[@class = 'contactsmenu__menu']")->
|
||||
describedAs("Contacts menu");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function contactsMenuSearchInput() {
|
||||
return Locator::forThe()->id("contactsmenu__menu__search")->
|
||||
descendantOf(self::contactsMenu())->
|
||||
describedAs("Contacts menu search input");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function noResultsMessage() {
|
||||
return Locator::forThe()->xpath("//*[@class = 'empty-content' and normalize-space() = 'No contacts found']")->
|
||||
descendantOf(self::contactsMenu())->
|
||||
describedAs("No results message in Contacts menu");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
private static function menuItemFor($contactName) {
|
||||
return Locator::forThe()->xpath("//*[@class = 'contact__body__full-name' and normalize-space() = '$contactName']")->
|
||||
descendantOf(self::contactsMenu())->
|
||||
describedAs($contactName . " contact in Contacts menu");
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I open the Contacts menu
|
||||
*/
|
||||
public function iOpenTheContactsMenu() {
|
||||
$this->actor->find(self::contactsMenuButton(), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I search for the user :user
|
||||
*/
|
||||
public function iSearchForTheUser($user) {
|
||||
$this->actor->find(self::contactsMenuSearchInput(), 10)->setValue($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the Contacts menu is shown
|
||||
*/
|
||||
public function iSeeThatTheContactsMenuIsShown() {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::contactsMenu(), 10)->isVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the Contacts menu search input is shown
|
||||
*/
|
||||
public function iSeeThatTheContactsMenuSearchInputIsShown() {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::contactsMenuSearchInput(), 10)->isVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the no results message in the Contacts menu is shown
|
||||
*/
|
||||
public function iSeeThatTheNoResultsMessageInTheContactsMenuIsShown() {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::noResultsMessage(), 10)->isVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the contact :contactName in the Contacts menu is shown
|
||||
*/
|
||||
public function iSeeThatTheContactInTheContactsMenuIsShown($contactName) {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::menuItemFor($contactName), 10)->isVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the contact :contactName in the Contacts menu is not shown
|
||||
*/
|
||||
public function iSeeThatTheContactInTheContactsMenuIsNotShown($contactName) {
|
||||
$this->iSeeThatThecontactsMenuIsShown();
|
||||
|
||||
try {
|
||||
Assert::assertFalse(
|
||||
$this->actor->find(self::menuItemFor($contactName))->isVisible());
|
||||
} catch (NoSuchElementException $exception) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the contact :contactName in the Contacts menu is eventually not shown
|
||||
*/
|
||||
public function iSeeThatTheContactInTheContactsMenuIsEventuallyNotShown($contactName) {
|
||||
$this->iSeeThatThecontactsMenuIsShown();
|
||||
|
||||
if (!WaitFor::elementToBeEventuallyNotShown(
|
||||
$this->actor,
|
||||
self::menuItemFor($contactName),
|
||||
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The $contactName contact in Contacts menu is still shown after $timeout seconds");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
class DialogContext implements Context, ActorAwareInterface {
|
||||
use ActorAware;
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function theDialog() {
|
||||
return Locator::forThe()->css(".oc-dialog")->
|
||||
describedAs("The dialog");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function theDialogButton($text) {
|
||||
return Locator::forThe()->xpath("//button[normalize-space() = \"$text\"]")->
|
||||
descendantOf(self::theDialog())->
|
||||
describedAs($text . " button of the dialog");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I click the :text button of the confirmation dialog
|
||||
*/
|
||||
public function iClickTheDialogButton($text) {
|
||||
$this->actor->find(self::theDialogButton($text), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the confirmation dialog is shown
|
||||
*/
|
||||
public function iSeeThatTheConfirmationDialogIsShown() {
|
||||
if (!WaitFor::elementToBeEventuallyShown(
|
||||
$this->actor,
|
||||
self::theDialog(),
|
||||
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The confirmation dialog was not shown yet after $timeout seconds");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the confirmation dialog is not shown
|
||||
*/
|
||||
public function iSeeThatTheConfirmationDialogIsNotShown() {
|
||||
if (!WaitFor::elementToBeEventuallyNotShown(
|
||||
$this->actor,
|
||||
self::theDialog(),
|
||||
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The confirmation dialog is still shown after $timeout seconds");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
|
||||
class FeatureContext implements Context, ActorAwareInterface {
|
||||
use ActorAware;
|
||||
|
||||
/**
|
||||
* @When I visit the Home page
|
||||
*/
|
||||
public function iVisitTheHomePage() {
|
||||
$this->actor->getSession()->visit($this->actor->locatePath("/"));
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2018, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
||||
|
||||
/**
|
||||
* Helper trait to set the ancestor of the file list.
|
||||
*
|
||||
* The FileListContext provides steps to interact with and check the behaviour
|
||||
* of a file list. However, the FileListContext does not know the right file
|
||||
* list ancestor that has to be used by the file list steps; this has to be set
|
||||
* from other contexts, for example, when the Files app or the public page for a
|
||||
* shared folder is opened.
|
||||
*
|
||||
* Contexts that "know" that certain file list ancestor has to be used by the
|
||||
* FileListContext steps should use this trait and call
|
||||
* "setFileListAncestorForActor" when needed.
|
||||
*/
|
||||
trait FileListAncestorSetter {
|
||||
/**
|
||||
* @var FileListContext
|
||||
*/
|
||||
private $fileListContext;
|
||||
|
||||
/**
|
||||
* @BeforeScenario
|
||||
*/
|
||||
public function getSiblingFileListContext(BeforeScenarioScope $scope) {
|
||||
$environment = $scope->getEnvironment();
|
||||
|
||||
$this->fileListContext = $environment->getContext("FileListContext");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file list ancestor to be used in the file list steps performed
|
||||
* by the given actor.
|
||||
*
|
||||
* @param null|Locator $fileListAncestor the file list ancestor
|
||||
* @param Actor $actor the actor
|
||||
*/
|
||||
private function setFileListAncestorForActor($fileListAncestor, Actor $actor) {
|
||||
$this->fileListContext->setFileListAncestorForActor($fileListAncestor, $actor);
|
||||
}
|
||||
}
|
@ -1,595 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2018, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
class FileListContext implements Context, ActorAwareInterface {
|
||||
/**
|
||||
* @var Actor
|
||||
*/
|
||||
private $actor;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $fileListAncestorsByActor;
|
||||
|
||||
/**
|
||||
* @var Locator
|
||||
*/
|
||||
private $fileListAncestor;
|
||||
|
||||
/**
|
||||
* @BeforeScenario
|
||||
*/
|
||||
public function initializeFileListAncestors() {
|
||||
$this->fileListAncestorsByActor = [];
|
||||
$this->fileListAncestor = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Actor $actor
|
||||
*/
|
||||
public function setCurrentActor(Actor $actor) {
|
||||
$this->actor = $actor;
|
||||
|
||||
if (array_key_exists($actor->getName(), $this->fileListAncestorsByActor)) {
|
||||
$this->fileListAncestor = $this->fileListAncestorsByActor[$actor->getName()];
|
||||
} else {
|
||||
$this->fileListAncestor = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file list ancestor to be used in the steps performed by the
|
||||
* given actor from that point on (until changed again).
|
||||
*
|
||||
* This is meant to be called from other contexts, for example, when the
|
||||
* Files app or the public page for a shared folder are opened.
|
||||
*
|
||||
* The FileListAncestorSetter trait can be used to reduce the boilerplate
|
||||
* needed to set the file list ancestor from other contexts.
|
||||
*
|
||||
* @param null|Locator $fileListAncestor the file list ancestor
|
||||
* @param Actor $actor the actor
|
||||
*/
|
||||
public function setFileListAncestorForActor($fileListAncestor, Actor $actor) {
|
||||
$this->fileListAncestorsByActor[$actor->getName()] = $fileListAncestor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function mainWorkingIcon($fileListAncestor) {
|
||||
return Locator::forThe()->css(".mask.icon-loading")->
|
||||
descendantOf($fileListAncestor)->
|
||||
describedAs("Main working icon in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function breadcrumbs($fileListAncestor) {
|
||||
return Locator::forThe()->css(".files-controls .breadcrumb")->
|
||||
descendantOf($fileListAncestor)->
|
||||
describedAs("Breadcrumbs in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function createMenuButton($fileListAncestor) {
|
||||
return Locator::forThe()->css(".files-controls .button.new")->
|
||||
descendantOf($fileListAncestor)->
|
||||
describedAs("Create menu button in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
private static function createMenuItemFor($fileListAncestor, $newType) {
|
||||
return Locator::forThe()->xpath("//div[contains(concat(' ', normalize-space(@class), ' '), ' newFileMenu ')]//span[normalize-space() = '$newType']/ancestor::li")->
|
||||
descendantOf($fileListAncestor)->
|
||||
describedAs("Create $newType menu item in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function createNewFolderMenuItem($fileListAncestor) {
|
||||
return self::createMenuItemFor($fileListAncestor, "New folder");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function createNewFolderMenuItemNameInput($fileListAncestor) {
|
||||
return Locator::forThe()->css(".filenameform input[type=text]")->
|
||||
descendantOf(self::createNewFolderMenuItem($fileListAncestor))->
|
||||
describedAs("Name input in create new folder menu item in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function createNewFolderMenuItemConfirmButton($fileListAncestor) {
|
||||
return Locator::forThe()->css(".filenameform input[type=submit]")->
|
||||
descendantOf(self::createNewFolderMenuItem($fileListAncestor))->
|
||||
describedAs("Confirm button in create new folder menu item in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function fileListHeader($fileListAncestor) {
|
||||
return Locator::forThe()->css("thead")->
|
||||
descendantOf($fileListAncestor)->
|
||||
describedAs("Header in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function selectedFilesActionsMenuButton($fileListAncestor) {
|
||||
return Locator::forThe()->css(".actions-selected")->
|
||||
descendantOf(self::fileListHeader($fileListAncestor))->
|
||||
describedAs("Selected files actions menu button in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function selectedFilesActionsMenu() {
|
||||
return Locator::forThe()->css(".filesSelectMenu")->
|
||||
describedAs("Selected files actions menu in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
private static function selectedFilesActionsMenuItemFor($itemText) {
|
||||
return Locator::forThe()->xpath("//a[normalize-space() = '$itemText']")->
|
||||
descendantOf(self::selectedFilesActionsMenu())->
|
||||
describedAs($itemText . " item in selected files actions menu in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function moveOrCopySelectedFilesMenuItem() {
|
||||
return self::selectedFilesActionsMenuItemFor("Move or copy");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function rowForFile($fileListAncestor, $fileName) {
|
||||
return Locator::forThe()->xpath("//*[@class = 'files-fileList']//span[contains(concat(' ', normalize-space(@class), ' '), ' nametext ') and normalize-space() = '$fileName']/ancestor::tr")->
|
||||
descendantOf($fileListAncestor)->
|
||||
describedAs("Row for file $fileName in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function rowForFilePreceding($fileListAncestor, $fileName1, $fileName2) {
|
||||
return Locator::forThe()->xpath("//preceding-sibling::tr//span[contains(concat(' ', normalize-space(@class), ' '), ' nametext ') and normalize-space() = '$fileName1']/ancestor::tr")->
|
||||
descendantOf(self::rowForFile($fileListAncestor, $fileName2))->
|
||||
describedAs("Row for file $fileName1 preceding $fileName2 in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function selectionCheckboxForFile($fileListAncestor, $fileName) {
|
||||
// Note that the element that the user interacts with is the label, not
|
||||
// the checbox itself.
|
||||
return Locator::forThe()->css(".selection label")->
|
||||
descendantOf(self::rowForFile($fileListAncestor, $fileName))->
|
||||
describedAs("Selection checkbox for file $fileName in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function selectionCheckboxInputForFile($fileListAncestor, $fileName) {
|
||||
return Locator::forThe()->css(".selection input[type=checkbox]")->
|
||||
descendantOf(self::rowForFile($fileListAncestor, $fileName))->
|
||||
describedAs("Selection checkbox input for file $fileName in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function favoriteMarkForFile($fileListAncestor, $fileName) {
|
||||
return Locator::forThe()->css(".favorite-mark")->
|
||||
descendantOf(self::rowForFile($fileListAncestor, $fileName))->
|
||||
describedAs("Favorite mark for file $fileName in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function notFavoritedStateIconForFile($fileListAncestor, $fileName) {
|
||||
return Locator::forThe()->css(".icon-star")->
|
||||
descendantOf(self::favoriteMarkForFile($fileListAncestor, $fileName))->
|
||||
describedAs("Not favorited state icon for file $fileName in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function favoritedStateIconForFile($fileListAncestor, $fileName) {
|
||||
return Locator::forThe()->css(".icon-starred")->
|
||||
descendantOf(self::favoriteMarkForFile($fileListAncestor, $fileName))->
|
||||
describedAs("Favorited state icon for file $fileName in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function mainLinkForFile($fileListAncestor, $fileName) {
|
||||
return Locator::forThe()->css(".name")->
|
||||
descendantOf(self::rowForFile($fileListAncestor, $fileName))->
|
||||
describedAs("Main link for file $fileName in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function renameInputForFile($fileListAncestor, $fileName) {
|
||||
return Locator::forThe()->css("input.filename")->
|
||||
descendantOf(self::rowForFile($fileListAncestor, $fileName))->
|
||||
describedAs("Rename input for file $fileName in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function commentActionForFile($fileListAncestor, $fileName) {
|
||||
return Locator::forThe()->css(".action-comment")->
|
||||
descendantOf(self::rowForFile($fileListAncestor, $fileName))->
|
||||
describedAs("Comment action for file $fileName in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function shareActionForFile($fileListAncestor, $fileName) {
|
||||
return Locator::forThe()->css(".action-share")->
|
||||
descendantOf(self::rowForFile($fileListAncestor, $fileName))->
|
||||
describedAs("Share action for file $fileName in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function fileActionsMenuButtonForFile($fileListAncestor, $fileName) {
|
||||
return Locator::forThe()->css(".action-menu")->
|
||||
descendantOf(self::rowForFile($fileListAncestor, $fileName))->
|
||||
describedAs("File actions menu button for file $fileName in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function fileActionsMenu() {
|
||||
return Locator::forThe()->css(".fileActionsMenu")->
|
||||
describedAs("File actions menu in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
private static function fileActionsMenuItemFor($itemText) {
|
||||
return Locator::forThe()->xpath("//a[normalize-space() = '$itemText']")->
|
||||
descendantOf(self::fileActionsMenu())->
|
||||
describedAs($itemText . " item in file actions menu in file list");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function addToFavoritesMenuItem() {
|
||||
return self::fileActionsMenuItemFor("Add to favorites");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function removeFromFavoritesMenuItem() {
|
||||
return self::fileActionsMenuItemFor("Remove from favorites");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function detailsMenuItem() {
|
||||
return self::fileActionsMenuItemFor("Details");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function renameMenuItem() {
|
||||
return self::fileActionsMenuItemFor("Rename");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function moveOrCopyMenuItem() {
|
||||
return self::fileActionsMenuItemFor("Move or copy");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function viewFileInFolderMenuItem() {
|
||||
return self::fileActionsMenuItemFor("View in folder");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function deleteMenuItem() {
|
||||
return self::fileActionsMenuItemFor("Delete");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I create a new folder named :folderName
|
||||
*/
|
||||
public function iCreateANewFolderNamed($folderName) {
|
||||
$this->actor->find(self::createMenuButton($this->fileListAncestor), 10)->click();
|
||||
|
||||
$this->actor->find(self::createNewFolderMenuItem($this->fileListAncestor), 2)->click();
|
||||
$this->actor->find(self::createNewFolderMenuItemNameInput($this->fileListAncestor), 2)->setValue($folderName);
|
||||
$this->actor->find(self::createNewFolderMenuItemConfirmButton($this->fileListAncestor), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I enter in the folder named :folderName
|
||||
*/
|
||||
public function iEnterInTheFolderNamed($folderName) {
|
||||
$this->actor->find(self::mainLinkForFile($this->fileListAncestor, $folderName), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I select :fileName
|
||||
*/
|
||||
public function iSelect($fileName) {
|
||||
$this->iSeeThatIsNotSelected($fileName);
|
||||
|
||||
$this->actor->find(self::selectionCheckboxForFile($this->fileListAncestor, $fileName), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I start the move or copy operation for the selected files
|
||||
*/
|
||||
public function iStartTheMoveOrCopyOperationForTheSelectedFiles() {
|
||||
$this->actor->find(self::selectedFilesActionsMenuButton($this->fileListAncestor), 10)->click();
|
||||
|
||||
$this->actor->find(self::moveOrCopySelectedFilesMenuItem(), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I open the details view for :fileName
|
||||
*/
|
||||
public function iOpenTheDetailsViewFor($fileName) {
|
||||
$this->openFileActionsMenuForFile($fileName);
|
||||
|
||||
$this->actor->find(self::detailsMenuItem(), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I rename :fileName1 to :fileName2
|
||||
*/
|
||||
public function iRenameTo($fileName1, $fileName2) {
|
||||
$this->openFileActionsMenuForFile($fileName1);
|
||||
|
||||
$this->actor->find(self::renameMenuItem(), 2)->click();
|
||||
|
||||
// For reference, due to a bug in the Firefox driver of Selenium and/or
|
||||
// maybe in Firefox itself, as a range is selected in the rename input
|
||||
// (the name of the file, without its extension) when the value is set
|
||||
// the window must be in the foreground. Otherwise, if the window is in
|
||||
// the background, instead of setting the value in the whole field it
|
||||
// would be set only in the selected range.
|
||||
// This should not be a problem, though, as the default behaviour is to
|
||||
// bring the browser window to the foreground when switching to a
|
||||
// different actor.
|
||||
$this->actor->find(self::renameInputForFile($this->fileListAncestor, $fileName1), 10)->setValue($fileName2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I start the move or copy operation for :fileName
|
||||
*/
|
||||
public function iStartTheMoveOrCopyOperationFor($fileName) {
|
||||
$this->openFileActionsMenuForFile($fileName);
|
||||
|
||||
$this->actor->find(self::moveOrCopyMenuItem(), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I mark :fileName as favorite
|
||||
*/
|
||||
public function iMarkAsFavorite($fileName) {
|
||||
$this->iSeeThatIsNotMarkedAsFavorite($fileName);
|
||||
|
||||
$this->openFileActionsMenuForFile($fileName);
|
||||
|
||||
$this->actor->find(self::addToFavoritesMenuItem(), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I unmark :fileName as favorite
|
||||
*/
|
||||
public function iUnmarkAsFavorite($fileName) {
|
||||
$this->iSeeThatIsMarkedAsFavorite($fileName);
|
||||
|
||||
$this->openFileActionsMenuForFile($fileName);
|
||||
|
||||
$this->actor->find(self::removeFromFavoritesMenuItem(), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I view :fileName in folder
|
||||
*/
|
||||
public function iViewInFolder($fileName) {
|
||||
$this->openFileActionsMenuForFile($fileName);
|
||||
|
||||
$this->actor->find(self::viewFileInFolderMenuItem(), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I delete :fileName
|
||||
*/
|
||||
public function iDelete($fileName) {
|
||||
$this->openFileActionsMenuForFile($fileName);
|
||||
|
||||
$this->actor->find(self::deleteMenuItem(), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I open the unread comments for :fileName
|
||||
*/
|
||||
public function iOpenTheUnreadCommentsFor($fileName) {
|
||||
$this->actor->find(self::commentActionForFile($this->fileListAncestor, $fileName), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the file list is eventually loaded
|
||||
*/
|
||||
public function iSeeThatTheFileListIsEventuallyLoaded() {
|
||||
if (!WaitFor::elementToBeEventuallyNotShown(
|
||||
$this->actor,
|
||||
self::mainWorkingIcon($this->fileListAncestor),
|
||||
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The main working icon for the file list is still shown after $timeout seconds");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the file list is currently in :path
|
||||
*/
|
||||
public function iSeeThatTheFileListIsCurrentlyIn($path) {
|
||||
// The text of the breadcrumbs is the text of all the crumbs separated
|
||||
// by white spaces.
|
||||
Assert::assertEquals(
|
||||
str_replace('/', ' ', $path), $this->actor->find(self::breadcrumbs($this->fileListAncestor), 10)->getText());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that it is not possible to create new files
|
||||
*/
|
||||
public function iSeeThatItIsNotPossibleToCreateNewFiles() {
|
||||
// Once a file list is loaded the "Create" menu button is always in the
|
||||
// DOM, so it is checked if it is visible or not.
|
||||
Assert::assertFalse($this->actor->find(self::createMenuButton($this->fileListAncestor))->isVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the file list contains a file named :fileName
|
||||
*/
|
||||
public function iSeeThatTheFileListContainsAFileNamed($fileName) {
|
||||
Assert::assertNotNull($this->actor->find(self::rowForFile($this->fileListAncestor, $fileName), 10));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the file list does not contain a file named :fileName
|
||||
*/
|
||||
public function iSeeThatTheFileListDoesNotContainAFileNamed($fileName) {
|
||||
if (!WaitFor::elementToBeEventuallyNotShown(
|
||||
$this->actor,
|
||||
self::rowForFile($this->fileListAncestor, $fileName),
|
||||
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The file list still contains a file named $fileName after $timeout seconds");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that :fileName1 precedes :fileName2 in the file list
|
||||
*/
|
||||
public function iSeeThatPrecedesInTheFileList($fileName1, $fileName2) {
|
||||
Assert::assertNotNull($this->actor->find(self::rowForFilePreceding($this->fileListAncestor, $fileName1, $fileName2), 10));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that :fileName is not selected
|
||||
*/
|
||||
public function iSeeThatIsNotSelected($fileName) {
|
||||
Assert::assertFalse($this->actor->find(self::selectionCheckboxInputForFile($this->fileListAncestor, $fileName), 10)->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that :fileName is marked as favorite
|
||||
*/
|
||||
public function iSeeThatIsMarkedAsFavorite($fileName) {
|
||||
Assert::assertNotNull($this->actor->find(self::favoritedStateIconForFile($this->fileListAncestor, $fileName), 10));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that :fileName is not marked as favorite
|
||||
*/
|
||||
public function iSeeThatIsNotMarkedAsFavorite($fileName) {
|
||||
Assert::assertNotNull($this->actor->find(self::notFavoritedStateIconForFile($this->fileListAncestor, $fileName), 10));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that :fileName has unread comments
|
||||
*/
|
||||
public function iSeeThatHasUnreadComments($fileName) {
|
||||
Assert::assertTrue($this->actor->find(self::commentActionForFile($this->fileListAncestor, $fileName), 10)->isVisible());
|
||||
}
|
||||
|
||||
private function waitForRowForFileToBeFullyOpaque($fileName) {
|
||||
$actor = $this->actor;
|
||||
$fileRowXpathExpression = $this->actor->find(self::rowForFile($this->fileListAncestor, $fileName), 10)->getWrappedElement()->getXpath();
|
||||
|
||||
$fileRowIsFullyOpaqueCallback = function () use ($actor, $fileRowXpathExpression) {
|
||||
$opacity = $actor->getSession()->evaluateScript("return window.getComputedStyle(document.evaluate(\"" . $fileRowXpathExpression . "\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue).opacity;");
|
||||
if ($opacity === "1") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
if (!Utils::waitFor($fileRowIsFullyOpaqueCallback, $timeout = 2 * $this->actor->getFindTimeoutMultiplier(), $timeoutStep = 1)) {
|
||||
Assert::fail("The row for file $fileName in file list is not fully opaque after $timeout seconds");
|
||||
}
|
||||
}
|
||||
|
||||
private function openFileActionsMenuForFile($fileName) {
|
||||
// When a row is added to the file list the opacity of the file row is
|
||||
// animated from transparent to fully opaque. As the file actions menu
|
||||
// is a descendant of the row but overflows it when the row is not fully
|
||||
// opaque clicks on the menu entries "fall-through" and are received
|
||||
// instead by the rows behind. Therefore it should be waited until the
|
||||
// row of the file is fully opaque before using the menu.
|
||||
$this->waitForRowForFileToBeFullyOpaque($fileName);
|
||||
|
||||
$this->actor->find(self::fileActionsMenuButtonForFile($this->fileListAncestor, $fileName), 10)->click();
|
||||
}
|
||||
}
|
@ -1,416 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
class FilesAppContext implements Context, ActorAwareInterface {
|
||||
use ActorAware;
|
||||
use FileListAncestorSetter;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function sections() {
|
||||
return [ "All files" => "files",
|
||||
"Recent" => "recent",
|
||||
"Favorites" => "favorites",
|
||||
"Shared with you" => "sharingin",
|
||||
"Shared with others" => "sharingout",
|
||||
"Shared by link" => "sharinglinks",
|
||||
"Tags" => "systemtagsfilter",
|
||||
"Deleted files" => "trashbin" ];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
private static function appMenu() {
|
||||
return Locator::forThe()->css("header nav.app-menu")->
|
||||
describedAs("App menu in header");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function filesItemInAppMenu() {
|
||||
return Locator::forThe()->xpath("//li[@data-app-id = 'files']")->
|
||||
descendantOf(self::appMenu())->
|
||||
describedAs("Files item in app menu in header");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function mainViewForSection($section) {
|
||||
$sectionId = self::sections()[$section];
|
||||
|
||||
return Locator::forThe()->id("app-content-$sectionId")->
|
||||
describedAs("Main view for section $section in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function currentSectionMainView() {
|
||||
return Locator::forThe()->xpath("//*[starts-with(@id, 'app-content-') and not(@id = 'app-content-vue') and not(contains(concat(' ', normalize-space(@class), ' '), ' hidden '))]")->
|
||||
describedAs("Current section main view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function detailsView() {
|
||||
return Locator::forThe()->xpath("//*[@id=\"app-sidebar\" or contains(@class, 'app-sidebar')]")->
|
||||
describedAs("Details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function closeDetailsViewButton() {
|
||||
return Locator::forThe()->css(".app-sidebar__close")->
|
||||
descendantOf(self::detailsView())->
|
||||
describedAs("Close details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function fileNameInDetailsView() {
|
||||
return Locator::forThe()->css(".app-sidebar-header__title")->
|
||||
descendantOf(self::detailsView())->
|
||||
describedAs("File name in details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function favoriteActionInFileDetailsInDetailsView() {
|
||||
return Locator::forThe()->css(".app-sidebar-header__star")->
|
||||
descendantOf(self::fileDetailsInDetailsView())->
|
||||
describedAs("Favorite action in file details in details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function notFavoritedStateIconInFileDetailsInDetailsView() {
|
||||
return Locator::forThe()->css(".star-outline-icon")->
|
||||
descendantOf(self::favoriteActionInFileDetailsInDetailsView())->
|
||||
describedAs("Not favorited state icon in file details in details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function favoritedStateIconInFileDetailsInDetailsView() {
|
||||
return Locator::forThe()->css(".star-icon")->
|
||||
descendantOf(self::favoriteActionInFileDetailsInDetailsView())->
|
||||
describedAs("Favorited state icon in file details in details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function fileDetailsInDetailsViewWithText($fileDetailsText) {
|
||||
return Locator::forThe()->xpath("//span[normalize-space() = '$fileDetailsText']")->
|
||||
descendantOf(self::fileDetailsInDetailsView())->
|
||||
describedAs("File details with text \"$fileDetailsText\" in details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
private static function fileDetailsInDetailsView() {
|
||||
return Locator::forThe()->css(".app-sidebar-header__desc")->
|
||||
descendantOf(self::detailsView())->
|
||||
describedAs("File details in details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function inputFieldForTagsInDetailsView() {
|
||||
return Locator::forThe()->css(".systemTagsInfoView")->
|
||||
descendantOf(self::detailsView())->
|
||||
describedAs("Input field for tags in details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function itemInInputFieldForTagsInDetailsViewForTag($tag) {
|
||||
return Locator::forThe()->xpath("//span[normalize-space() = '$tag']")->
|
||||
descendantOf(self::inputFieldForTagsInDetailsView())->
|
||||
describedAs("Item in input field for tags in details view for tag $tag in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function itemInDropdownForTag($tag) {
|
||||
return Locator::forThe()->xpath("//*[contains(concat(' ', normalize-space(@class), ' '), ' select2-result-label ')]//span[normalize-space() = '$tag']/ancestor::li")->
|
||||
descendantOf(self::select2Dropdown())->
|
||||
describedAs("Item in dropdown for tag $tag in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function checkmarkInItemInDropdownForTag($tag) {
|
||||
return Locator::forThe()->css(".checkmark")->
|
||||
descendantOf(self::itemInDropdownForTag($tag))->
|
||||
describedAs("Checkmark in item in dropdown for tag $tag in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
private static function select2Dropdown() {
|
||||
return Locator::forThe()->css("#select2-drop")->
|
||||
describedAs("Select2 dropdown in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function tabHeaderInDetailsViewNamed($tabHeaderName) {
|
||||
return Locator::forThe()->xpath("//span[contains(@class, 'app-sidebar-tabs__tab') and normalize-space() = '$tabHeaderName']")->
|
||||
descendantOf(self::tabHeadersInDetailsView())->
|
||||
describedAs("Tab header named $tabHeaderName in details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
private static function tabHeadersInDetailsView() {
|
||||
return Locator::forThe()->css(".app-sidebar-tabs__nav")->
|
||||
descendantOf(self::detailsView())->
|
||||
describedAs("Tab headers in details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function tabInDetailsViewNamed($tabName) {
|
||||
return Locator::forThe()->xpath("//div[contains(concat(' ', normalize-space(@class), ' '), ' app-sidebar-tabs__content ')]/section[@aria-labelledby = '$tabName' and @role = 'tabpanel']")->
|
||||
descendantOf(self::detailsView())->
|
||||
describedAs("Tab named $tabName in details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function loadingIconForTabInDetailsViewNamed($tabName) {
|
||||
return Locator::forThe()->css(".icon-loading")->
|
||||
descendantOf(self::tabInDetailsViewNamed($tabName))->
|
||||
describedAs("Loading icon for tab named $tabName in details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I open the Files app
|
||||
*/
|
||||
public function iOpenTheFilesApp() {
|
||||
$this->actor->find(self::filesItemInAppMenu(), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I close the details view
|
||||
*/
|
||||
public function iCloseTheDetailsView() {
|
||||
$this->actor->find(self::closeDetailsViewButton(), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I open the input field for tags in the details view
|
||||
*/
|
||||
public function iOpenTheInputFieldForTagsInTheDetailsView() {
|
||||
$this->actor->find(self::fileDetailsInDetailsViewWithText("Tags"), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I open the :tabName tab in the details view
|
||||
*/
|
||||
public function iOpenTheTabInTheDetailsView($tabName) {
|
||||
$this->actor->find(self::tabHeaderInDetailsViewNamed($tabName), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I mark the file as favorite in the details view
|
||||
*/
|
||||
public function iMarkTheFileAsFavoriteInTheDetailsView() {
|
||||
$this->iSeeThatTheFileIsNotMarkedAsFavoriteInTheDetailsView();
|
||||
|
||||
$this->actor->find(self::favoriteActionInFileDetailsInDetailsView(), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I unmark the file as favorite in the details view
|
||||
*/
|
||||
public function iUnmarkTheFileAsFavoriteInTheDetailsView() {
|
||||
$this->iSeeThatTheFileIsMarkedAsFavoriteInTheDetailsView();
|
||||
|
||||
$this->actor->find(self::favoriteActionInFileDetailsInDetailsView(), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I check the tag :tag in the dropdown for tags in the details view
|
||||
*/
|
||||
public function iCheckTheTagInTheDropdownForTagsInTheDetailsView($tag) {
|
||||
$this->iSeeThatTheTagInTheDropdownForTagsInTheDetailsViewIsNotChecked($tag);
|
||||
|
||||
$this->actor->find(self::itemInDropdownForTag($tag), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I uncheck the tag :tag in the dropdown for tags in the details view
|
||||
*/
|
||||
public function iUncheckTheTagInTheDropdownForTagsInTheDetailsView($tag) {
|
||||
$this->iSeeThatTheTagInTheDropdownForTagsInTheDetailsViewIsChecked($tag);
|
||||
|
||||
$this->actor->find(self::itemInDropdownForTag($tag), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the current page is the Files app
|
||||
*/
|
||||
public function iSeeThatTheCurrentPageIsTheFilesApp() {
|
||||
Assert::assertStringStartsWith(
|
||||
$this->actor->locatePath("/apps/files/"),
|
||||
$this->actor->getSession()->getCurrentUrl());
|
||||
|
||||
$this->setFileListAncestorForActor(self::currentSectionMainView(), $this->actor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the details view is open
|
||||
*/
|
||||
public function iSeeThatTheDetailsViewIsOpen() {
|
||||
// The sidebar always exists in the DOM, so it has to be explicitly
|
||||
// waited for it to be visible instead of relying on the implicit wait
|
||||
// made to find the element.
|
||||
if (!WaitFor::elementToBeEventuallyShown(
|
||||
$this->actor,
|
||||
self::detailsView(),
|
||||
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The details view is not open yet after $timeout seconds");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the details view is closed
|
||||
*/
|
||||
public function iSeeThatTheDetailsViewIsClosed() {
|
||||
if (!WaitFor::elementToBeEventuallyNotShown(
|
||||
$this->actor,
|
||||
self::detailsView(),
|
||||
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The details view is not closed yet after $timeout seconds");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the file name shown in the details view is :fileName
|
||||
*/
|
||||
public function iSeeThatTheFileNameShownInTheDetailsViewIs($fileName) {
|
||||
Assert::assertEquals(
|
||||
$this->actor->find(self::fileNameInDetailsView(), 10)->getText(), $fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the file is marked as favorite in the details view
|
||||
*/
|
||||
public function iSeeThatTheFileIsMarkedAsFavoriteInTheDetailsView() {
|
||||
Assert::assertNotNull(
|
||||
$this->actor->find(self::favoritedStateIconInFileDetailsInDetailsView(), 10));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the file is not marked as favorite in the details view
|
||||
*/
|
||||
public function iSeeThatTheFileIsNotMarkedAsFavoriteInTheDetailsView() {
|
||||
Assert::assertNotNull(
|
||||
$this->actor->find(self::notFavoritedStateIconInFileDetailsInDetailsView(), 10));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the input field for tags in the details view is shown
|
||||
*/
|
||||
public function iSeeThatTheInputFieldForTagsInTheDetailsViewIsShown() {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::inputFieldForTagsInDetailsView(), 10)->isVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the input field for tags in the details view contains the tag :tag
|
||||
*/
|
||||
public function iSeeThatTheInputFieldForTagsInTheDetailsViewContainsTheTag($tag) {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::itemInInputFieldForTagsInDetailsViewForTag($tag), 10)->isVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the input field for tags in the details view does not contain the tag :tag
|
||||
*/
|
||||
public function iSeeThatTheInputFieldForTagsInTheDetailsViewDoesNotContainTheTag($tag) {
|
||||
$this->iSeeThatTheInputFieldForTagsInTheDetailsViewIsShown();
|
||||
|
||||
try {
|
||||
Assert::assertFalse(
|
||||
$this->actor->find(self::itemInInputFieldForTagsInDetailsViewForTag($tag))->isVisible());
|
||||
} catch (NoSuchElementException $exception) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the tag :tag in the dropdown for tags in the details view is checked
|
||||
*/
|
||||
public function iSeeThatTheTagInTheDropdownForTagsInTheDetailsViewIsChecked($tag) {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::checkmarkInItemInDropdownForTag($tag), 10)->isVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the tag :tag in the dropdown for tags in the details view is not checked
|
||||
*/
|
||||
public function iSeeThatTheTagInTheDropdownForTagsInTheDetailsViewIsNotChecked($tag) {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::itemInDropdownForTag($tag), 10)->isVisible());
|
||||
|
||||
Assert::assertFalse(
|
||||
$this->actor->find(self::checkmarkInItemInDropdownForTag($tag))->isVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I see that the :tabName tab in the details view is eventually loaded
|
||||
*/
|
||||
public function iSeeThatTheTabInTheDetailsViewIsEventuallyLoaded($tabName) {
|
||||
if (!WaitFor::elementToBeEventuallyNotShown(
|
||||
$this->actor,
|
||||
self::loadingIconForTabInDetailsViewNamed($tabName),
|
||||
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The $tabName tab in the details view has not been loaded after $timeout seconds");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,811 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2018, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use PHPUnit\Framework\Assert;
|
||||
use WebDriver\Key;
|
||||
|
||||
class FilesAppSharingContext implements Context, ActorAwareInterface {
|
||||
use ActorAware;
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function sharedByLabel() {
|
||||
return Locator::forThe()->css(".sharing-entry__reshare")->
|
||||
descendantOf(FilesAppContext::detailsView())->
|
||||
describedAs("Shared by label in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function shareWithInput() {
|
||||
return Locator::forThe()->css(".sharing-search__input input")->
|
||||
descendantOf(FilesAppContext::detailsView())->
|
||||
describedAs("Share with input in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function shareWithInputResults() {
|
||||
return Locator::forThe()->css(".vs__dropdown-menu")->
|
||||
describedAs("Share with input results list in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function shareWithInputResult($result) {
|
||||
return Locator::forThe()->xpath("//li//span[normalize-space() = '$result']/ancestor::li")->
|
||||
descendantOf(self::shareWithInputResults())->
|
||||
describedAs("Share with input result from the results list in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function shareeList() {
|
||||
return Locator::forThe()->css(".sharing-sharee-list")->
|
||||
descendantOf(FilesAppContext::detailsView())->
|
||||
describedAs("Sharee list in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function sharedWithRow($sharedWithName) {
|
||||
// "username" class is used for any type of share, not only for shares
|
||||
// with users.
|
||||
return Locator::forThe()->xpath("//li[contains(concat(' ', normalize-space(@class), ' '), ' sharing-entry ')]//span[normalize-space() = '$sharedWithName']/ancestor::li")->
|
||||
descendantOf(self::shareeList())->
|
||||
describedAs("Shared with $sharedWithName row in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function shareWithMenuTrigger($sharedWithName) {
|
||||
return Locator::forThe()->css(".sharing-entry__actions button")->
|
||||
descendantOf(self::sharedWithRow($sharedWithName))->
|
||||
describedAs("Share with $sharedWithName menu trigger in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function shareWithMenuButton($sharedWithName) {
|
||||
return Locator::forThe()->css(".action-item__menutoggle")->
|
||||
descendantOf(self::shareWithMenuTrigger($sharedWithName))->
|
||||
describedAs("Share with $sharedWithName menu button in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function shareWithMenu($sharedWithName, $shareWithMenuTriggerElement) {
|
||||
return Locator::forThe()->xpath("//*[@id = " . $shareWithMenuTriggerElement->getWrappedElement()->getXpath() . "/@aria-describedby]")->
|
||||
describedAs("Share with $sharedWithName menu in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function permissionCheckboxFor($sharedWithName, $shareWithMenuTriggerElement, $itemText) {
|
||||
// forThe()->checkbox($itemText) can not be used here; that would return
|
||||
// the checkbox itself, but the element that the user interacts with is
|
||||
// the label.
|
||||
return Locator::forThe()->xpath("//label[normalize-space() = '$itemText']")->
|
||||
descendantOf(self::shareWithMenu($sharedWithName, $shareWithMenuTriggerElement))->
|
||||
describedAs("$itemText checkbox in the share with $sharedWithName menu in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function permissionCheckboxInputFor($sharedWithName, $shareWithMenuTriggerElement, $itemText) {
|
||||
return Locator::forThe()->checkbox($itemText)->
|
||||
descendantOf(self::shareWithMenu($sharedWithName, $shareWithMenuTriggerElement))->
|
||||
describedAs("$itemText checkbox input in the share with $sharedWithName menu in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function canEditCheckbox($sharedWithName, $shareWithMenuTriggerElement) {
|
||||
return self::permissionCheckboxFor($sharedWithName, $shareWithMenuTriggerElement, 'Allow editing');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function canEditCheckboxInput($sharedWithName, $shareWithMenuTriggerElement) {
|
||||
return self::permissionCheckboxInputFor($sharedWithName, $shareWithMenuTriggerElement, 'Allow editing');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function canCreateCheckbox($sharedWithName, $shareWithMenuTriggerElement) {
|
||||
return self::permissionCheckboxFor($sharedWithName, $shareWithMenuTriggerElement, 'Allow creating');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function canCreateCheckboxInput($sharedWithName, $shareWithMenuTriggerElement) {
|
||||
return self::permissionCheckboxInputFor($sharedWithName, $shareWithMenuTriggerElement, 'Allow creating');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function canReshareCheckbox($sharedWithName, $shareWithMenuTriggerElement) {
|
||||
return self::permissionCheckboxFor($sharedWithName, $shareWithMenuTriggerElement, 'Allow resharing');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function canReshareCheckboxInput($sharedWithName, $shareWithMenuTriggerElement) {
|
||||
return self::permissionCheckboxInputFor($sharedWithName, $shareWithMenuTriggerElement, 'Allow resharing');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function unshareButton($sharedWithName, $shareWithMenuTriggerElement) {
|
||||
return Locator::forThe()->xpath("//li[contains(concat(' ', normalize-space(@class), ' '), ' action ')]//button[normalize-space() = 'Unshare']")->
|
||||
descendantOf(self::shareWithMenu($sharedWithName, $shareWithMenuTriggerElement))->
|
||||
describedAs("Unshare button in the share with $sharedWithName menu in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function shareLinkRow() {
|
||||
return Locator::forThe()->css(".sharing-link-list .sharing-entry__link:first-child")->
|
||||
descendantOf(FilesAppContext::detailsView())->
|
||||
describedAs("Share link row in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function shareLinkAddNewButton() {
|
||||
// When there is no link share the "Add new share" item is shown instead
|
||||
// of the menu button as a direct child of ".share-menu".
|
||||
return Locator::forThe()->css(".action-item.new-share-link")->
|
||||
descendantOf(self::shareLinkRow())->
|
||||
describedAs("Add new share link button in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function copyLinkButton() {
|
||||
return Locator::forThe()->css("a.sharing-entry__copy")->
|
||||
descendantOf(self::shareLinkRow())->
|
||||
describedAs("Copy link button in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function shareLinkMenuTrigger() {
|
||||
return Locator::forThe()->css(".sharing-entry__actions .action-item__menutoggle")->
|
||||
descendantOf(self::shareLinkRow())->
|
||||
describedAs("Share link menu trigger in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function shareLinkSingleUnshareAction() {
|
||||
return Locator::forThe()->css(".sharing-entry__actions.icon-close")->
|
||||
descendantOf(self::shareLinkRow())->
|
||||
describedAs("Unshare link single action in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function shareLinkMenuButton() {
|
||||
return Locator::forThe()->css(".action-item__menutoggle")->
|
||||
descendantOf(self::shareLinkMenuTrigger())->
|
||||
describedAs("Share link menu button in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function shareLinkMenu($shareLinkMenuTriggerElement) {
|
||||
return Locator::forThe()->xpath("//*[@id = " . $shareLinkMenuTriggerElement->getWrappedElement()->getXpath() . "/@aria-describedby]")->
|
||||
describedAs("Share link menu in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function hideDownloadCheckbox($shareLinkMenuTriggerElement) {
|
||||
// forThe()->checkbox("Hide download") can not be used here; that would
|
||||
// return the checkbox itself, but the element that the user interacts
|
||||
// with is the label.
|
||||
return Locator::forThe()->xpath("//label[normalize-space() = 'Hide download']")->
|
||||
descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))->
|
||||
describedAs("Hide download checkbox in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function hideDownloadCheckboxInput($shareLinkMenuTriggerElement) {
|
||||
return Locator::forThe()->checkbox("Hide download")->
|
||||
descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))->
|
||||
describedAs("Hide download checkbox input in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function allowUploadAndEditingRadioButton($shareLinkMenuTriggerElement) {
|
||||
// forThe()->radio("Allow upload and editing") can not be used here;
|
||||
// that would return the radio button itself, but the element that the
|
||||
// user interacts with is the label.
|
||||
return Locator::forThe()->xpath("//label[normalize-space() = 'Allow upload and editing']")->
|
||||
descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))->
|
||||
describedAs("Allow upload and editing radio button in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function passwordProtectCheckbox($shareLinkMenuTriggerElement) {
|
||||
// forThe()->checkbox("Password protect") can not be used here; that
|
||||
// would return the checkbox itself, but the element that the user
|
||||
// interacts with is the label.
|
||||
return Locator::forThe()->xpath("//label[normalize-space() = 'Password protect']")->
|
||||
descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))->
|
||||
describedAs("Password protect checkbox in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function passwordProtectCheckboxInput($shareLinkMenuTriggerElement) {
|
||||
return Locator::forThe()->checkbox("Password protect")->
|
||||
descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))->
|
||||
describedAs("Password protect checkbox input in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function passwordProtectField($shareLinkMenuTriggerElement) {
|
||||
return Locator::forThe()->css(".share-link-password input.input-field__input")->descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))->
|
||||
describedAs("Password protect field in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function disabledPasswordProtectField($shareLinkMenuTriggerElement) {
|
||||
return Locator::forThe()->css(".share-link-password input.input-field__input[disabled]")->descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))->
|
||||
describedAs("Disabled password protect field in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function passwordProtectByTalkCheckbox($shareLinkMenuTriggerElement) {
|
||||
// forThe()->checkbox("Password protect by Talk") can not be used here;
|
||||
// that would return the checkbox itself, but the element that the user
|
||||
// interacts with is the label.
|
||||
return Locator::forThe()->xpath("//label[normalize-space() = 'Password protect by Talk']")->
|
||||
descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))->
|
||||
describedAs("Password protect by Talk checkbox in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function passwordProtectByTalkCheckboxInput($shareLinkMenuTriggerElement) {
|
||||
return Locator::forThe()->checkbox("Password protect by Talk")->
|
||||
descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))->
|
||||
describedAs("Password protect by Talk checkbox input in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function unshareLinkButton($shareLinkMenuTriggerElement) {
|
||||
return Locator::forThe()->xpath("//li[contains(concat(' ', normalize-space(@class), ' '), ' action ')]//button[normalize-space() = 'Unshare']")->
|
||||
descendantOf(self::shareLinkMenu($shareLinkMenuTriggerElement))->
|
||||
describedAs("Unshare link button in the details view in Files app");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I share the link for :fileName
|
||||
*/
|
||||
public function iShareTheLinkFor($fileName) {
|
||||
$this->actor->find(FileListContext::shareActionForFile(FilesAppContext::currentSectionMainView(), $fileName), 10)->click();
|
||||
|
||||
$this->actor->find(self::shareLinkAddNewButton(), 5)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I share :fileName with :shareWithName
|
||||
*/
|
||||
public function iShareWith($fileName, $shareWithName) {
|
||||
$this->actor->find(FileListContext::shareActionForFile(FilesAppContext::currentSectionMainView(), $fileName), 10)->click();
|
||||
|
||||
$this->actor->find(self::shareWithInput(), 5)->setValue($shareWithName);
|
||||
// "setValue()" ends sending a tab, which unfocuses the input and causes
|
||||
// the results to be hidden, so the input needs to be clicked to show
|
||||
// the results again.
|
||||
$this->actor->find(self::shareWithInput())->click();
|
||||
$this->actor->find(self::shareWithInputResult($shareWithName), 5)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I write down the shared link
|
||||
*/
|
||||
public function iWriteDownTheSharedLink() {
|
||||
$shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 2);
|
||||
|
||||
// Close the share link menu if it is open to ensure that it does not
|
||||
// cover the copy link button.
|
||||
if (!WaitFor::elementToBeEventuallyNotShown(
|
||||
$this->actor,
|
||||
self::shareLinkMenu($shareLinkMenuTriggerElement),
|
||||
$timeout = 2 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
// It may not be possible to click on the menu button (due to the
|
||||
// menu itself covering it), so "Enter" key is pressed instead.
|
||||
$this->actor->find(self::shareLinkMenuButton(), 2)->getWrappedElement()->keyPress(13);
|
||||
}
|
||||
|
||||
$this->actor->find(self::copyLinkButton(), 10)->click();
|
||||
|
||||
// Clicking on the menu item copies the link to the clipboard, but it is
|
||||
// not possible to access that value from the acceptance tests. Due to
|
||||
// this the value of the attribute that holds the URL is used instead.
|
||||
$this->actor->getSharedNotebook()["shared link"] = $this->actor->find(self::copyLinkButton(), 2)->getWrappedElement()->getAttribute("href");
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I set the download of the shared link as hidden
|
||||
*/
|
||||
public function iSetTheDownloadOfTheSharedLinkAsHidden() {
|
||||
$this->showShareLinkMenuIfNeeded();
|
||||
|
||||
$this->iSeeThatTheDownloadOfTheLinkShareIsShown();
|
||||
|
||||
$shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 2);
|
||||
$this->actor->find(self::hideDownloadCheckbox($shareLinkMenuTriggerElement), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I set the download of the shared link as shown
|
||||
*/
|
||||
public function iSetTheDownloadOfTheSharedLinkAsShown() {
|
||||
$this->showShareLinkMenuIfNeeded();
|
||||
|
||||
$this->iSeeThatTheDownloadOfTheLinkShareIsHidden();
|
||||
|
||||
$shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 2);
|
||||
$this->actor->find(self::hideDownloadCheckbox($shareLinkMenuTriggerElement), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I set the shared link as editable
|
||||
*/
|
||||
public function iSetTheSharedLinkAsEditable() {
|
||||
$this->showShareLinkMenuIfNeeded();
|
||||
|
||||
$shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 2);
|
||||
$this->actor->find(self::allowUploadAndEditingRadioButton($shareLinkMenuTriggerElement), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I protect the shared link with the password :password
|
||||
*/
|
||||
public function iProtectTheSharedLinkWithThePassword($password) {
|
||||
$this->showShareLinkMenuIfNeeded();
|
||||
|
||||
$shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 2);
|
||||
$this->actor->find(self::passwordProtectCheckbox($shareLinkMenuTriggerElement), 2)->click();
|
||||
|
||||
$this->actor->find(self::passwordProtectField($shareLinkMenuTriggerElement), 2)->setValue($password . Key::ENTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I set the password of the shared link as protected by Talk
|
||||
*/
|
||||
public function iSetThePasswordOfTheSharedLinkAsProtectedByTalk() {
|
||||
$this->showShareLinkMenuIfNeeded();
|
||||
|
||||
$this->iSeeThatThePasswordOfTheLinkShareIsNotProtectedByTalk();
|
||||
|
||||
$shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 2);
|
||||
$this->actor->find(self::passwordProtectByTalkCheckbox($shareLinkMenuTriggerElement), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I set the password of the shared link as not protected by Talk
|
||||
*/
|
||||
public function iSetThePasswordOfTheSharedLinkAsNotProtectedByTalk() {
|
||||
$this->showShareLinkMenuIfNeeded();
|
||||
|
||||
$this->iSeeThatThePasswordOfTheLinkShareIsProtectedByTalk();
|
||||
|
||||
$shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 2);
|
||||
$this->actor->find(self::passwordProtectByTalkCheckbox($shareLinkMenuTriggerElement), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I set the share with :shareWithName as not editable
|
||||
*/
|
||||
public function iSetTheShareWithAsNotEditable($shareWithName) {
|
||||
$this->showShareWithMenuIfNeeded($shareWithName);
|
||||
|
||||
$this->iSeeThatCanEditTheShare($shareWithName);
|
||||
|
||||
$shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($shareWithName), 2);
|
||||
$this->actor->find(self::canEditCheckbox($shareWithName, $shareWithMenuTriggerElement), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I set the share with :shareWithName as not creatable
|
||||
*/
|
||||
public function iSetTheShareWithAsNotCreatable($shareWithName) {
|
||||
$this->showShareWithMenuIfNeeded($shareWithName);
|
||||
|
||||
$this->iSeeThatCanCreateInTheShare($shareWithName);
|
||||
|
||||
$shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($shareWithName), 2);
|
||||
$this->actor->find(self::canCreateCheckbox($shareWithName, $shareWithMenuTriggerElement), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I set the share with :shareWithName as not reshareable
|
||||
*/
|
||||
public function iSetTheShareWithAsNotReshareable($shareWithName) {
|
||||
$this->showShareWithMenuIfNeeded($shareWithName);
|
||||
|
||||
$this->iSeeThatCanReshareTheShare($shareWithName);
|
||||
|
||||
$shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($shareWithName), 2);
|
||||
$this->actor->find(self::canReshareCheckbox($shareWithName, $shareWithMenuTriggerElement), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I unshare the share with :shareWithName
|
||||
*/
|
||||
public function iUnshareTheFileWith($shareWithName) {
|
||||
$this->showShareWithMenuIfNeeded($shareWithName);
|
||||
|
||||
$shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($shareWithName), 2);
|
||||
$this->actor->find(self::unshareButton($shareWithName, $shareWithMenuTriggerElement), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I unshare the link share
|
||||
*/
|
||||
public function iUnshareTheLink() {
|
||||
try {
|
||||
$this->actor->find(self::shareLinkSingleUnshareAction(), 2)->click();
|
||||
} catch (NoSuchElementException $e) {
|
||||
$this->showShareLinkMenuIfNeeded();
|
||||
$shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 2);
|
||||
$this->actor->find(self::unshareLinkButton($shareLinkMenuTriggerElement), 2)->click();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the file is shared with me by :sharedByName
|
||||
*/
|
||||
public function iSeeThatTheFileIsSharedWithMeBy($sharedByName) {
|
||||
Assert::assertEquals(
|
||||
$this->actor->find(self::sharedByLabel(), 10)->getText(), "Shared with you by $sharedByName");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the file is shared with :sharedWithName
|
||||
*/
|
||||
public function iSeeThatTheFileIsSharedWith($sharedWithName) {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::sharedWithRow($sharedWithName), 10)->isVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the file is not shared with :sharedWithName
|
||||
*/
|
||||
public function iSeeThatTheFileIsNotSharedWith($sharedWithName) {
|
||||
if (!WaitFor::elementToBeEventuallyNotShown(
|
||||
$this->actor,
|
||||
self::sharedWithRow($sharedWithName),
|
||||
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The shared with $sharedWithName row is still shown after $timeout seconds");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that resharing the file is not allowed
|
||||
*/
|
||||
public function iSeeThatResharingTheFileIsNotAllowed() {
|
||||
Assert::assertEquals(
|
||||
$this->actor->find(self::shareWithInput(), 10)->getWrappedElement()->getAttribute("disabled"), "disabled");
|
||||
Assert::assertEquals(
|
||||
$this->actor->find(self::shareWithInput(), 10)->getWrappedElement()->getAttribute("placeholder"), "Resharing is not allowed");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that resharing the file by link is not available
|
||||
*/
|
||||
public function iSeeThatResharingTheFileByLinkIsNotAvailable() {
|
||||
if (!WaitFor::elementToBeEventuallyNotShown(
|
||||
$this->actor,
|
||||
self::shareLinkAddNewButton(),
|
||||
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The add new share link button is still shown after $timeout seconds");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that :sharedWithName can not be allowed to edit the share
|
||||
*/
|
||||
public function iSeeThatCanNotBeAllowedToEditTheShare($sharedWithName) {
|
||||
$this->showShareWithMenuIfNeeded($sharedWithName);
|
||||
|
||||
$shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($sharedWithName), 10);
|
||||
Assert::assertEquals(
|
||||
$this->actor->find(self::canEditCheckboxInput($sharedWithName, $shareWithMenuTriggerElement), 10)->getWrappedElement()->getAttribute("disabled"), "disabled");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that :sharedWithName can edit the share
|
||||
*/
|
||||
public function iSeeThatCanEditTheShare($sharedWithName) {
|
||||
$this->showShareWithMenuIfNeeded($sharedWithName);
|
||||
|
||||
$shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($sharedWithName), 10);
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::canEditCheckboxInput($sharedWithName, $shareWithMenuTriggerElement), 10)->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that :sharedWithName can not edit the share
|
||||
*/
|
||||
public function iSeeThatCanNotEditTheShare($sharedWithName) {
|
||||
$this->showShareWithMenuIfNeeded($sharedWithName);
|
||||
|
||||
$shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($sharedWithName), 10);
|
||||
Assert::assertFalse(
|
||||
$this->actor->find(self::canEditCheckboxInput($sharedWithName, $shareWithMenuTriggerElement), 10)->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that :sharedWithName can not be allowed to create in the share
|
||||
*/
|
||||
public function iSeeThatCanNotBeAllowedToCreateInTheShare($sharedWithName) {
|
||||
$this->showShareWithMenuIfNeeded($sharedWithName);
|
||||
|
||||
$shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($sharedWithName), 10);
|
||||
Assert::assertEquals(
|
||||
$this->actor->find(self::canCreateCheckboxInput($sharedWithName, $shareWithMenuTriggerElement), 10)->getWrappedElement()->getAttribute("disabled"), "disabled");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that :sharedWithName can create in the share
|
||||
*/
|
||||
public function iSeeThatCanCreateInTheShare($sharedWithName) {
|
||||
$this->showShareWithMenuIfNeeded($sharedWithName);
|
||||
|
||||
$shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($sharedWithName), 10);
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::canCreateCheckboxInput($sharedWithName, $shareWithMenuTriggerElement), 10)->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that :sharedWithName can not create in the share
|
||||
*/
|
||||
public function iSeeThatCanNotCreateInTheShare($sharedWithName) {
|
||||
$this->showShareWithMenuIfNeeded($sharedWithName);
|
||||
|
||||
$shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($sharedWithName), 10);
|
||||
Assert::assertFalse(
|
||||
$this->actor->find(self::canCreateCheckboxInput($sharedWithName, $shareWithMenuTriggerElement), 10)->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that resharing for :sharedWithName is not available
|
||||
*/
|
||||
public function iSeeThatResharingForIsNotAvailable($sharedWithName) {
|
||||
$this->showShareWithMenuIfNeeded($sharedWithName);
|
||||
|
||||
$shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($sharedWithName), 10);
|
||||
if (!WaitFor::elementToBeEventuallyNotShown(
|
||||
$this->actor,
|
||||
self::canReshareCheckbox($sharedWithName, $shareWithMenuTriggerElement),
|
||||
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The resharing checkbox for $sharedWithName is still shown after $timeout seconds");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that :sharedWithName can reshare the share
|
||||
*/
|
||||
public function iSeeThatCanReshareTheShare($sharedWithName) {
|
||||
$this->showShareWithMenuIfNeeded($sharedWithName);
|
||||
|
||||
$shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($sharedWithName), 10);
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::canReshareCheckboxInput($sharedWithName, $shareWithMenuTriggerElement), 10)->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that :sharedWithName can not reshare the share
|
||||
*/
|
||||
public function iSeeThatCanNotReshareTheShare($sharedWithName) {
|
||||
$this->showShareWithMenuIfNeeded($sharedWithName);
|
||||
|
||||
$shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($sharedWithName), 10);
|
||||
Assert::assertFalse(
|
||||
$this->actor->find(self::canReshareCheckboxInput($sharedWithName, $shareWithMenuTriggerElement), 10)->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the download of the link share is hidden
|
||||
*/
|
||||
public function iSeeThatTheDownloadOfTheLinkShareIsHidden() {
|
||||
$this->showShareLinkMenuIfNeeded();
|
||||
|
||||
$shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 10);
|
||||
Assert::assertTrue($this->actor->find(self::hideDownloadCheckboxInput($shareLinkMenuTriggerElement), 10)->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the download of the link share is shown
|
||||
*/
|
||||
public function iSeeThatTheDownloadOfTheLinkShareIsShown() {
|
||||
$this->showShareLinkMenuIfNeeded();
|
||||
|
||||
$shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 10);
|
||||
Assert::assertFalse($this->actor->find(self::hideDownloadCheckboxInput($shareLinkMenuTriggerElement), 10)->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the password protect is disabled while loading
|
||||
*/
|
||||
public function iSeeThatThePasswordProtectIsDisabledWhileLoading() {
|
||||
// Due to the additional time needed to find the menu trigger element it
|
||||
// could happen that the request to modify the password protect was
|
||||
// completed and the field enabled again even before finding the
|
||||
// disabled field started. Therefore, if the disabled field could not be
|
||||
// found it is just assumed that it was already enabled again.
|
||||
// Nevertheless, this check should be done anyway to ensure that the
|
||||
// following scenario steps are not executed before the request to the
|
||||
// server was done.
|
||||
$shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 10);
|
||||
|
||||
try {
|
||||
$this->actor->find(self::disabledPasswordProtectField($shareLinkMenuTriggerElement), 5);
|
||||
} catch (NoSuchElementException $exception) {
|
||||
echo "The password protect field was not found disabled after " . (5 * $this->actor->getFindTimeoutMultiplier()) . " seconds, assumming that it was disabled and enabled again before the check started and continuing";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!WaitFor::elementToBeEventuallyNotShown(
|
||||
$this->actor,
|
||||
self::disabledPasswordProtectField($shareLinkMenuTriggerElement),
|
||||
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The password protect field is still disabled after $timeout seconds");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the link share is password protected
|
||||
*/
|
||||
public function iSeeThatTheLinkShareIsPasswordProtected() {
|
||||
$this->showShareLinkMenuIfNeeded();
|
||||
|
||||
$shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 10);
|
||||
Assert::assertTrue($this->actor->find(self::passwordProtectCheckboxInput($shareLinkMenuTriggerElement), 10)->isChecked(), "Password protect checkbox is checked");
|
||||
Assert::assertTrue($this->actor->find(self::passwordProtectField($shareLinkMenuTriggerElement), 10)->isVisible(), "Password protect field is visible");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the password of the link share is protected by Talk
|
||||
*/
|
||||
public function iSeeThatThePasswordOfTheLinkShareIsProtectedByTalk() {
|
||||
$this->showShareLinkMenuIfNeeded();
|
||||
|
||||
$shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 10);
|
||||
Assert::assertTrue($this->actor->find(self::passwordProtectByTalkCheckboxInput($shareLinkMenuTriggerElement), 10)->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the password of the link share is not protected by Talk
|
||||
*/
|
||||
public function iSeeThatThePasswordOfTheLinkShareIsNotProtectedByTalk() {
|
||||
$this->showShareLinkMenuIfNeeded();
|
||||
|
||||
$shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 10);
|
||||
Assert::assertFalse($this->actor->find(self::passwordProtectByTalkCheckboxInput($shareLinkMenuTriggerElement), 10)->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the checkbox to protect the password of the link share by Talk is not shown
|
||||
*/
|
||||
public function iSeeThatTheCheckboxToProtectThePasswordOfTheLinkShareByTalkIsNotShown() {
|
||||
$this->showShareLinkMenuIfNeeded();
|
||||
|
||||
$shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 10);
|
||||
try {
|
||||
Assert::assertFalse(
|
||||
$this->actor->find(self::passwordProtectByTalkCheckbox($shareLinkMenuTriggerElement))->isVisible());
|
||||
} catch (NoSuchElementException $exception) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I share the link for :fileName protected by the password :password
|
||||
*/
|
||||
public function iShareTheLinkForProtectedByThePassword($fileName, $password) {
|
||||
$this->iShareTheLinkFor($fileName);
|
||||
$this->iProtectTheSharedLinkWithThePassword($password);
|
||||
$this->iSeeThatThePasswordProtectIsDisabledWhileLoading();
|
||||
}
|
||||
|
||||
private function showShareLinkMenuIfNeeded() {
|
||||
$shareLinkMenuTriggerElement = $this->actor->find(self::shareLinkMenuTrigger(), 2);
|
||||
|
||||
// In some cases the share menu is hidden after clicking on an action of
|
||||
// the menu. Therefore, if the menu is visible, wait a little just in
|
||||
// case it is in the process of being hidden due to a previous action,
|
||||
// in which case it is shown again.
|
||||
if (WaitFor::elementToBeEventuallyNotShown(
|
||||
$this->actor,
|
||||
self::shareLinkMenu($shareLinkMenuTriggerElement),
|
||||
$timeout = 2 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
$this->actor->find(self::shareLinkMenuButton(), 10)->click();
|
||||
}
|
||||
}
|
||||
|
||||
private function showShareWithMenuIfNeeded($shareWithName) {
|
||||
$shareWithMenuTriggerElement = $this->actor->find(self::shareWithMenuTrigger($shareWithName), 2);
|
||||
|
||||
// In some cases the share menu is hidden after clicking on an action of
|
||||
// the menu. Therefore, if the menu is visible, wait a little just in
|
||||
// case it is in the process of being hidden due to a previous action,
|
||||
// in which case it is shown again.
|
||||
if (WaitFor::elementToBeEventuallyNotShown(
|
||||
$this->actor,
|
||||
self::shareWithMenu($shareWithName, $shareWithMenuTriggerElement),
|
||||
$timeout = 2 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
$this->actor->find(self::shareWithMenuButton($shareWithName), 10)->click();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2019, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
|
||||
class NotificationsContext implements Context, ActorAwareInterface {
|
||||
use ActorAware;
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function notificationsButton() {
|
||||
return Locator::forThe()->css("#header #notifications.notifications-button")->
|
||||
describedAs("Notifications button in the header");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function notificationsContainer() {
|
||||
return Locator::forThe()->css("#header #notifications .notification-container")->
|
||||
describedAs("Notifications container");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function incomingShareNotificationForFile($fileName) {
|
||||
return Locator::forThe()->xpath("//li[contains(concat(' ', normalize-space(@class), ' '), ' notification ') and //div[starts-with(normalize-space(), 'You received $fileName as a share by')]]")->
|
||||
descendantOf(self::notificationsContainer())->
|
||||
describedAs("Notification of incoming share for file $fileName");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function actionsInIncomingShareNotificationForFile($fileName) {
|
||||
return Locator::forThe()->css(".notification-actions")->
|
||||
descendantOf(self::incomingShareNotificationForFile($fileName))->
|
||||
describedAs("Actions in notification of incoming share for file $fileName");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function actionInIncomingShareNotificationForFile($fileName, $action) {
|
||||
return Locator::forThe()->xpath("//button[normalize-space() = '$action']")->
|
||||
descendantOf(self::actionsInIncomingShareNotificationForFile($fileName))->
|
||||
describedAs("$action button in notification of incoming share for file $fileName");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function acceptButtonInIncomingShareNotificationForFile($fileName) {
|
||||
return self::actionInIncomingShareNotificationForFile($fileName, 'Accept');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I accept the share for :fileName in the notifications
|
||||
*/
|
||||
public function iAcceptTheShareForInTheNotifications($fileName) {
|
||||
$this->actor->find(self::notificationsButton(), 10)->click();
|
||||
|
||||
// Notifications are refreshed every 30 seconds, so wait a bit longer.
|
||||
// As the waiting is long enough already the find timeout multiplier is
|
||||
// capped at 2 when finding notifications.
|
||||
$findTimeoutMultiplier = $this->actor->getFindTimeoutMultiplier();
|
||||
$this->actor->setFindTimeoutMultiplier(min(2, $findTimeoutMultiplier));
|
||||
$this->actor->find(self::acceptButtonInIncomingShareNotificationForFile($fileName), 35)->click();
|
||||
$this->actor->setFindTimeoutMultiplier($findTimeoutMultiplier);
|
||||
|
||||
// Hide the notifications again
|
||||
$this->actor->find(self::notificationsButton(), 10)->click();
|
||||
}
|
||||
}
|
@ -1,253 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
class PublicShareContext implements Context, ActorAwareInterface {
|
||||
use ActorAware;
|
||||
use FileListAncestorSetter;
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function passwordField() {
|
||||
return Locator::forThe()->field("password")->
|
||||
describedAs("Password field in Authenticate page");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function authenticateButton() {
|
||||
return Locator::forThe()->id("password-submit")->
|
||||
describedAs("Authenticate button in Authenticate page");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function wrongPasswordMessage() {
|
||||
return Locator::forThe()->css(".warning .wrongPasswordMsg")->
|
||||
describedAs("Wrong password message in Authenticate page");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function shareMenuButton() {
|
||||
return Locator::forThe()->id("header-actions-toggle")->
|
||||
describedAs("Share menu button in Shared file page");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function shareMenu() {
|
||||
return Locator::forThe()->id("header-actions-menu")->
|
||||
describedAs("Share menu in Shared file page");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function downloadItemInShareMenu() {
|
||||
return Locator::forThe()->id("download")->
|
||||
descendantOf(self::shareMenu())->
|
||||
describedAs("Download item in Share menu in Shared file page");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function directLinkItemInShareMenu() {
|
||||
return Locator::forThe()->id("directLink-container")->
|
||||
descendantOf(self::shareMenu())->
|
||||
describedAs("Direct link item in Share menu in Shared file page");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function saveItemInShareMenu() {
|
||||
return Locator::forThe()->id("save-external-share")->
|
||||
descendantOf(self::shareMenu())->
|
||||
describedAs("Save item in Share menu in Shared file page");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function textPreview() {
|
||||
return Locator::forThe()->css(".text-preview")->
|
||||
describedAs("Text preview in Shared file page");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function downloadButton() {
|
||||
return Locator::forThe()->id("downloadFile")->
|
||||
describedAs("Download button in Shared file page");
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I visit the shared link I wrote down
|
||||
*/
|
||||
public function iVisitTheSharedLinkIWroteDown() {
|
||||
$this->actor->getSession()->visit($this->actor->getSharedNotebook()["shared link"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I visit the direct download shared link I wrote down
|
||||
*/
|
||||
public function iVisitTheDirectDownloadSharedLinkIWroteDown() {
|
||||
$this->actor->getSession()->visit($this->actor->getSharedNotebook()["shared link"] . "/download");
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I authenticate with password :password
|
||||
*/
|
||||
public function iAuthenticateWithPassword($password) {
|
||||
$this->actor->find(self::passwordField(), 10)->setValue($password);
|
||||
$this->actor->find(self::authenticateButton())->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I open the Share menu
|
||||
*/
|
||||
public function iOpenTheShareMenu() {
|
||||
$this->actor->find(self::shareMenuButton(), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the current page is the Authenticate page for the shared link I wrote down
|
||||
*/
|
||||
public function iSeeThatTheCurrentPageIsTheAuthenticatePageForTheSharedLinkIWroteDown() {
|
||||
Assert::assertEquals(
|
||||
$this->actor->getSharedNotebook()["shared link"] . "/authenticate/showShare",
|
||||
$this->actor->getSession()->getCurrentUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the current page is the Authenticate page for the direct download shared link I wrote down
|
||||
*/
|
||||
public function iSeeThatTheCurrentPageIsTheAuthenticatePageForTheDirectDownloadSharedLinkIWroteDown() {
|
||||
Assert::assertEquals(
|
||||
$this->actor->getSharedNotebook()["shared link"] . "/authenticate/downloadShare",
|
||||
$this->actor->getSession()->getCurrentUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the current page is the shared link I wrote down
|
||||
*/
|
||||
public function iSeeThatTheCurrentPageIsTheSharedLinkIWroteDown() {
|
||||
Assert::assertEquals(
|
||||
$this->actor->getSharedNotebook()["shared link"],
|
||||
$this->actor->getSession()->getCurrentUrl());
|
||||
|
||||
$this->setFileListAncestorForActor(null, $this->actor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the current page is the direct download shared link I wrote down
|
||||
*/
|
||||
public function iSeeThatTheCurrentPageIsTheDirectDownloadSharedLinkIWroteDown() {
|
||||
Assert::assertEquals(
|
||||
$this->actor->getSharedNotebook()["shared link"] . "/download",
|
||||
$this->actor->getSession()->getCurrentUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that a wrong password for the shared file message is shown
|
||||
*/
|
||||
public function iSeeThatAWrongPasswordForTheSharedFileMessageIsShown() {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::wrongPasswordMessage(), 10)->isVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the Share menu is shown
|
||||
*/
|
||||
public function iSeeThatTheShareMenuIsShown() {
|
||||
// Unlike other menus, the Share menu is always present in the DOM, so
|
||||
// the element could be found when it was no made visible yet due to the
|
||||
// command not having been processed by the browser.
|
||||
if (!WaitFor::elementToBeEventuallyShown(
|
||||
$this->actor, self::shareMenu(), $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The Share menu is not visible yet after $timeout seconds");
|
||||
}
|
||||
|
||||
// The acceptance tests are run in a window wider than the mobile breakpoint, so the
|
||||
// download item should not be shown in the menu (although it will be in
|
||||
// the DOM).
|
||||
Assert::assertFalse(
|
||||
$this->actor->find(self::downloadItemInShareMenu())->isVisible(),
|
||||
"Download item in share menu is visible");
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::directLinkItemInShareMenu())->isVisible(),
|
||||
"Direct link item in share menu is not visible");
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::saveItemInShareMenu())->isVisible(),
|
||||
"Save item in share menu is not visible");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the Share menu button is not shown
|
||||
*/
|
||||
public function iSeeThatTheShareMenuButtonIsNotShown() {
|
||||
try {
|
||||
Assert::assertFalse(
|
||||
$this->actor->find(self::shareMenuButton())->isVisible());
|
||||
} catch (NoSuchElementException $exception) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the shared file preview shows the text :text
|
||||
*/
|
||||
public function iSeeThatTheSharedFilePreviewShowsTheText($text) {
|
||||
Assert::assertStringContainsString($text, $this->actor->find(self::textPreview(), 10)->getText());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the download button is shown
|
||||
*/
|
||||
public function iSeeThatTheDownloadButtonIsShown() {
|
||||
if (!WaitFor::elementToBeEventuallyShown(
|
||||
$this->actor, self::downloadButton(), $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
|
||||
Assert::fail("The download button is not visible yet after $timeout seconds");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the download button is not shown
|
||||
*/
|
||||
public function iSeeThatTheDownloadButtonIsNotShown() {
|
||||
try {
|
||||
Assert::assertFalse(
|
||||
$this->actor->find(self::downloadButton())->isVisible());
|
||||
} catch (NoSuchElementException $exception) {
|
||||
}
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2018, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
class SearchContext implements Context, ActorAwareInterface {
|
||||
use ActorAware;
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function searchBoxInput() {
|
||||
return Locator::forThe()->css("#header .searchbox input")->
|
||||
describedAs("Search box input in the header");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function searchResults() {
|
||||
return Locator::forThe()->css("#searchresults")->
|
||||
describedAs("Search results");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function searchResult($number) {
|
||||
return Locator::forThe()->xpath("//*[contains(concat(' ', normalize-space(@class), ' '), ' result ')][$number]")->
|
||||
descendantOf(self::searchResults())->
|
||||
describedAs("Search result $number");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function searchResultName($number) {
|
||||
return Locator::forThe()->css(".name")->
|
||||
descendantOf(self::searchResult($number))->
|
||||
describedAs("Name for search result $number");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function searchResultPath($number) {
|
||||
// Currently search results for comments misuse the ".path" class to
|
||||
// dim the user name, so "div.path" needs to be used to find the proper
|
||||
// path element.
|
||||
return Locator::forThe()->css("div.path")->
|
||||
descendantOf(self::searchResult($number))->
|
||||
describedAs("Path for search result $number");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function searchResultLink($number) {
|
||||
return Locator::forThe()->css(".link")->
|
||||
descendantOf(self::searchResult($number))->
|
||||
describedAs("Link for search result $number");
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I search for :query
|
||||
*/
|
||||
public function iSearchFor($query) {
|
||||
$this->actor->find(self::searchBoxInput(), 10)->setValue($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I open the search result :number
|
||||
*/
|
||||
public function iOpenTheSearchResult($number) {
|
||||
$this->actor->find(self::searchResultLink($number), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the search result :number is :name
|
||||
*/
|
||||
public function iSeeThatTheSearchResultIs($number, $name) {
|
||||
Assert::assertEquals(
|
||||
$name, $this->actor->find(self::searchResultName($number), 10)->getText());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the search result :number was found in :path
|
||||
*/
|
||||
public function iSeeThatTheSearchResultWasFoundIn($number, $path) {
|
||||
Assert::assertEquals(
|
||||
$path, $this->actor->find(self::searchResultPath($number), 10)->getText());
|
||||
}
|
||||
}
|
@ -1,283 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
class SettingsContext implements Context, ActorAwareInterface {
|
||||
use ActorAware;
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function acceptSharesByDefaultCheckbox() {
|
||||
// forThe()->checkbox("Accept user...") can not be used here; that would
|
||||
// return the checkbox itself, but the element that the user interacts
|
||||
// with is the label.
|
||||
return Locator::forThe()->xpath("//label[normalize-space() = 'Accept user and group shares by default']")->
|
||||
describedAs("Accept shares by default checkbox in Sharing section in Personal Sharing Settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function acceptSharesByDefaultCheckboxInput() {
|
||||
return Locator::forThe()->checkbox("Accept user and group shares by default")->
|
||||
describedAs("Accept shares by default checkbox input in Sharing section in Personal Sharing Settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function allowResharingCheckbox() {
|
||||
// forThe()->checkbox("Allow resharing") can not be used here; that
|
||||
// would return the checkbox itself, but the element that the user
|
||||
// interacts with is the label.
|
||||
return Locator::forThe()->xpath("//label[normalize-space() = 'Allow resharing']")->
|
||||
describedAs("Allow resharing checkbox in Sharing section in Administration Sharing Settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function allowResharingCheckboxInput() {
|
||||
return Locator::forThe()->checkbox("Allow resharing")->
|
||||
describedAs("Allow resharing checkbox input in Sharing section in Administration Sharing Settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function restrictUsernameAutocompletionToGroupsCheckbox() {
|
||||
// forThe()->checkbox("Restrict username...") can not be used here; that
|
||||
// would return the checkbox itself, but the element that the user
|
||||
// interacts with is the label.
|
||||
return Locator::forThe()->xpath("//label[normalize-space() = 'Allow username autocompletion to users within the same groups']")->
|
||||
describedAs("Allow username autocompletion to users within the same groups checkbox in Sharing section in Administration Sharing Settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function restrictUsernameAutocompletionToGroupsCheckboxInput() {
|
||||
return Locator::forThe()->checkbox("Allow username autocompletion to users within the same groups")->
|
||||
describedAs("Allow username autocompletion to users within the same groups checkbox input in Sharing section in Administration Sharing Settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function systemTagsSelectTagButton() {
|
||||
return Locator::forThe()->id("s2id_systemtag")->
|
||||
describedAs("Select tag button in system tags section in Administration Settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function systemTagsItemInDropdownForTag($tag) {
|
||||
return Locator::forThe()->xpath("//*[contains(concat(' ', normalize-space(@class), ' '), ' select2-result-label ')]//span[normalize-space() = '$tag']/ancestor::li")->
|
||||
descendantOf(self::select2Dropdown())->
|
||||
describedAs("Item in dropdown for tag $tag in system tags section in Administration Settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
private static function select2Dropdown() {
|
||||
return Locator::forThe()->css("#select2-drop")->
|
||||
describedAs("Select2 dropdown in Settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
private static function select2DropdownMask() {
|
||||
return Locator::forThe()->css("#select2-drop-mask")->
|
||||
describedAs("Select2 dropdown mask in Settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function systemTagsTagNameInput() {
|
||||
return Locator::forThe()->id("systemtag_name")->
|
||||
describedAs("Tag name input in system tags section in Administration Settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function systemTagsCreateOrUpdateButton() {
|
||||
return Locator::forThe()->id("systemtag_submit")->
|
||||
describedAs("Create/Update button in system tags section in Administration Settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function systemTagsResetButton() {
|
||||
return Locator::forThe()->id("systemtag_reset")->
|
||||
describedAs("Reset button in system tags section in Administration Settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I disable accepting the shares by default
|
||||
*/
|
||||
public function iDisableAcceptingTheSharesByDefault() {
|
||||
$this->iSeeThatSharesAreAcceptedByDefault();
|
||||
|
||||
$this->actor->find(self::acceptSharesByDefaultCheckbox(), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I disable resharing
|
||||
*/
|
||||
public function iDisableResharing() {
|
||||
$this->iSeeThatResharingIsEnabled();
|
||||
|
||||
$this->actor->find(self::allowResharingCheckbox(), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I enable restricting username autocompletion to groups
|
||||
*/
|
||||
public function iEnableRestrictingUsernameAutocompletionToGroups() {
|
||||
$this->iSeeThatUsernameAutocompletionIsNotRestrictedToGroups();
|
||||
|
||||
$this->actor->find(self::restrictUsernameAutocompletionToGroupsCheckbox(), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I create the tag :tag in the settings
|
||||
*/
|
||||
public function iCreateTheTagInTheSettings($tag) {
|
||||
$this->actor->find(self::systemTagsResetButton(), 10)->click();
|
||||
$this->actor->find(self::systemTagsTagNameInput())->setValue($tag);
|
||||
$this->actor->find(self::systemTagsCreateOrUpdateButton())->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that shares are accepted by default
|
||||
*/
|
||||
public function iSeeThatSharesAreAcceptedByDefault() {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::acceptSharesByDefaultCheckboxInput(), 10)->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that resharing is enabled
|
||||
*/
|
||||
public function iSeeThatResharingIsEnabled() {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::allowResharingCheckboxInput(), 10)->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that resharing is disabled
|
||||
*/
|
||||
public function iSeeThatResharingIsDisabled() {
|
||||
Assert::assertFalse(
|
||||
$this->actor->find(self::allowResharingCheckboxInput(), 10)->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that username autocompletion is restricted to groups
|
||||
*/
|
||||
public function iSeeThatUsernameAutocompletionIsRestrictedToGroups() {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::restrictUsernameAutocompletionToGroupsCheckboxInput(), 10)->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that username autocompletion is not restricted to groups
|
||||
*/
|
||||
public function iSeeThatUsernameAutocompletionIsNotRestrictedToGroups() {
|
||||
Assert::assertFalse(
|
||||
$this->actor->find(self::restrictUsernameAutocompletionToGroupsCheckboxInput(), 10)->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that shares are not accepted by default
|
||||
*/
|
||||
public function iSeeThatSharesAreNotAcceptedByDefault() {
|
||||
Assert::assertFalse(
|
||||
$this->actor->find(self::acceptSharesByDefaultCheckboxInput(), 10)->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the button to select tags is shown
|
||||
*/
|
||||
public function iSeeThatTheButtonToSelectTagsIsShown() {
|
||||
Assert::assertTrue($this->actor->find(self::systemTagsSelectTagButton(), 10)->isVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the dropdown for tags in the settings eventually contains the tag :tag
|
||||
*/
|
||||
public function iSeeThatTheDropdownForTagsInTheSettingsEventuallyContainsTheTag($tag) {
|
||||
// When the dropdown is opened it is not automatically updated if new
|
||||
// tags are added to the server, and when a tag is created, no explicit
|
||||
// feedback is provided to the user about the completion of that
|
||||
// operation (that is, when the tag is added to the server). Therefore,
|
||||
// to verify that creating a tag does in fact add it to the server it is
|
||||
// necessary to repeatedly open the dropdown until the tag is shown in
|
||||
// the dropdown (or the limit of tries is reached).
|
||||
|
||||
Assert::assertTrue($this->actor->find(self::systemTagsSelectTagButton(), 10)->isVisible());
|
||||
|
||||
$actor = $this->actor;
|
||||
|
||||
$tagFoundInDropdownCallback = function () use ($actor, $tag) {
|
||||
// Open the dropdown to look for the tag.
|
||||
$actor->find(self::systemTagsSelectTagButton())->click();
|
||||
|
||||
// When the dropdown is opened it is initially empty, and its
|
||||
// contents are updated once received from the server. Therefore, a
|
||||
// timeout must be used when looking for the tags.
|
||||
try {
|
||||
$tagFound = $this->actor->find(self::systemTagsItemInDropdownForTag($tag), 10)->isVisible();
|
||||
} catch (NoSuchElementException $exception) {
|
||||
$tagFound = false;
|
||||
}
|
||||
|
||||
// Close again the dropdown after looking for the tag. When a
|
||||
// dropdown is opened Select2 creates a special element that masks
|
||||
// every other element but the dropdown to get all mouse clicks;
|
||||
// this is used by Select2 to close the dropdown when the user
|
||||
// clicks outside it.
|
||||
$actor->find(self::select2DropdownMask())->click();
|
||||
|
||||
return $tagFound;
|
||||
};
|
||||
|
||||
$numberOfTries = 5;
|
||||
for ($i = 0; $i < $numberOfTries; $i++) {
|
||||
if ($tagFoundInDropdownCallback()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Assert::fail("The dropdown in system tags section in Administration Settings does not contain the tag $tag after $numberOfTries tries");
|
||||
}
|
||||
}
|
@ -1,228 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
* @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) (skjnldsv@protonmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
class SettingsMenuContext implements Context, ActorAwareInterface {
|
||||
use ActorAware;
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function settingsSectionInHeader() {
|
||||
return Locator::forThe()->xpath("//*[@id = 'header']//*[@id = 'user-menu']")->
|
||||
describedAs("Settings menu section in the header");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function settingsMenuButton() {
|
||||
return Locator::forThe()->css(".header-menu__trigger")->
|
||||
descendantOf(self::settingsSectionInHeader())->
|
||||
describedAs("Settings menu button");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function settingsMenu() {
|
||||
return Locator::forThe()->css("ul")->
|
||||
descendantOf(self::settingsSectionInHeader())->
|
||||
describedAs("Settings menu");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function usersMenuItem() {
|
||||
return self::menuItemFor("Users");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function usersAppsItem() {
|
||||
return self::menuItemFor("Apps");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function logOutMenuItem() {
|
||||
return self::menuItemFor("Log out");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
private static function menuItemFor($itemText) {
|
||||
return Locator::forThe()->xpath("//a[normalize-space() = '$itemText']")->
|
||||
descendantOf(self::settingsMenu())->
|
||||
describedAs($itemText . " item in Settings menu");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $itemText
|
||||
* @return Locator
|
||||
*/
|
||||
private static function settingsPanelFor($itemText) {
|
||||
return Locator::forThe()->xpath("//div[@id = 'app-navigation' or contains(@class, 'app-navigation')]//div[contains(@class, 'app-navigation-caption') and normalize-space() = '$itemText']")->
|
||||
describedAs($itemText . " item in Settings panel");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $itemText
|
||||
* @return Locator
|
||||
*/
|
||||
private static function settingsPanelEntryFor($itemText) {
|
||||
return Locator::forThe()->xpath("//div[@id = 'app-navigation' or contains(@class, 'app-navigation')]//ul//li[normalize-space() = '$itemText']")->
|
||||
describedAs($itemText . " entry in Settings panel");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function menuItems() {
|
||||
return $this->actor->find(self::settingsMenu(), 10)
|
||||
->getWrappedElement()->findAll('xpath', '//a');
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I open the Settings menu
|
||||
*/
|
||||
public function iOpenTheSettingsMenu() {
|
||||
$this->actor->find(self::settingsMenuButton(), 10)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I open the User settings
|
||||
*/
|
||||
public function iOpenTheUserSettings() {
|
||||
$this->iOpenTheSettingsMenu();
|
||||
|
||||
$this->actor->find(self::usersMenuItem(), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I open the Apps management
|
||||
*/
|
||||
public function iOpenTheAppsManagement() {
|
||||
$this->iOpenTheSettingsMenu();
|
||||
|
||||
$this->actor->find(self::usersAppsItem(), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I visit the settings page
|
||||
*/
|
||||
public function iVisitTheSettingsPage() {
|
||||
$this->iOpenTheSettingsMenu();
|
||||
$this->actor->find(self::menuItemFor('Settings'), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I visit the admin settings page
|
||||
*/
|
||||
public function iVisitTheAdminSettingsPage() {
|
||||
$this->iOpenTheSettingsMenu();
|
||||
$this->actor->find(self::menuItemFor('Administration settings'), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I log out
|
||||
*/
|
||||
public function iLogOut() {
|
||||
$this->iOpenTheSettingsMenu();
|
||||
|
||||
$this->actor->find(self::logOutMenuItem(), 2)->click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the Settings menu is shown
|
||||
*/
|
||||
public function iSeeThatTheSettingsMenuIsShown() {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::settingsMenu(), 10)->isVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the Settings menu has only :items items
|
||||
*/
|
||||
public function iSeeThatTheSettingsMenuHasOnlyXItems($items) {
|
||||
Assert::assertCount(intval($items), self::menuItems());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the :itemText item in the Settings menu is shown
|
||||
*/
|
||||
public function iSeeThatTheItemInTheSettingsMenuIsShown($itemText) {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::menuItemFor($itemText), 10)->isVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the :itemText item in the Settings menu is not shown
|
||||
*/
|
||||
public function iSeeThatTheItemInTheSettingsMenuIsNotShown($itemText) {
|
||||
$this->iSeeThatTheSettingsMenuIsShown();
|
||||
|
||||
try {
|
||||
Assert::assertFalse(
|
||||
$this->actor->find(self::menuItemFor($itemText))->isVisible());
|
||||
} catch (NoSuchElementException $exception) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the :itemText settings panel is shown
|
||||
*/
|
||||
public function iSeeThatTheItemSettingsPanelIsShown($itemText) {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::settingsPanelFor($itemText), 10)->isVisible()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the :itemText entry in the settings panel is shown
|
||||
*/
|
||||
public function iSeeThatTheItemEntryInTheSettingsPanelIsShown($itemText) {
|
||||
Assert::assertTrue(
|
||||
$this->actor->find(self::settingsPanelEntryFor($itemText), 10)->isVisible()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the :itemText settings panel is not shown
|
||||
*/
|
||||
public function iSeeThatTheItemSettingsPanelIsNotShown($itemText) {
|
||||
try {
|
||||
Assert::assertFalse(
|
||||
$this->actor->find(self::settingsPanelFor($itemText), 10)->isVisible()
|
||||
);
|
||||
} catch (NoSuchElementException $exception) {
|
||||
}
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
class ToastContext implements Context, ActorAwareInterface {
|
||||
use ActorAware;
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
public static function toastMessage($message) {
|
||||
return Locator::forThe()->xpath("//*[contains(concat(' ', normalize-space(@class), ' '), ' toastify ') and normalize-space(text()) = '$message']")->
|
||||
descendantOf(self::toastContainer())->
|
||||
describedAs("$message toast");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Locator
|
||||
*/
|
||||
private static function toastContainer() {
|
||||
return Locator::forThe()->xpath("//*[@id=\"content\" or contains(@class, 'content')]")->
|
||||
describedAs("Toast container");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I see that the :message toast is shown
|
||||
*/
|
||||
public function iSeeThatTheToastIsShown($message) {
|
||||
Assert::assertTrue($this->actor->find(
|
||||
self::toastMessage($message), 10)->isVisible());
|
||||
}
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2018, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper class with common "wait for" functions.
|
||||
*/
|
||||
class WaitFor {
|
||||
/**
|
||||
* Waits for the element to be visible.
|
||||
*
|
||||
* @param Actor $actor the Actor used to find the element.
|
||||
* @param Locator $elementLocator the locator for the element.
|
||||
* @param float $timeout the number of seconds (decimals allowed) to wait at
|
||||
* most for the element to be visible.
|
||||
* @param float $timeoutStep the number of seconds (decimals allowed) to
|
||||
* wait before checking the visibility again.
|
||||
* @return boolean true if the element is visible before (or exactly when)
|
||||
* the timeout expires, false otherwise.
|
||||
*/
|
||||
public static function elementToBeEventuallyShown(Actor $actor, Locator $elementLocator, $timeout = 10, $timeoutStep = 1) {
|
||||
$elementShownCallback = function () use ($actor, $elementLocator) {
|
||||
try {
|
||||
return $actor->find($elementLocator)->isVisible();
|
||||
} catch (NoSuchElementException $exception) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return Utils::waitFor($elementShownCallback, $timeout, $timeoutStep);
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for the element to be hidden (either not visible or not found in
|
||||
* the DOM).
|
||||
*
|
||||
* @param Actor $actor the Actor used to find the element.
|
||||
* @param Locator $elementLocator the locator for the element.
|
||||
* @param float $timeout the number of seconds (decimals allowed) to wait at
|
||||
* most for the element to be hidden.
|
||||
* @param float $timeoutStep the number of seconds (decimals allowed) to
|
||||
* wait before checking the visibility again.
|
||||
* @return boolean true if the element is hidden before (or exactly when)
|
||||
* the timeout expires, false otherwise.
|
||||
*/
|
||||
public static function elementToBeEventuallyNotShown(Actor $actor, Locator $elementLocator, $timeout = 10, $timeoutStep = 1) {
|
||||
$elementNotShownCallback = function () use ($actor, $elementLocator) {
|
||||
try {
|
||||
return !$actor->find($elementLocator)->isVisible();
|
||||
} catch (NoSuchElementException $exception) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
return Utils::waitFor($elementNotShownCallback, $timeout, $timeoutStep);
|
||||
}
|
||||
}
|
@ -1,214 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* An actor in a test scenario.
|
||||
*
|
||||
* Every Actor object is intended to be used only in a single test scenario.
|
||||
* An Actor can control its web browser thanks to the Mink Session received when
|
||||
* it was created, so in each scenario each Actor must have its own Mink
|
||||
* Session; the same Mink Session can be used by different Actors in different
|
||||
* scenarios, but never by different Actors in the same scenario.
|
||||
*
|
||||
* The test servers used in an scenario can change between different test runs,
|
||||
* so an Actor stores the base URL for the current test server being used; in
|
||||
* most cases the tests are specified using relative paths that can be converted
|
||||
* to the appropriate absolute URL using locatePath() in the step
|
||||
* implementation.
|
||||
*
|
||||
* An Actor can find elements in its Mink Session using its find() method; it is
|
||||
* a wrapper over the find() method provided by Mink that extends it with
|
||||
* several features: the element can be looked for based on a Locator object, an
|
||||
* exception is thrown if the element is not found, and, optionally, it is
|
||||
* possible to try again to find the element several times before giving up.
|
||||
*
|
||||
* The returned object is also a wrapper over the element itself that
|
||||
* automatically handles common causes of failed commands, like clicking on a
|
||||
* hidden element; in this case, the wrapper would wait for the element to be
|
||||
* visible up to the timeout set to find the element.
|
||||
*
|
||||
* The amount of time to wait before giving up is specified in each call to
|
||||
* find(). However, a general multiplier to be applied to every timeout can be
|
||||
* set using setFindTimeoutMultiplier(); this makes possible to retry longer
|
||||
* before giving up without modifying the tests themselves. Note that the
|
||||
* multiplier affects the timeout, but not the timeout step; the rate at which
|
||||
* find() will try again to find the element does not change.
|
||||
*
|
||||
* All actors share a notebook in which data can be annotated. This makes
|
||||
* possible to share data between different test steps, no matter which Actor
|
||||
* performs them.
|
||||
*/
|
||||
class Actor {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var \Behat\Mink\Session
|
||||
*/
|
||||
private $session;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $baseUrl;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $findTimeoutMultiplier;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $sharedNotebook;
|
||||
|
||||
/**
|
||||
* Creates a new Actor.
|
||||
*
|
||||
* @param string $name the name of the actor.
|
||||
* @param \Behat\Mink\Session $session the Mink Session used to control its
|
||||
* web browser.
|
||||
* @param string $baseUrl the base URL used when solving relative URLs.
|
||||
* @param array $sharedNotebook the notebook shared between all actors.
|
||||
*/
|
||||
public function __construct($name, \Behat\Mink\Session $session, $baseUrl, &$sharedNotebook) {
|
||||
$this->name = $name;
|
||||
$this->session = $session;
|
||||
$this->baseUrl = $baseUrl;
|
||||
$this->sharedNotebook = &$sharedNotebook;
|
||||
$this->findTimeoutMultiplier = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this Actor.
|
||||
*
|
||||
* @return string the name of this Actor.
|
||||
*/
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the base URL.
|
||||
*
|
||||
* @param string $baseUrl the base URL used when solving relative URLs.
|
||||
*/
|
||||
public function setBaseUrl($baseUrl) {
|
||||
$this->baseUrl = $baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the multiplier for find timeouts.
|
||||
*
|
||||
* @return float the multiplier to apply to find timeouts.
|
||||
*/
|
||||
public function getFindTimeoutMultiplier() {
|
||||
return $this->findTimeoutMultiplier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the multiplier for find timeouts.
|
||||
*
|
||||
* @param float $findTimeoutMultiplier the multiplier to apply to find
|
||||
* timeouts.
|
||||
*/
|
||||
public function setFindTimeoutMultiplier($findTimeoutMultiplier) {
|
||||
$this->findTimeoutMultiplier = $findTimeoutMultiplier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Mink Session used to control its web browser.
|
||||
*
|
||||
* @return \Behat\Mink\Session the Mink Session used to control its web
|
||||
* browser.
|
||||
*/
|
||||
public function getSession() {
|
||||
return $this->session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full path for the given relative path based on the base URL.
|
||||
*
|
||||
* @param string relativePath the relative path.
|
||||
* @return string the full path.
|
||||
*/
|
||||
public function locatePath($relativePath) {
|
||||
return $this->baseUrl . $relativePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds an element in the Mink Session of this Actor.
|
||||
*
|
||||
* The given element locator is relative to its ancestor (either another
|
||||
* locator or an actual element); if it has no ancestor then the base
|
||||
* document element is used.
|
||||
*
|
||||
* Sometimes an element may not be found simply because it has not appeared
|
||||
* yet; for those cases this method supports trying again to find the
|
||||
* element several times before giving up. The timeout parameter controls
|
||||
* how much time to wait, at most, to find the element; the timeoutStep
|
||||
* parameter controls how much time to wait before trying again to find the
|
||||
* element. If ancestor locators need to be found the timeout is applied
|
||||
* individually to each one, that is, if the timeout is 10 seconds the
|
||||
* method will wait up to 10 seconds to find the ancestor of the ancestor
|
||||
* and, then, up to 10 seconds to find the ancestor and, then, up to 10
|
||||
* seconds to find the element. By default the timeout is 0, so the element
|
||||
* and its ancestor will be looked for just once; the default time to wait
|
||||
* before retrying is half a second. If the timeout is not 0 it will be
|
||||
* affected by the multiplier set using setFindTimeoutMultiplier(), if any.
|
||||
*
|
||||
* When found, the element is returned wrapped in an ElementWrapper; the
|
||||
* ElementWrapper handles common causes of failures when executing commands
|
||||
* in an element, like clicking on a hidden element.
|
||||
*
|
||||
* In any case, if the element, or its ancestors, can not be found a
|
||||
* NoSuchElementException is thrown.
|
||||
*
|
||||
* @param Locator $elementLocator the locator for the element.
|
||||
* @param float $timeout the number of seconds (decimals allowed) to wait at
|
||||
* most for the element to appear.
|
||||
* @param float $timeoutStep the number of seconds (decimals allowed) to
|
||||
* wait before trying to find the element again.
|
||||
* @return ElementWrapper an ElementWrapper object for the element.
|
||||
* @throws NoSuchElementException if the element, or its ancestor, can not
|
||||
* be found.
|
||||
*/
|
||||
public function find(Locator $elementLocator, $timeout = 0, $timeoutStep = 0.5) {
|
||||
$timeout = $timeout * $this->findTimeoutMultiplier;
|
||||
|
||||
$elementFinder = new ElementFinder($this->session, $elementLocator, $timeout, $timeoutStep);
|
||||
|
||||
return new ElementWrapper($elementFinder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shared notebook of the Actors.
|
||||
*
|
||||
* @return array the shared notebook of the Actors.
|
||||
*/
|
||||
public function &getSharedNotebook() {
|
||||
return $this->sharedNotebook;
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
trait ActorAware {
|
||||
/**
|
||||
* @var Actor
|
||||
*/
|
||||
protected $actor;
|
||||
|
||||
/**
|
||||
* @param Actor $actor
|
||||
*/
|
||||
public function setCurrentActor(Actor $actor) {
|
||||
$this->actor = $actor;
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
interface ActorAwareInterface {
|
||||
/**
|
||||
* @param Actor $actor
|
||||
*/
|
||||
public function setCurrentActor(Actor $actor);
|
||||
}
|
@ -1,194 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Hook\Scope\BeforeStepScope;
|
||||
use Behat\MinkExtension\Context\RawMinkContext;
|
||||
|
||||
/**
|
||||
* Behat context to set the actor used in sibling contexts.
|
||||
*
|
||||
* This helper context provides a step definition ("I act as XXX") to change the
|
||||
* current actor of the scenario, which makes possible to use different browser
|
||||
* sessions in the same scenario.
|
||||
*
|
||||
* Sibling contexts that want to have access to the current actor of the
|
||||
* scenario must implement the ActorAwareInterface; this can be done just by
|
||||
* using the ActorAware trait.
|
||||
*
|
||||
* Besides updating the current actor in sibling contexts the ActorContext also
|
||||
* propagates its inherited "base_url" Mink parameter to the Actors as needed.
|
||||
*
|
||||
* By default no multiplier for the find timeout is set in the Actors. However,
|
||||
* it can be customized using the "actorTimeoutMultiplier" parameter of the
|
||||
* ActorContext in "behat.yml". This parameter also affects the overall timeout
|
||||
* to start a session for an Actor before giving up.
|
||||
*
|
||||
* Every actor used in the scenarios must have a corresponding Mink session
|
||||
* declared in "behat.yml" with the same name as the actor. All used sessions
|
||||
* are stopped after each scenario is run.
|
||||
*/
|
||||
class ActorContext extends RawMinkContext {
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $actors;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $sharedNotebook;
|
||||
|
||||
/**
|
||||
* @var Actor
|
||||
*/
|
||||
private $currentActor;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $actorTimeoutMultiplier;
|
||||
|
||||
/**
|
||||
* Creates a new ActorContext.
|
||||
*
|
||||
* @param float $actorTimeoutMultiplier the timeout multiplier for Actor
|
||||
* related timeouts.
|
||||
*/
|
||||
public function __construct($actorTimeoutMultiplier = 1) {
|
||||
$this->actorTimeoutMultiplier = $actorTimeoutMultiplier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a Mink parameter.
|
||||
*
|
||||
* When the "base_url" parameter is set its value is propagated to all the
|
||||
* Actors.
|
||||
*
|
||||
* @param string $name the name of the parameter.
|
||||
* @param string $value the value of the parameter.
|
||||
*/
|
||||
public function setMinkParameter($name, $value) {
|
||||
parent::setMinkParameter($name, $value);
|
||||
|
||||
if ($name === "base_url") {
|
||||
foreach ($this->actors as $actor) {
|
||||
$actor->setBaseUrl($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the session with the given name.
|
||||
*
|
||||
* If the session is not started it is started before returning it; if the
|
||||
* session fails to start (typically due to a timeout connecting with the
|
||||
* web browser) it will be tried again up to $actorTimeoutMultiplier times
|
||||
* in total (rounded up to the next integer) before giving up.
|
||||
*
|
||||
* @param string|null $sname the name of the session to get, or null for the
|
||||
* default session.
|
||||
* @return \Behat\Mink\Session the session.
|
||||
*/
|
||||
public function getSession($name = null) {
|
||||
for ($i = 0; $i < ($this->actorTimeoutMultiplier - 1); $i++) {
|
||||
try {
|
||||
return parent::getSession($name);
|
||||
} catch (\Behat\Mink\Exception\DriverException $exception) {
|
||||
echo "Exception when getting " . ($name == null? "default session": "session '$name'") . ": " . $exception->getMessage() . "\n";
|
||||
echo "Trying again\n";
|
||||
}
|
||||
}
|
||||
|
||||
return parent::getSession($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @BeforeScenario
|
||||
*
|
||||
* Initializes the Actors for the new Scenario with the default Actor.
|
||||
*
|
||||
* Other Actors are added (and their Mink Sessions started) only when they
|
||||
* are used in an "I act as XXX" step.
|
||||
*/
|
||||
public function initializeActors() {
|
||||
$this->actors = [];
|
||||
$this->sharedNotebook = [];
|
||||
|
||||
$this->getSession()->start();
|
||||
|
||||
$this->getSession()->maximizeWindow();
|
||||
|
||||
$this->actors["default"] = new Actor("default", $this->getSession(), $this->getMinkParameter("base_url"), $this->sharedNotebook);
|
||||
$this->actors["default"]->setFindTimeoutMultiplier($this->actorTimeoutMultiplier);
|
||||
|
||||
$this->currentActor = $this->actors["default"];
|
||||
}
|
||||
|
||||
/**
|
||||
* @BeforeStep
|
||||
*/
|
||||
public function setCurrentActorInSiblingActorAwareContexts(BeforeStepScope $scope) {
|
||||
$environment = $scope->getEnvironment();
|
||||
|
||||
foreach ($environment->getContexts() as $context) {
|
||||
if ($context instanceof ActorAwareInterface) {
|
||||
$context->setCurrentActor($this->currentActor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I act as :actorName
|
||||
*/
|
||||
public function iActAs($actorName) {
|
||||
if (!array_key_exists($actorName, $this->actors)) {
|
||||
$this->getSession($actorName)->start();
|
||||
|
||||
$this->getSession($actorName)->maximizeWindow();
|
||||
|
||||
$this->actors[$actorName] = new Actor($actorName, $this->getSession($actorName), $this->getMinkParameter("base_url"), $this->sharedNotebook);
|
||||
$this->actors[$actorName]->setFindTimeoutMultiplier($this->actorTimeoutMultiplier);
|
||||
}
|
||||
|
||||
$this->currentActor = $this->actors[$actorName];
|
||||
|
||||
// Ensure that the browser window of the actor is the one in the
|
||||
// foreground; this works around a bug in the Firefox driver of Selenium
|
||||
// and/or maybe in Firefox itself when interacting with a window in the
|
||||
// background, but also reflects better how the user would interact with
|
||||
// the browser in real life.
|
||||
$session = $this->actors[$actorName]->getSession();
|
||||
$session->switchToWindow($session->getWindowName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @AfterScenario
|
||||
*
|
||||
* Stops all the Mink Sessions used in the last Scenario.
|
||||
*/
|
||||
public function cleanUpSessions() {
|
||||
foreach ($this->actors as $actor) {
|
||||
$actor->getSession()->stop();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,203 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Command object to find Mink elements.
|
||||
*
|
||||
* The element locator is relative to its ancestor (either another locator or an
|
||||
* actual element); if it has no ancestor then the base document element is
|
||||
* used.
|
||||
*
|
||||
* Sometimes an element may not be found simply because it has not appeared yet;
|
||||
* for those cases ElementFinder supports trying again to find the element
|
||||
* several times before giving up. The timeout parameter controls how much time
|
||||
* to wait, at most, to find the element; the timeoutStep parameter controls how
|
||||
* much time to wait before trying again to find the element. If ancestor
|
||||
* locators need to be found the timeout is applied individually to each one,
|
||||
* that is, if the timeout is 10 seconds the method will wait up to 10 seconds
|
||||
* to find the ancestor of the ancestor and, then, up to 10 seconds to find the
|
||||
* ancestor and, then, up to 10 seconds to find the element. By default the
|
||||
* timeout is 0, so the element and its ancestor will be looked for just once;
|
||||
* the default time to wait before retrying is half a second.
|
||||
*
|
||||
* In any case, if the element, or its ancestors, can not be found a
|
||||
* NoSuchElementException is thrown.
|
||||
*/
|
||||
class ElementFinder {
|
||||
/**
|
||||
* Finds an element in the given Mink Session.
|
||||
*
|
||||
* @see ElementFinder
|
||||
*/
|
||||
private static function findInternal(\Behat\Mink\Session $session, Locator $elementLocator, $timeout, $timeoutStep) {
|
||||
$element = null;
|
||||
$selector = $elementLocator->getSelector();
|
||||
$locator = $elementLocator->getLocator();
|
||||
$ancestorElement = self::findAncestorElement($session, $elementLocator, $timeout, $timeoutStep);
|
||||
|
||||
$findCallback = function () use (&$element, $selector, $locator, $ancestorElement) {
|
||||
$element = $ancestorElement->find($selector, $locator);
|
||||
|
||||
return $element !== null;
|
||||
};
|
||||
if (!Utils::waitFor($findCallback, $timeout, $timeoutStep)) {
|
||||
$message = $elementLocator->getDescription() . " could not be found";
|
||||
if ($timeout > 0) {
|
||||
$message = $message . " after $timeout seconds";
|
||||
}
|
||||
throw new NoSuchElementException($message);
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ancestor element from which the given locator will be looked
|
||||
* for.
|
||||
*
|
||||
* If the ancestor of the given locator is another locator the element for
|
||||
* the ancestor locator is found and returned. If the ancestor of the given
|
||||
* locator is already an element that element is the one returned. If the
|
||||
* given locator has no ancestor then the base document element is returned.
|
||||
*
|
||||
* The timeout is used only when finding the element for the ancestor
|
||||
* locator; if the timeout expires a NoSuchElementException is thrown.
|
||||
*
|
||||
* @param \Behat\Mink\Session $session the Mink Session to get the ancestor
|
||||
* element from.
|
||||
* @param Locator $elementLocator the locator for the element to get its
|
||||
* ancestor.
|
||||
* @param float $timeout the number of seconds (decimals allowed) to wait at
|
||||
* most for the ancestor element to appear.
|
||||
* @param float $timeoutStep the number of seconds (decimals allowed) to
|
||||
* wait before trying to find the ancestor element again.
|
||||
* @return \Behat\Mink\Element\Element the ancestor element found.
|
||||
* @throws NoSuchElementException if the ancestor element can not be found.
|
||||
*/
|
||||
private static function findAncestorElement(\Behat\Mink\Session $session, Locator $elementLocator, $timeout, $timeoutStep) {
|
||||
$ancestorElement = $elementLocator->getAncestor();
|
||||
if ($ancestorElement instanceof Locator) {
|
||||
try {
|
||||
$ancestorElement = self::findInternal($session, $ancestorElement, $timeout, $timeoutStep);
|
||||
} catch (NoSuchElementException $exception) {
|
||||
// Little hack to show the stack of ancestor elements that could
|
||||
// not be found, as Behat only shows the message of the last
|
||||
// exception in the chain.
|
||||
$message = $exception->getMessage() . "\n" .
|
||||
$elementLocator->getDescription() . " could not be found";
|
||||
if ($timeout > 0) {
|
||||
$message = $message . " after $timeout seconds";
|
||||
}
|
||||
throw new NoSuchElementException($message, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
if ($ancestorElement === null) {
|
||||
$ancestorElement = $session->getPage();
|
||||
}
|
||||
|
||||
return $ancestorElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var \Behat\Mink\Session
|
||||
*/
|
||||
private $session;
|
||||
|
||||
/**
|
||||
* @param Locator
|
||||
*/
|
||||
private $elementLocator;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $timeout;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $timeoutStep;
|
||||
|
||||
/**
|
||||
* Creates a new ElementFinder.
|
||||
*
|
||||
* @param \Behat\Mink\Session $session the Mink Session to get the element
|
||||
* from.
|
||||
* @param Locator $elementLocator the locator for the element.
|
||||
* @param float $timeout the number of seconds (decimals allowed) to wait at
|
||||
* most for the element to appear.
|
||||
* @param float $timeoutStep the number of seconds (decimals allowed) to
|
||||
* wait before trying to find the element again.
|
||||
*/
|
||||
public function __construct(\Behat\Mink\Session $session, Locator $elementLocator, $timeout, $timeoutStep) {
|
||||
$this->session = $session;
|
||||
$this->elementLocator = $elementLocator;
|
||||
$this->timeout = $timeout;
|
||||
$this->timeoutStep = $timeoutStep;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of the element to find.
|
||||
*
|
||||
* @return string the description of the element to find.
|
||||
*/
|
||||
public function getDescription() {
|
||||
return $this->elementLocator->getDescription();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the timeout.
|
||||
*
|
||||
* @return float the number of seconds (decimals allowed) to wait at most
|
||||
* for the element to appear.
|
||||
*/
|
||||
public function getTimeout() {
|
||||
return $this->timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the timeout step.
|
||||
*
|
||||
* @return float the number of seconds (decimals allowed) to wait before
|
||||
* trying to find the element again.
|
||||
*/
|
||||
public function getTimeoutStep() {
|
||||
return $this->timeoutStep;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds an element using the parameters set in the constructor of this
|
||||
* ElementFinder.
|
||||
*
|
||||
* If the element, or its ancestors, can not be found a
|
||||
* NoSuchElementException is thrown.
|
||||
*
|
||||
* @return \Behat\Mink\Element\Element the element found.
|
||||
* @throws NoSuchElementException if the element, or its ancestor, can not
|
||||
* be found.
|
||||
*/
|
||||
public function find() {
|
||||
return self::findInternal($this->session, $this->elementLocator, $this->timeout, $this->timeoutStep);
|
||||
}
|
||||
}
|
@ -1,358 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Wrapper to automatically handle failed commands on Mink elements.
|
||||
*
|
||||
* Commands executed on Mink elements may fail for several reasons. The
|
||||
* ElementWrapper frees the caller of the commands from handling the most common
|
||||
* reasons of failure.
|
||||
*
|
||||
* StaleElementReference exceptions are thrown when the command is executed on
|
||||
* an element that is no longer attached to the DOM. This can happen even in
|
||||
* a chained call like "$actor->find($locator)->click()"; in the milliseconds
|
||||
* between finding the element and clicking it the element could have been
|
||||
* removed from the page (for example, if a previous interaction with the page
|
||||
* started an asynchronous update of the DOM). Every command executed through
|
||||
* the ElementWrapper is guarded against StaleElementReference exceptions; if
|
||||
* the element is stale it is found again using the same parameters to find it
|
||||
* in the first place.
|
||||
*
|
||||
* NoSuchElement exceptions are sometimes thrown instead of
|
||||
* StaleElementReference exceptions. This can happen when the Selenium2 driver
|
||||
* for Mink performs an action on an element through the WebDriver session
|
||||
* instead of directly through the WebDriver element. In that case, if the
|
||||
* element with the given ID does not exist, a NoSuchElement exception would be
|
||||
* thrown instead of a StaleElementReference exception, so those cases are
|
||||
* handled like StaleElementReference exceptions.
|
||||
*
|
||||
* ElementNotVisible exceptions are thrown when the command requires the element
|
||||
* to be visible but the element is not. Finding an element only guarantees that
|
||||
* (at that time) the element is attached to the DOM, but it does not provide
|
||||
* any guarantee regarding its visibility. Due to that, a call like
|
||||
* "$actor->find($locator)->click()" can fail if the element was hidden and
|
||||
* meant to be made visible by a previous interaction with the page, but that
|
||||
* interaction triggered an asynchronous update that was not finished when the
|
||||
* click command is executed. All commands executed through the ElementWrapper
|
||||
* that require the element to be visible are guarded against ElementNotVisible
|
||||
* exceptions; if the element is not visible it is waited for it to be visible
|
||||
* up to the timeout set to find it.
|
||||
*
|
||||
* MoveTargetOutOfBounds exceptions are sometimes thrown instead of
|
||||
* ElementNotVisible exceptions. This can happen when the Selenium2 driver for
|
||||
* Mink moves the cursor on an element using the "moveto" method of the
|
||||
* WebDriver session, for example, before clicking on an element. In that case,
|
||||
* if the element is not visible, "moveto" would throw a MoveTargetOutOfBounds
|
||||
* exception instead of an ElementNotVisible exception, so those cases are
|
||||
* handled like ElementNotVisible exceptions.
|
||||
*
|
||||
* ElementNotInteractable exceptions are thrown in Selenium 3 when the command
|
||||
* needs to interact with an element but that is not possible. This could be a
|
||||
* transitive situation (for example, due to an animation), so the command is
|
||||
* executed again after a small timeout.
|
||||
*
|
||||
* Despite the automatic handling it is possible for the commands to throw those
|
||||
* exceptions when they are executed again; this class does not handle cases
|
||||
* like an element becoming stale several times in a row (uncommon) or an
|
||||
* element not becoming visible before the timeout expires (which would mean
|
||||
* that the timeout is too short or that the test has to, indeed, fail). In a
|
||||
* similar way, MoveTargetOutOfBounds exceptions would be thrown again if
|
||||
* originally they were thrown because the element was visible but "out of
|
||||
* reach". ElementNotInteractable exceptions would be thrown again if it is not
|
||||
* possible to interact yet with the element after the wait (which could mean
|
||||
* that the test has to, indeed, fail, although it could mean too that the
|
||||
* automatic handling needs to be improved).
|
||||
*
|
||||
* If needed, automatically handling failed commands can be disabled calling
|
||||
* "doNotHandleFailedCommands()"; as it returns the ElementWrapper it can be
|
||||
* chained with the command to execute (but note that automatically handling
|
||||
* failed commands will still be disabled if further commands are executed on
|
||||
* the ElementWrapper).
|
||||
*/
|
||||
class ElementWrapper {
|
||||
/**
|
||||
* @var ElementFinder
|
||||
*/
|
||||
private $elementFinder;
|
||||
|
||||
/**
|
||||
* @var \Behat\Mink\Element\Element
|
||||
*/
|
||||
private $element;
|
||||
|
||||
/**
|
||||
* @param boolean
|
||||
*/
|
||||
private $handleFailedCommands;
|
||||
|
||||
/**
|
||||
* Creates a new ElementWrapper.
|
||||
*
|
||||
* The wrapped element is found in the constructor itself using the
|
||||
* ElementFinder.
|
||||
*
|
||||
* @param ElementFinder $elementFinder the command object to find the
|
||||
* wrapped element.
|
||||
* @throws NoSuchElementException if the element, or its ancestor, can not
|
||||
* be found.
|
||||
*/
|
||||
public function __construct(ElementFinder $elementFinder) {
|
||||
$this->elementFinder = $elementFinder;
|
||||
$this->element = $elementFinder->find();
|
||||
$this->handleFailedCommands = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw Mink element.
|
||||
*
|
||||
* @return \Behat\Mink\Element\Element the wrapped element.
|
||||
*/
|
||||
public function getWrappedElement() {
|
||||
return $this->element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents the automatic handling of failed commands.
|
||||
*
|
||||
* @return ElementWrapper this ElementWrapper.
|
||||
*/
|
||||
public function doNotHandleFailedCommands() {
|
||||
$this->handleFailedCommands = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the wrapped element is visible or not.
|
||||
*
|
||||
* @return bool true if the wrapped element is visible, false otherwise.
|
||||
*/
|
||||
public function isVisible() {
|
||||
$commandCallback = function () {
|
||||
return $this->element->isVisible();
|
||||
};
|
||||
return $this->executeCommand($commandCallback, "visibility could not be got");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the wrapped element is checked or not.
|
||||
*
|
||||
* @return bool true if the wrapped element is checked, false otherwise.
|
||||
*/
|
||||
public function isChecked() {
|
||||
$commandCallback = function () {
|
||||
return $this->element->isChecked();
|
||||
};
|
||||
return $this->executeCommand($commandCallback, "check state could not be got");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the text of the wrapped element.
|
||||
*
|
||||
* If the wrapped element is not visible the returned text is an empty
|
||||
* string.
|
||||
*
|
||||
* @return string the text of the wrapped element, or an empty string if it
|
||||
* is not visible.
|
||||
*/
|
||||
public function getText() {
|
||||
$commandCallback = function () {
|
||||
return $this->element->getText();
|
||||
};
|
||||
return $this->executeCommand($commandCallback, "text could not be got");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the wrapped element.
|
||||
*
|
||||
* The value can be got even if the wrapped element is not visible.
|
||||
*
|
||||
* @return string the value of the wrapped element.
|
||||
*/
|
||||
public function getValue() {
|
||||
$commandCallback = function () {
|
||||
return $this->element->getValue();
|
||||
};
|
||||
return $this->executeCommand($commandCallback, "value could not be got");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given value on the wrapped element.
|
||||
*
|
||||
* If automatically waits for the wrapped element to be visible (up to the
|
||||
* timeout set when finding it).
|
||||
*
|
||||
* @param string $value the value to set.
|
||||
*/
|
||||
public function setValue($value) {
|
||||
$commandCallback = function () use ($value) {
|
||||
$this->element->setValue($value);
|
||||
};
|
||||
$this->executeCommandOnVisibleElement($commandCallback, "value could not be set");
|
||||
}
|
||||
|
||||
/**
|
||||
* Clicks on the wrapped element.
|
||||
*
|
||||
* If automatically waits for the wrapped element to be visible (up to the
|
||||
* timeout set when finding it).
|
||||
*/
|
||||
public function click() {
|
||||
$commandCallback = function () {
|
||||
$this->element->click();
|
||||
};
|
||||
$this->executeCommandOnVisibleElement($commandCallback, "could not be clicked");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the wrapped element.
|
||||
*
|
||||
* If automatically waits for the wrapped element to be visible (up to the
|
||||
* timeout set when finding it).
|
||||
*/
|
||||
public function check() {
|
||||
$commandCallback = function () {
|
||||
$this->element->check();
|
||||
};
|
||||
$this->executeCommand($commandCallback, "could not be checked");
|
||||
}
|
||||
|
||||
/**
|
||||
* uncheck the wrapped element.
|
||||
*
|
||||
* If automatically waits for the wrapped element to be visible (up to the
|
||||
* timeout set when finding it).
|
||||
*/
|
||||
public function uncheck() {
|
||||
$commandCallback = function () {
|
||||
$this->element->uncheck();
|
||||
};
|
||||
$this->executeCommand($commandCallback, "could not be unchecked");
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the given command.
|
||||
*
|
||||
* If a StaleElementReference or a NoSuchElement exception is thrown the
|
||||
* wrapped element is found again and, then, the command is executed again.
|
||||
*
|
||||
* @param \Closure $commandCallback the command to execute.
|
||||
* @param string $errorMessage an error message that describes the failed
|
||||
* command (appended to the description of the element).
|
||||
*/
|
||||
private function executeCommand(\Closure $commandCallback, $errorMessage) {
|
||||
if (!$this->handleFailedCommands) {
|
||||
return $commandCallback();
|
||||
}
|
||||
|
||||
try {
|
||||
return $commandCallback();
|
||||
} catch (\WebDriver\Exception\StaleElementReference $exception) {
|
||||
$this->printFailedCommandMessage($exception, $errorMessage);
|
||||
} catch (\WebDriver\Exception\NoSuchElement $exception) {
|
||||
$this->printFailedCommandMessage($exception, $errorMessage);
|
||||
}
|
||||
|
||||
$this->element = $this->elementFinder->find();
|
||||
|
||||
return $commandCallback();
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the given command on a visible element.
|
||||
*
|
||||
* If a StaleElementReference or a NoSuchElement exception is thrown the
|
||||
* wrapped element is found again and, then, the command is executed again.
|
||||
* If an ElementNotVisible or a MoveTargetOutOfBounds exception is thrown it
|
||||
* is waited for the wrapped element to be visible and, then, the command is
|
||||
* executed again.
|
||||
* If an ElementNotInteractable exception is thrown it is also waited for
|
||||
* the wrapped element to be visible. It is very likely that the element was
|
||||
* visible already, but it is not possible to easily check if the element
|
||||
* can be interacted with, retrying will be only useful if it was a
|
||||
* transitive situation that resolves itself with a wait (for example, due
|
||||
* to an animation) and waiting for the element to be visible will always
|
||||
* start with a wait.
|
||||
*
|
||||
* @param \Closure $commandCallback the command to execute.
|
||||
* @param string $errorMessage an error message that describes the failed
|
||||
* command (appended to the description of the element).
|
||||
*/
|
||||
private function executeCommandOnVisibleElement(\Closure $commandCallback, $errorMessage) {
|
||||
if (!$this->handleFailedCommands) {
|
||||
return $commandCallback();
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->executeCommand($commandCallback, $errorMessage);
|
||||
} catch (\WebDriver\Exception\ElementNotVisible $exception) {
|
||||
$this->printFailedCommandMessage($exception, $errorMessage);
|
||||
} catch (\WebDriver\Exception\MoveTargetOutOfBounds $exception) {
|
||||
$this->printFailedCommandMessage($exception, $errorMessage);
|
||||
} catch (\Exception $exception) {
|
||||
// The "ElementNotInteractable" exception is not available yet in
|
||||
// the current "instaclick/php-webdriver" version, so it is thrown
|
||||
// as a generic exception with a specific message.
|
||||
if (stripos($exception->getMessage(), "element not interactable") === false) {
|
||||
throw $exception;
|
||||
}
|
||||
$this->printFailedCommandMessage($exception, $errorMessage);
|
||||
}
|
||||
|
||||
$this->waitForElementToBeVisible();
|
||||
|
||||
return $commandCallback();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints information about the failed command.
|
||||
*
|
||||
* @param \Exception exception the exception thrown by the command.
|
||||
* @param string $errorMessage an error message that describes the failed
|
||||
* command (appended to the description of the locator of the element).
|
||||
*/
|
||||
private function printFailedCommandMessage(\Exception $exception, $errorMessage) {
|
||||
echo $this->elementFinder->getDescription() . " " . $errorMessage . "\n";
|
||||
echo "Exception message: " . $exception->getMessage() . "\n";
|
||||
echo "Trying again\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for the wrapped element to be visible.
|
||||
*
|
||||
* This method waits up to the timeout used when finding the wrapped
|
||||
* element; therefore, it may return when the element is still not visible.
|
||||
*
|
||||
* @return boolean true if the element is visible after the wait, false
|
||||
* otherwise.
|
||||
*/
|
||||
private function waitForElementToBeVisible() {
|
||||
$isVisibleCallback = function () {
|
||||
return $this->isVisible();
|
||||
};
|
||||
$timeout = $this->elementFinder->getTimeout();
|
||||
$timeoutStep = $this->elementFinder->getTimeoutStep();
|
||||
|
||||
return Utils::waitFor($isVisibleCallback, $timeout, $timeoutStep);
|
||||
}
|
||||
}
|
@ -1,313 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Data object for the information needed to locate an element in a web page
|
||||
* using Mink.
|
||||
*
|
||||
* Locators can be created directly using the constructor, or through a more
|
||||
* fluent interface with Locator::forThe().
|
||||
*/
|
||||
class Locator {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $selector;
|
||||
|
||||
/**
|
||||
* @var string|array
|
||||
*/
|
||||
private $locator;
|
||||
|
||||
/**
|
||||
* @var null|Locator|\Behat\Mink\Element\ElementInterface
|
||||
*/
|
||||
private $ancestor;
|
||||
|
||||
/**
|
||||
* Starting point for the fluent interface to create Locators.
|
||||
*
|
||||
* @return LocatorBuilder
|
||||
*/
|
||||
public static function forThe() {
|
||||
return new LocatorBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description
|
||||
* @param string $selector
|
||||
* @param string|array $locator
|
||||
* @param null|Locator|\Behat\Mink\Element\ElementInterface $ancestor
|
||||
*/
|
||||
public function __construct($description, $selector, $locator, $ancestor = null) {
|
||||
$this->description = $description;
|
||||
$this->selector = $selector;
|
||||
$this->locator = $locator;
|
||||
$this->ancestor = $ancestor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription() {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSelector() {
|
||||
return $this->selector;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|array
|
||||
*/
|
||||
public function getLocator() {
|
||||
return $this->locator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|Locator|\Behat\Mink\Element\ElementInterface
|
||||
*/
|
||||
public function getAncestor() {
|
||||
return $this->ancestor;
|
||||
}
|
||||
}
|
||||
|
||||
class LocatorBuilder {
|
||||
/**
|
||||
* @param string $selector
|
||||
* @param string|array $locator
|
||||
* @return LocatorBuilderSecondStep
|
||||
*/
|
||||
public function customSelector($selector, $locator) {
|
||||
return new LocatorBuilderSecondStep($selector, $locator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $cssExpression
|
||||
* @return LocatorBuilderSecondStep
|
||||
*/
|
||||
public function css($cssExpression) {
|
||||
return $this->customSelector("css", $cssExpression);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $xpathExpression
|
||||
* @return LocatorBuilderSecondStep
|
||||
*/
|
||||
public function xpath($xpathExpression) {
|
||||
return $this->customSelector("xpath", $xpathExpression);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return LocatorBuilderSecondStep
|
||||
*/
|
||||
public function id($value) {
|
||||
return $this->customSelector("named_exact", ["id", $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return LocatorBuilderSecondStep
|
||||
*/
|
||||
public function idOrName($value) {
|
||||
return $this->customSelector("named_exact", ["id_or_name", $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return LocatorBuilderSecondStep
|
||||
*/
|
||||
public function link($value) {
|
||||
return $this->customSelector("named_exact", ["link", $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return LocatorBuilderSecondStep
|
||||
*/
|
||||
public function button($value) {
|
||||
return $this->customSelector("named_exact", ["button", $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return LocatorBuilderSecondStep
|
||||
*/
|
||||
public function linkOrButton($value) {
|
||||
return $this->customSelector("named_exact", ["link_or_button", $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return LocatorBuilderSecondStep
|
||||
*/
|
||||
public function field($value) {
|
||||
return $this->customSelector("named_exact", ["field", $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return LocatorBuilderSecondStep
|
||||
*/
|
||||
public function selectField($value) {
|
||||
return $this->customSelector("named_exact", ["select", $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return LocatorBuilderSecondStep
|
||||
*/
|
||||
public function checkbox($value) {
|
||||
return $this->customSelector("named_exact", ["checkbox", $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return LocatorBuilderSecondStep
|
||||
*/
|
||||
public function radioButton($value) {
|
||||
return $this->customSelector("named_exact", ["radio", $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return LocatorBuilderSecondStep
|
||||
*/
|
||||
public function fileInput($value) {
|
||||
return $this->customSelector("named_exact", ["file", $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return LocatorBuilderSecondStep
|
||||
*/
|
||||
public function optionGroup($value) {
|
||||
return $this->customSelector("named_exact", ["optgroup", $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return LocatorBuilderSecondStep
|
||||
*/
|
||||
public function option($value) {
|
||||
return $this->customSelector("named_exact", ["option", $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return LocatorBuilderSecondStep
|
||||
*/
|
||||
public function fieldSet($value) {
|
||||
return $this->customSelector("named_exact", ["fieldset", $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return LocatorBuilderSecondStep
|
||||
*/
|
||||
public function table($value) {
|
||||
return $this->customSelector("named_exact", ["table", $value]);
|
||||
}
|
||||
}
|
||||
|
||||
class LocatorBuilderSecondStep {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $selector;
|
||||
|
||||
/**
|
||||
* @var string|array
|
||||
*/
|
||||
private $locator;
|
||||
|
||||
/**
|
||||
* @param string $selector
|
||||
* @param string|array $locator
|
||||
*/
|
||||
public function __construct($selector, $locator) {
|
||||
$this->selector = $selector;
|
||||
$this->locator = $locator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Locator|\Behat\Mink\Element\ElementInterface $ancestor
|
||||
* @return LocatorBuilderThirdStep
|
||||
*/
|
||||
public function descendantOf($ancestor) {
|
||||
return new LocatorBuilderThirdStep($this->selector, $this->locator, $ancestor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description
|
||||
* @return Locator
|
||||
*/
|
||||
public function describedAs($description) {
|
||||
return new Locator($description, $this->selector, $this->locator);
|
||||
}
|
||||
}
|
||||
|
||||
class LocatorBuilderThirdStep {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $selector;
|
||||
|
||||
/**
|
||||
* @var string|array
|
||||
*/
|
||||
private $locator;
|
||||
|
||||
/**
|
||||
* @var Locator|\Behat\Mink\Element\ElementInterface
|
||||
*/
|
||||
private $ancestor;
|
||||
|
||||
/**
|
||||
* @param string $selector
|
||||
* @param string|array $locator
|
||||
* @param Locator|\Behat\Mink\Element\ElementInterface $ancestor
|
||||
*/
|
||||
public function __construct($selector, $locator, $ancestor) {
|
||||
$this->selector = $selector;
|
||||
$this->locator = $locator;
|
||||
$this->ancestor = $ancestor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description
|
||||
* @return Locator
|
||||
*/
|
||||
public function describedAs($description) {
|
||||
return new Locator($description, $this->selector, $this->locator, $this->ancestor);
|
||||
}
|
||||
}
|
@ -1,126 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
||||
|
||||
/**
|
||||
* Behat context to run each scenario against a clean Nextcloud server.
|
||||
*
|
||||
* Before each scenario is run, this context sets up a fresh Nextcloud server
|
||||
* with predefined data and configuration. Thanks to this every scenario is
|
||||
* independent from the others and they all know the initial state of the
|
||||
* server.
|
||||
*
|
||||
* This context is expected to be used along with RawMinkContext contexts (or
|
||||
* subclasses). As the server address can be different for each scenario, this
|
||||
* context automatically sets the "base_url" parameter of all its sibling
|
||||
* RawMinkContexts; just add NextcloudTestServerContext to the context list of a
|
||||
* suite in "behat.yml".
|
||||
*
|
||||
* The Nextcloud server is provided by an instance of NextcloudTestServerHelper;
|
||||
* its class must be specified when this context is created. By default,
|
||||
* "NextcloudTestServerLocalBuiltInHelper" is used, although that can be
|
||||
* customized using the "nextcloudTestServerHelper" parameter in "behat.yml". In
|
||||
* the same way, the parameters to be passed to the helper when it is created
|
||||
* can be customized using the "nextcloudTestServerHelperParameters" parameter,
|
||||
* which is an array (without keys) with the value of the parameters in the same
|
||||
* order as in the constructor of the helper class (by default, [ ]).
|
||||
*
|
||||
* Example of custom parameters in "behat.yml":
|
||||
* default:
|
||||
* suites:
|
||||
* default:
|
||||
* contexts:
|
||||
* - NextcloudTestServerContext:
|
||||
* nextcloudTestServerHelper: NextcloudTestServerCustomHelper
|
||||
* nextcloudTestServerHelperParameters:
|
||||
* - first-parameter-value
|
||||
* - second-parameter-value
|
||||
*/
|
||||
class NextcloudTestServerContext implements Context {
|
||||
/**
|
||||
* @var NextcloudTestServerHelper
|
||||
*/
|
||||
private $nextcloudTestServerHelper;
|
||||
|
||||
/**
|
||||
* Creates a new NextcloudTestServerContext.
|
||||
*
|
||||
* @param string $nextcloudTestServerHelper the name of the
|
||||
* NextcloudTestServerHelper implementing class to use.
|
||||
* @param array $nextcloudTestServerHelperParameters the parameters for the
|
||||
* constructor of the $nextcloudTestServerHelper class.
|
||||
*/
|
||||
public function __construct($nextcloudTestServerHelper = "NextcloudTestServerLocalBuiltInHelper",
|
||||
$nextcloudTestServerHelperParameters = [ ]) {
|
||||
$nextcloudTestServerHelperClass = new ReflectionClass($nextcloudTestServerHelper);
|
||||
|
||||
if ($nextcloudTestServerHelperParameters === null) {
|
||||
$nextcloudTestServerHelperParameters = [];
|
||||
}
|
||||
|
||||
$this->nextcloudTestServerHelper = $nextcloudTestServerHelperClass->newInstanceArgs($nextcloudTestServerHelperParameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* @BeforeScenario
|
||||
*
|
||||
* Sets up the Nextcloud test server before each scenario.
|
||||
*
|
||||
* Once the Nextcloud test server is set up, the "base_url" parameter of the
|
||||
* sibling RawMinkContexts is set to the base URL of the Nextcloud test
|
||||
* server.
|
||||
*
|
||||
* @param \Behat\Behat\Hook\Scope\BeforeScenarioScope $scope the
|
||||
* BeforeScenario hook scope.
|
||||
* @throws \Exception if the Nextcloud test server can not be set up or its
|
||||
* base URL got.
|
||||
*/
|
||||
public function setUpNextcloudTestServer(BeforeScenarioScope $scope) {
|
||||
$this->nextcloudTestServerHelper->setUp();
|
||||
|
||||
$this->setBaseUrlInSiblingRawMinkContexts($scope, $this->nextcloudTestServerHelper->getBaseUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* @AfterScenario
|
||||
*
|
||||
* Cleans up the Nextcloud test server after each scenario.
|
||||
*
|
||||
* @throws \Exception if the Nextcloud test server can not be cleaned up.
|
||||
*/
|
||||
public function cleanUpNextcloudTestServer() {
|
||||
$this->nextcloudTestServerHelper->cleanUp();
|
||||
}
|
||||
|
||||
private function setBaseUrlInSiblingRawMinkContexts(BeforeScenarioScope $scope, $baseUrl) {
|
||||
$environment = $scope->getEnvironment();
|
||||
|
||||
foreach ($environment->getContexts() as $context) {
|
||||
if ($context instanceof Behat\MinkExtension\Context\RawMinkContext) {
|
||||
$context->setMinkParameter("base_url", $baseUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface for classes that manage a Nextcloud server during acceptance tests.
|
||||
*
|
||||
* A NextcloudTestServerHelper takes care of setting up a Nextcloud server to be
|
||||
* used in acceptance tests through its "setUp" method. It does not matter
|
||||
* wheter the server is a fresh new server just started or an already running
|
||||
* server; in any case, the state of the server must comply with the initial
|
||||
* state expected by the tests (like having performed the Nextcloud installation
|
||||
* or having an admin user with certain password).
|
||||
*
|
||||
* As the IP address and thus its the base URL of the server is not known
|
||||
* beforehand, the NextcloudTestServerHelper must provide it through its
|
||||
* "getBaseUrl" method. Note that this must be the base URL from the point of
|
||||
* view of the Selenium server, which may be a different value than the base URL
|
||||
* from the point of view of the acceptance tests themselves.
|
||||
*
|
||||
* Once the Nextcloud test server is no longer needed the "cleanUp" method will
|
||||
* be called; depending on how the Nextcloud test server was set up it may not
|
||||
* need to do anything.
|
||||
*
|
||||
* All the methods throw an exception if they fail to execute; as, due to the
|
||||
* current use of this interface, it is just a warning for the test runner and
|
||||
* nothing to be explicitly catched a plain base Exception is used.
|
||||
*/
|
||||
interface NextcloudTestServerHelper {
|
||||
/**
|
||||
* Sets up the Nextcloud test server.
|
||||
*
|
||||
* @throws \Exception if the Nextcloud test server can not be set up.
|
||||
*/
|
||||
public function setUp();
|
||||
|
||||
/**
|
||||
* Cleans up the Nextcloud test server.
|
||||
*
|
||||
* @throws \Exception if the Nextcloud test server can not be cleaned up.
|
||||
*/
|
||||
public function cleanUp();
|
||||
|
||||
/**
|
||||
* Returns the base URL of the Nextcloud test server (from the point of view
|
||||
* of the Selenium server).
|
||||
*
|
||||
* @return string the base URL of the Nextcloud test server.
|
||||
* @throws \Exception if the base URL can not be determined.
|
||||
*/
|
||||
public function getBaseUrl();
|
||||
}
|
@ -1,128 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2018, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper to manage a Nextcloud test server started directly by the acceptance
|
||||
* tests themselves using the Apache web server.
|
||||
*
|
||||
* The Nextcloud test server is executed using the Apache web server; the
|
||||
* default Apache directory is expected to have been set to the root directory
|
||||
* of the Nextcloud server (for example, by linking "var/www/html" to it); in
|
||||
* any case, note that the acceptance tests must be run from the acceptance
|
||||
* tests directory. The "setUp" method resets the Nextcloud server to its
|
||||
* initial state and starts it, while the "cleanUp" method stops it. To be able
|
||||
* to reset the Nextcloud server to its initial state a Git repository must be
|
||||
* provided in the root directory of the Nextcloud server; the last commit in
|
||||
* that Git repository must provide the initial state for the Nextcloud server
|
||||
* expected by the acceptance tests. When the Nextcloud server is reset the
|
||||
* owner of "apps", "config" and "data" must be set to the user that Apache
|
||||
* server is run as; it is assumed that Apache is run as "www-data".
|
||||
*
|
||||
* The Nextcloud server is available at "$nextcloudServerDomain", which can be
|
||||
* optionally specified when the NextcloudTestServerLocalApacheHelper is
|
||||
* created; if no value is given "127.0.0.1" is used by default. In any case,
|
||||
* the value of "$nextcloudServerDomain" must be seen as a trusted domain by the
|
||||
* Nextcloud server (which would be the case for "127.0.0.1" if it was installed
|
||||
* by running "occ maintenance:install"). The base URL to access the Nextcloud
|
||||
* server can be got from "getBaseUrl".
|
||||
*/
|
||||
class NextcloudTestServerLocalApacheHelper implements NextcloudTestServerHelper {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $nextcloudServerDomain;
|
||||
|
||||
/**
|
||||
* Creates a new NextcloudTestServerLocalApacheHelper.
|
||||
*/
|
||||
public function __construct($nextcloudServerDomain = "127.0.0.1") {
|
||||
$this->nextcloudServerDomain = $nextcloudServerDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the Nextcloud test server.
|
||||
*
|
||||
* It resets the Nextcloud test server restoring its last saved Git state
|
||||
* and then waits for the Nextcloud test server to start again; if the
|
||||
* server can not be reset or if it does not start again after some time an
|
||||
* exception is thrown (as it is just a warning for the test runner and
|
||||
* nothing to be explicitly catched a plain base Exception is used).
|
||||
*
|
||||
* @throws \Exception if the Nextcloud test server can not be reset or
|
||||
* started again.
|
||||
*/
|
||||
public function setUp(): void {
|
||||
// Ensure that previous Apache server is not running (as cleanUp may not
|
||||
// have been called).
|
||||
$this->stopApacheServer();
|
||||
|
||||
$this->execOrException("cd ../../ && git reset --hard HEAD");
|
||||
$this->execOrException("cd ../../ && git clean -d --force");
|
||||
$this->execOrException("cd ../../ && chown -R www-data:www-data apps config data");
|
||||
|
||||
$this->execOrException("service apache2 start");
|
||||
|
||||
$timeout = 60;
|
||||
if (!Utils::waitForServer($this->getBaseUrl(), $timeout)) {
|
||||
throw new Exception("Nextcloud test server could not be started");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up the Nextcloud test server.
|
||||
*
|
||||
* It stops the running Nextcloud test server, if any.
|
||||
*/
|
||||
public function cleanUp() {
|
||||
$this->stopApacheServer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the base URL of the Nextcloud test server.
|
||||
*
|
||||
* @return string the base URL of the Nextcloud test server.
|
||||
*/
|
||||
public function getBaseUrl() {
|
||||
return "http://" . $this->nextcloudServerDomain . "/index.php";
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the given command, throwing an Exception if it fails.
|
||||
*
|
||||
* @param string $command the command to execute.
|
||||
* @throws \Exception if the command fails to execute.
|
||||
*/
|
||||
private function execOrException($command) {
|
||||
exec($command . " 2>&1", $output, $returnValue);
|
||||
if ($returnValue != 0) {
|
||||
throw new Exception("'$command' could not be executed: " . implode("\n", $output));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the Apache server started in setUp, if any.
|
||||
*/
|
||||
private function stopApacheServer() {
|
||||
$this->execOrException("service apache2 stop");
|
||||
}
|
||||
}
|
@ -1,142 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper to manage a Nextcloud test server started directly by the acceptance
|
||||
* tests themselves using the PHP built-in web server.
|
||||
*
|
||||
* The Nextcloud test server is executed using the PHP built-in web server
|
||||
* directly from the grandparent directory of the acceptance tests directory
|
||||
* (that is, the root directory of the Nextcloud server); note that the
|
||||
* acceptance tests must be run from the acceptance tests directory. The "setUp"
|
||||
* method resets the Nextcloud server to its initial state and starts it, while
|
||||
* the "cleanUp" method stops it. To be able to reset the Nextcloud server to
|
||||
* its initial state a Git repository must be provided in the root directory of
|
||||
* the Nextcloud server; the last commit in that Git repository must provide the
|
||||
* initial state for the Nextcloud server expected by the acceptance tests.
|
||||
*
|
||||
* The Nextcloud server is available at "$nextcloudServerDomain", which can be
|
||||
* optionally specified when the NextcloudTestServerLocalBuiltInHelper is
|
||||
* created; if no value is given "127.0.0.1" is used by default. In any case,
|
||||
* the value of "$nextcloudServerDomain" must be seen as a trusted domain by the
|
||||
* Nextcloud server (which would be the case for "127.0.0.1" if it was installed
|
||||
* by running "occ maintenance:install"). The base URL to access the Nextcloud
|
||||
* server can be got from "getBaseUrl".
|
||||
*/
|
||||
class NextcloudTestServerLocalBuiltInHelper implements NextcloudTestServerHelper {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $nextcloudServerDomain;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $phpServerPid;
|
||||
|
||||
/**
|
||||
* Creates a new NextcloudTestServerLocalBuiltInHelper.
|
||||
*/
|
||||
public function __construct($nextcloudServerDomain = "127.0.0.1") {
|
||||
$this->nextcloudServerDomain = $nextcloudServerDomain;
|
||||
|
||||
$this->phpServerPid = "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the Nextcloud test server.
|
||||
*
|
||||
* It resets the Nextcloud test server restoring its last saved Git state
|
||||
* and then waits for the Nextcloud test server to start again; if the
|
||||
* server can not be reset or if it does not start again after some time an
|
||||
* exception is thrown (as it is just a warning for the test runner and
|
||||
* nothing to be explicitly catched a plain base Exception is used).
|
||||
*
|
||||
* @throws \Exception if the Nextcloud test server can not be reset or
|
||||
* started again.
|
||||
*/
|
||||
public function setUp(): void {
|
||||
// Ensure that previous PHP server is not running (as cleanUp may not
|
||||
// have been called).
|
||||
$this->killPhpServer();
|
||||
|
||||
$this->execOrException("cd ../../ && git reset --hard HEAD");
|
||||
$this->execOrException("cd ../../ && git clean -d --force");
|
||||
|
||||
// execOrException is not used because the server is started in the
|
||||
// background, so the command will always succeed even if the server
|
||||
// itself fails.
|
||||
$this->phpServerPid = exec("php -S " . $this->nextcloudServerDomain . ":80 -t ../../ >/dev/null 2>&1 & echo $!");
|
||||
|
||||
$timeout = 60;
|
||||
if (!Utils::waitForServer($this->getBaseUrl(), $timeout)) {
|
||||
throw new Exception("Nextcloud test server could not be started");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up the Nextcloud test server.
|
||||
*
|
||||
* It kills the running Nextcloud test server, if any.
|
||||
*/
|
||||
public function cleanUp() {
|
||||
$this->killPhpServer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the base URL of the Nextcloud test server.
|
||||
*
|
||||
* @return string the base URL of the Nextcloud test server.
|
||||
*/
|
||||
public function getBaseUrl() {
|
||||
return "http://" . $this->nextcloudServerDomain . "/index.php";
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the given command, throwing an Exception if it fails.
|
||||
*
|
||||
* @param string $command the command to execute.
|
||||
* @throws \Exception if the command fails to execute.
|
||||
*/
|
||||
private function execOrException($command) {
|
||||
exec($command . " 2>&1", $output, $returnValue);
|
||||
if ($returnValue != 0) {
|
||||
throw new Exception("'$command' could not be executed: " . implode("\n", $output));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kills the PHP built-in web server started in setUp, if any.
|
||||
*/
|
||||
private function killPhpServer() {
|
||||
if ($this->phpServerPid == "") {
|
||||
return;
|
||||
}
|
||||
|
||||
// execOrException is not used because the PID may no longer exist when
|
||||
// trying to kill it.
|
||||
exec("kill " . $this->phpServerPid);
|
||||
|
||||
$this->phpServerPid = "";
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception to signal that the element looked for could not be found.
|
||||
*/
|
||||
class NoSuchElementException extends \Exception {
|
||||
/**
|
||||
* @param string $message
|
||||
* @param null|\Exception $previous
|
||||
*/
|
||||
public function __construct($message, \Exception $previous = null) {
|
||||
parent::__construct($message, 0, $previous);
|
||||
}
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
class Utils {
|
||||
/**
|
||||
* Waits at most $timeout seconds for the given condition to be true,
|
||||
* checking it again every $timeoutStep seconds.
|
||||
*
|
||||
* Note that the timeout is no longer taken into account when a condition is
|
||||
* met; that is, true will be returned if the condition is met before the
|
||||
* timeout expires, but also if it is met exactly when the timeout expires.
|
||||
* For example, even if the timeout is set to 0, the condition will be
|
||||
* checked at least once, and true will be returned in that case if the
|
||||
* condition was met.
|
||||
*
|
||||
* @param \Closure $conditionCallback the condition to wait for, as a
|
||||
* function that returns a boolean.
|
||||
* @param float $timeout the number of seconds (decimals allowed) to wait at
|
||||
* most for the condition to be true.
|
||||
* @param float $timeoutStep the number of seconds (decimals allowed) to
|
||||
* wait before checking the condition again.
|
||||
* @return boolean true if the condition is met before (or exactly when) the
|
||||
* timeout expires, false otherwise.
|
||||
*/
|
||||
public static function waitFor($conditionCallback, $timeout, $timeoutStep) {
|
||||
$elapsedTime = 0;
|
||||
$conditionMet = false;
|
||||
|
||||
while (!($conditionMet = $conditionCallback()) && $elapsedTime < $timeout) {
|
||||
usleep($timeoutStep * 1000000);
|
||||
|
||||
$elapsedTime += $timeoutStep;
|
||||
}
|
||||
|
||||
return $conditionMet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits at most $timeout seconds for the server at the given URL to be up,
|
||||
* checking it again every $timeoutStep seconds.
|
||||
*
|
||||
* Note that it does not verify whether the URL returns a valid HTTP status
|
||||
* or not; it simply checks that the server at the given URL is accessible.
|
||||
*
|
||||
* @param string $url the URL for the server to check.
|
||||
* @param float $timeout the number of seconds (decimals allowed) to wait at
|
||||
* most for the server.
|
||||
* @param float $timeoutStep the number of seconds (decimals allowed) to
|
||||
* wait before checking the server again; by default, 0.5 seconds.
|
||||
* @return boolean true if the server was found, false otherwise.
|
||||
*/
|
||||
public static function waitForServer($url, $timeout, $timeoutStep = 0.5) {
|
||||
$isServerUpCallback = function () use ($url) {
|
||||
$curlHandle = curl_init($url);
|
||||
|
||||
// Returning the transfer as the result of curl_exec prevents the
|
||||
// transfer from being written to the output.
|
||||
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$transfer = curl_exec($curlHandle);
|
||||
|
||||
curl_close($curlHandle);
|
||||
|
||||
return $transfer !== false;
|
||||
};
|
||||
return self::waitFor($isServerUpCallback, $timeout, $timeoutStep);
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
#
|
||||
# @license GNU AGPL version 3 or any later version
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Helper script to install and configure the Nextcloud server as expected by the
|
||||
# acceptance tests.
|
||||
#
|
||||
# This script is not meant to be called manually; it is called when needed by
|
||||
# the acceptance tests launchers.
|
||||
|
||||
set -o errexit
|
||||
|
||||
NEXTCLOUD_SERVER_DOMAIN=""
|
||||
if [ "$1" = "--nextcloud-server-domain" ]; then
|
||||
NEXTCLOUD_SERVER_DOMAIN=$2
|
||||
|
||||
shift 2
|
||||
fi
|
||||
|
||||
php occ maintenance:install --admin-pass=admin
|
||||
|
||||
OC_PASS=123456acb php occ user:add --password-from-env user0
|
||||
OC_PASS=123456acb php occ user:add --password-from-env user1
|
||||
OC_PASS=123456acb php occ user:add --password-from-env disabledUser
|
||||
php occ user:disable disabledUser
|
||||
|
||||
# Redirect to files after login for acceptance tests
|
||||
php occ app:disable dashboard
|
||||
|
||||
# Disable browser warning as selenium is old
|
||||
php occ config:system:set no_unsupported_browser_warning --value=true --type=boolean
|
||||
|
||||
if [ "$NEXTCLOUD_SERVER_DOMAIN" != "" ]; then
|
||||
# Default first trusted domain is "localhost"; replace it with given domain.
|
||||
php occ config:system:set trusted_domains 0 --value="$NEXTCLOUD_SERVER_DOMAIN"
|
||||
fi
|
@ -1,229 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
#
|
||||
# @license GNU AGPL version 3 or any later version
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Helper script to run the acceptance tests, which test a running Nextcloud
|
||||
# instance from the point of view of a real user, configured to start the
|
||||
# Nextcloud server themselves and from their grandparent directory.
|
||||
#
|
||||
# The acceptance tests are written in Behat so, besides running the tests, this
|
||||
# script installs Behat, its dependencies, and some related packages in the
|
||||
# "vendor" subdirectory of the acceptance tests. The acceptance tests expect
|
||||
# that the last commit in the Git repository provides the default state of the
|
||||
# Nextcloud server, so the script installs the Nextcloud server and saves a
|
||||
# snapshot of the whole grandparent directory (no .gitignore file is used) in
|
||||
# the Git repository. Finally, the acceptance tests also use the Selenium server
|
||||
# to control a web browser, so this script waits for the Selenium server
|
||||
# (which should have been started before executing this script) to be ready
|
||||
# before running the tests.
|
||||
#
|
||||
# By default the acceptance tests run are those for the Nextcloud server;
|
||||
# acceptance tests for apps can be run by providing the
|
||||
# "--acceptance-tests-dir XXX" option. When this option is used the Behat
|
||||
# configuration and the Nextcloud installation script used by the acceptance
|
||||
# tests for the Nextcloud server are ignored; they must be provided in the given
|
||||
# acceptance tests directory. Note, however, that the context classes for the
|
||||
# Nextcloud server and the core acceptance test framework classes are
|
||||
# automatically loaded; there is no need to explicitly set them in the Behat
|
||||
# configuration. Also, even when that option is used, the packages installed by
|
||||
# this script end in the "vendor" subdirectory of the acceptance tests for the
|
||||
# Nextcloud server, not in the one given in the option.
|
||||
|
||||
# Exit immediately on errors.
|
||||
set -o errexit
|
||||
|
||||
# Ensure working directory is script directory, as some actions (like installing
|
||||
# Behat through Composer or running Behat) expect that.
|
||||
cd "$(dirname $0)"
|
||||
|
||||
# "--acceptance-tests-dir XXX" option can be provided to set the directory
|
||||
# (relative to the root directory of the Nextcloud server) used to look for the
|
||||
# Behat configuration and the Nextcloud installation script.
|
||||
# By default it is "tests/acceptance", that is, the acceptance tests for the
|
||||
# Nextcloud server itself.
|
||||
ACCEPTANCE_TESTS_DIR="tests/acceptance"
|
||||
if [ "$1" = "--acceptance-tests-dir" ]; then
|
||||
ACCEPTANCE_TESTS_DIR=$2
|
||||
|
||||
shift 2
|
||||
fi
|
||||
|
||||
ACCEPTANCE_TESTS_CONFIG_DIR="../../$ACCEPTANCE_TESTS_DIR/config"
|
||||
DEV_BRANCH="master"
|
||||
|
||||
# "--timeout-multiplier N" option can be provided to set the timeout multiplier
|
||||
# to be used in ActorContext.
|
||||
TIMEOUT_MULTIPLIER=""
|
||||
if [ "$1" = "--timeout-multiplier" ]; then
|
||||
if [[ ! "$2" =~ ^[0-9]+$ ]]; then
|
||||
echo "--timeout-multiplier must be followed by a positive integer"
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TIMEOUT_MULTIPLIER=$2
|
||||
|
||||
shift 2
|
||||
fi
|
||||
|
||||
# "--nextcloud-server-domain XXX" option can be provided to set the domain used
|
||||
# by the Selenium server to access the Nextcloud server.
|
||||
DEFAULT_NEXTCLOUD_SERVER_DOMAIN="127.0.0.1"
|
||||
NEXTCLOUD_SERVER_DOMAIN="$DEFAULT_NEXTCLOUD_SERVER_DOMAIN"
|
||||
if [ "$1" = "--nextcloud-server-domain" ]; then
|
||||
NEXTCLOUD_SERVER_DOMAIN=$2
|
||||
|
||||
shift 2
|
||||
fi
|
||||
|
||||
# "--selenium-server XXX" option can be provided to set the domain and port used
|
||||
# by the acceptance tests to access the Selenium server.
|
||||
DEFAULT_SELENIUM_SERVER="127.0.0.1:4444"
|
||||
SELENIUM_SERVER="$DEFAULT_SELENIUM_SERVER"
|
||||
if [ "$1" = "--selenium-server" ]; then
|
||||
SELENIUM_SERVER=$2
|
||||
|
||||
shift 2
|
||||
fi
|
||||
|
||||
# Safety parameter to prevent executing this script by mistake and messing with
|
||||
# the Git repository.
|
||||
if [ "$1" != "allow-git-repository-modifications" ]; then
|
||||
echo "To run the acceptance tests use \"run.sh\" instead"
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SCENARIO_TO_RUN=$2
|
||||
if [ "$ACCEPTANCE_TESTS_DIR" != "tests/acceptance" ]; then
|
||||
if [ "$SCENARIO_TO_RUN" == "" ]; then
|
||||
echo "When an acceptance tests directory is given the scenario to run" \
|
||||
"should be provided too (paths are relative to the acceptance" \
|
||||
"tests directory; use the features directory to run all tests)"
|
||||
echo "No scenario was given, so \"features/\" was automatically used"
|
||||
|
||||
SCENARIO_TO_RUN="features/"
|
||||
fi
|
||||
|
||||
SCENARIO_TO_RUN=../../$ACCEPTANCE_TESTS_DIR/$SCENARIO_TO_RUN
|
||||
fi
|
||||
|
||||
if [ "$TIMEOUT_MULTIPLIER" != "" ]; then
|
||||
# Although Behat documentation states that using the BEHAT_PARAMS
|
||||
# environment variable "You can set any value for any option that is
|
||||
# available in a behat.yml file" this is currently not true for the
|
||||
# constructor parameters of contexts (see
|
||||
# https://github.com/Behat/Behat/issues/983). Thus, the default "behat.yml"
|
||||
# configuration file has to be adjusted to provide the appropriate
|
||||
# parameters for ActorContext.
|
||||
ORIGINAL="\
|
||||
- ActorContext"
|
||||
REPLACEMENT="\
|
||||
- ActorContext:\n\
|
||||
actorTimeoutMultiplier: $TIMEOUT_MULTIPLIER"
|
||||
sed --in-place "s/$ORIGINAL/$REPLACEMENT/" $ACCEPTANCE_TESTS_CONFIG_DIR/behat.yml
|
||||
fi
|
||||
|
||||
if [ "$NEXTCLOUD_SERVER_DOMAIN" != "$DEFAULT_NEXTCLOUD_SERVER_DOMAIN" ]; then
|
||||
# Although Behat documentation states that using the BEHAT_PARAMS
|
||||
# environment variable "You can set any value for any option that is
|
||||
# available in a behat.yml file" this is currently not true for the
|
||||
# constructor parameters of contexts (see
|
||||
# https://github.com/Behat/Behat/issues/983). Thus, the default "behat.yml"
|
||||
# configuration file has to be adjusted to provide the appropriate
|
||||
# parameters for NextcloudTestServerContext.
|
||||
#
|
||||
# Note that the substitution below is only valid if no parameters for
|
||||
# the helper are set in behat.yml, although it is valid if a specific
|
||||
# helper is.
|
||||
ORIGINAL="\
|
||||
- NextcloudTestServerContext:\?"
|
||||
REPLACEMENT="\
|
||||
- NextcloudTestServerContext:\n\
|
||||
nextcloudTestServerHelperParameters:\n\
|
||||
- $NEXTCLOUD_SERVER_DOMAIN"
|
||||
sed --in-place "s/$ORIGINAL/$REPLACEMENT/" $ACCEPTANCE_TESTS_CONFIG_DIR/behat.yml
|
||||
fi
|
||||
|
||||
# Due to a bug in the Mink Extension for Behat it is not possible to use the
|
||||
# "paths.base" variable in the path to the custom Firefox profile. Thus, the
|
||||
# default "behat.yml" configuration file has to be adjusted to replace the
|
||||
# variable by its value before the configuration file is parsed by Behat.
|
||||
ORIGINAL="profile: %paths.base%"
|
||||
REPLACEMENT="profile: $ACCEPTANCE_TESTS_CONFIG_DIR"
|
||||
# As the substitution does not involve regular expressions or multilines it can
|
||||
# be done just with Bash. Moreover, this does not require escaping the regular
|
||||
# expression characters that may appear in the path, like "/".
|
||||
FILE_CONTENTS=$(<$ACCEPTANCE_TESTS_CONFIG_DIR/behat.yml)
|
||||
echo "${FILE_CONTENTS//$ORIGINAL/$REPLACEMENT}" > $ACCEPTANCE_TESTS_CONFIG_DIR/behat.yml
|
||||
|
||||
# Set the Selenium server to be used by Mink. Although Mink sessions can be
|
||||
# extended through BEHAT_PARAMS this would require adding here too each new
|
||||
# session added to "behat.yml", including those added in the acceptance
|
||||
# tests of apps. Instead, the default "behat.yml" configuration file is
|
||||
# adjusted to replace the simulated "selenium.server" variable by its value
|
||||
# before the configuration file is parsed by Behat.
|
||||
ORIGINAL="wd_host: %selenium.server%"
|
||||
REPLACEMENT="wd_host: http://$SELENIUM_SERVER/wd/hub"
|
||||
# As the substitution does not involve regular expressions or multilines it
|
||||
# can be done just with Bash. Moreover, this does not require escaping the
|
||||
# regular expression characters that may appear in the URL, like "/".
|
||||
FILE_CONTENTS=$(<$ACCEPTANCE_TESTS_CONFIG_DIR/behat.yml)
|
||||
echo "${FILE_CONTENTS//$ORIGINAL/$REPLACEMENT}" > $ACCEPTANCE_TESTS_CONFIG_DIR/behat.yml
|
||||
|
||||
composer install
|
||||
|
||||
cd ../../
|
||||
|
||||
# Link the default Apache directory to the root directory of the Nextcloud
|
||||
# server to make possible to run the Nextcloud server on Apache if needed.
|
||||
ln --symbolic $(pwd) /var/www/html
|
||||
|
||||
# Add Notifications app to the "apps" directory (unless it is already there).
|
||||
if [ ! -e "apps/notifications" ]; then
|
||||
(cd apps && git clone --depth 1 --branch ${DEV_BRANCH} https://github.com/nextcloud/notifications)
|
||||
fi
|
||||
|
||||
INSTALL_AND_CONFIGURE_SERVER_PARAMETERS=""
|
||||
if [ "$NEXTCLOUD_SERVER_DOMAIN" != "$DEFAULT_NEXTCLOUD_SERVER_DOMAIN" ]; then
|
||||
INSTALL_AND_CONFIGURE_SERVER_PARAMETERS+="--nextcloud-server-domain $NEXTCLOUD_SERVER_DOMAIN"
|
||||
fi
|
||||
|
||||
echo "Installing and configuring Nextcloud server"
|
||||
# The server is installed and configured using the www-data user as it is the
|
||||
# user that Apache sub-processes will be run as; the PHP built-in web server is
|
||||
# run as the root user, and in that case the permissions of apps, config and
|
||||
# data dirs makes no difference, so this is valid for both cases.
|
||||
mkdir data
|
||||
chown -R www-data:www-data apps config data
|
||||
NEXTCLOUD_DIR=`pwd`
|
||||
su --shell /bin/bash --login www-data --command "cd $NEXTCLOUD_DIR && $ACCEPTANCE_TESTS_DIR/installAndConfigureServer.sh $INSTALL_AND_CONFIGURE_SERVER_PARAMETERS"
|
||||
|
||||
echo "Saving the default state so acceptance tests can reset to it"
|
||||
find . -name ".gitignore" -exec rm --force {} \;
|
||||
# Create dummy files in empty directories to force Git to save the directories.
|
||||
find . -not -path "*.git*" -type d -empty -exec touch {}/.keep \;
|
||||
git add --all && echo 'Default state' | git -c user.name='John Doe' -c user.email='john@doe.org' commit --quiet --file=-
|
||||
|
||||
cd tests/acceptance
|
||||
|
||||
# Ensure that the Selenium server is ready before running the tests.
|
||||
echo "Waiting for Selenium"
|
||||
timeout 60s bash -c "while ! curl $SELENIUM_SERVER >/dev/null 2>&1; do sleep 1; done"
|
||||
|
||||
vendor/bin/behat --colors --config=$ACCEPTANCE_TESTS_CONFIG_DIR/behat.yml $SCENARIO_TO_RUN
|
@ -1,254 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
||||
#
|
||||
# @license GNU AGPL version 3 or any later version
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Helper script to run the acceptance tests, which test a running Nextcloud
|
||||
# instance from the point of view of a real user.
|
||||
#
|
||||
# The acceptance tests are run in its own Docker container; the grandparent
|
||||
# directory of the acceptance tests directory (that is, the root directory of
|
||||
# the Nextcloud server) is copied to the container and the acceptance tests are
|
||||
# run inside it. Once the tests end the container is stopped. The acceptance
|
||||
# tests also use the Selenium server to control a web browser, so the Selenium
|
||||
# server is also launched before the tests start in its own Docker container (it
|
||||
# will be stopped automatically too once the tests end).
|
||||
#
|
||||
# To perform its job, the script requires the "docker" command to be available.
|
||||
#
|
||||
# The Docker Command Line Interface (the "docker" command) requires special
|
||||
# permissions to talk to the Docker daemon, and those permissions are typically
|
||||
# available only to the root user. Please see the Docker documentation to find
|
||||
# out how to give access to a regular user to the Docker daemon:
|
||||
# https://docs.docker.com/engine/installation/linux/linux-postinstall/
|
||||
#
|
||||
# Note, however, that being able to communicate with the Docker daemon is the
|
||||
# same as being able to get root privileges for the system. Therefore, you must
|
||||
# give access to the Docker daemon (and thus run this script as) ONLY to trusted
|
||||
# and secure users:
|
||||
# https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
|
||||
#
|
||||
# Finally, take into account that this script will automatically remove the
|
||||
# Docker containers named "selenium-nextcloud-local-test-acceptance" and
|
||||
# "nextcloud-local-test-acceptance", even if the script did not create them
|
||||
# (probably you will not have containers nor images with those names, but just
|
||||
# in case).
|
||||
|
||||
# Sets the variables that abstract the differences in command names and options
|
||||
# between operating systems.
|
||||
#
|
||||
# Switches between timeout on GNU/Linux and gtimeout on macOS (same for mktemp
|
||||
# and gmktemp).
|
||||
function setOperatingSystemAbstractionVariables() {
|
||||
case "$OSTYPE" in
|
||||
darwin*)
|
||||
if [ "$(which gtimeout)" == "" ]; then
|
||||
echo "Please install coreutils (brew install coreutils)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
MKTEMP=gmktemp
|
||||
TIMEOUT=gtimeout
|
||||
DOCKER_OPTIONS="-e no_proxy=localhost "
|
||||
;;
|
||||
linux*)
|
||||
MKTEMP=mktemp
|
||||
TIMEOUT=timeout
|
||||
DOCKER_OPTIONS=" "
|
||||
;;
|
||||
*)
|
||||
echo "Operating system ($OSTYPE) not supported"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Launches the Selenium server in a Docker container.
|
||||
#
|
||||
# The acceptance tests use Firefox by default but, unfortunately, Firefox >= 48
|
||||
# does not provide yet the same level of support as earlier versions for certain
|
||||
# features related to automated testing. Therefore, the Docker image used is not
|
||||
# the latest one, but an older version known to work.
|
||||
#
|
||||
# The acceptance tests expect the Selenium server to be accessible at
|
||||
# "127.0.0.1:4444"; as the Selenium server container and the container in which
|
||||
# the acceptance tests are run share the same network nothing else needs to be
|
||||
# done for the acceptance tests to access the Selenium server and for the
|
||||
# Selenium server to access the Nextcloud server. However, in order to ensure
|
||||
# from this script that the Selenium server was started the 4444 port of its
|
||||
# container is mapped to the 4444 port of the host.
|
||||
#
|
||||
# Besides the Selenium server, the Docker image also provides a VNC server, so
|
||||
# the 5900 port of the container is also mapped to the 5900 port of the host.
|
||||
#
|
||||
# The Docker container started here will be automatically stopped when the
|
||||
# script exits (see cleanUp). If the Selenium server can not be started then the
|
||||
# script will be exited immediately with an error state; the most common cause
|
||||
# for the Selenium server to fail to start is that another server is already
|
||||
# using the mapped ports in the host.
|
||||
#
|
||||
# As the web browser is run inside the Docker container it is not visible by
|
||||
# default. However, it can be viewed using VNC (for example,
|
||||
# "vncviewer 127.0.0.1:5900"); when asked for the password use "secret".
|
||||
function prepareSelenium() {
|
||||
SELENIUM_CONTAINER=selenium-nextcloud-local-test-acceptance
|
||||
|
||||
echo "Starting Selenium server"
|
||||
docker run --detach --name=$SELENIUM_CONTAINER --publish 4444:4444 --publish 5900:5900 $DOCKER_OPTIONS selenium/standalone-chrome-debug:3.141.59
|
||||
|
||||
echo "Waiting for Selenium server to be ready"
|
||||
if ! $TIMEOUT 10s bash -c "while ! curl 127.0.0.1:4444 >/dev/null 2>&1; do sleep 1; done"; then
|
||||
echo "Could not start Selenium server; running" \
|
||||
"\"docker run --rm --publish 4444:4444 --publish 5900:5900 $DOCKER_OPTIONS selenium/standalone-chrome-debug:3.141.59\"" \
|
||||
"could give you a hint of the problem"
|
||||
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Creates a Docker container to run both the acceptance tests and the Nextcloud
|
||||
# server used by them.
|
||||
#
|
||||
# This function starts a Docker container with a copy the Nextcloud code from
|
||||
# the grandparent directory, although ignoring any configuration or data that it
|
||||
# may provide (for example, if that directory was used directly to deploy a
|
||||
# Nextcloud instance in a web server). As the Nextcloud code is copied to the
|
||||
# container instead of referenced the original code can be modified while the
|
||||
# acceptance tests are running without interfering in them.
|
||||
function prepareDocker() {
|
||||
NEXTCLOUD_LOCAL_CONTAINER=nextcloud-local-test-acceptance
|
||||
|
||||
echo "Starting the Nextcloud container"
|
||||
# As the Nextcloud server container uses the network of the Selenium server
|
||||
# container the Nextcloud server can be accessed at "127.0.0.1" from the
|
||||
# Selenium server.
|
||||
# The container exits immediately if no command is given, so a Bash session
|
||||
# is created to prevent that.
|
||||
docker run \
|
||||
--detach \
|
||||
--name=$NEXTCLOUD_LOCAL_CONTAINER \
|
||||
--network=container:$SELENIUM_CONTAINER \
|
||||
--volume composer_cache:/root/.composer \
|
||||
--interactive \
|
||||
--tty ghcr.io/nextcloud/continuous-integration-acceptance-php8.0:latest bash
|
||||
|
||||
# Use the $TMPDIR or, if not set, fall back to /tmp.
|
||||
NEXTCLOUD_LOCAL_TAR="$($MKTEMP --tmpdir="${TMPDIR:-/tmp}" --suffix=.tar nextcloud-local-XXXXXXXXXX)"
|
||||
|
||||
# Setting the user and group of files in the tar would be superfluous, as
|
||||
# "docker cp" does not take them into account (the extracted files are set
|
||||
# to root).
|
||||
echo "Copying local Git working directory of Nextcloud to the container"
|
||||
tar --create --file="$NEXTCLOUD_LOCAL_TAR" \
|
||||
--exclude=".git" \
|
||||
--exclude="./build" \
|
||||
--exclude="./config/config.php" \
|
||||
--exclude="./data" \
|
||||
--exclude="./data-autotest" \
|
||||
--exclude="./tests" \
|
||||
--exclude="./apps-extra" \
|
||||
--exclude="./apps-writable" \
|
||||
--exclude="node_modules" \
|
||||
--directory=../../ \
|
||||
.
|
||||
tar --append --file="$NEXTCLOUD_LOCAL_TAR" --directory=../../ tests/acceptance/
|
||||
|
||||
docker exec $NEXTCLOUD_LOCAL_CONTAINER mkdir /nextcloud
|
||||
docker cp - $NEXTCLOUD_LOCAL_CONTAINER:/nextcloud/ < "$NEXTCLOUD_LOCAL_TAR"
|
||||
|
||||
# run-local.sh expects a Git repository to be available in the root of the
|
||||
# Nextcloud server, but it was excluded when the Git working directory was
|
||||
# copied to the container to avoid copying the large and unneeded history of
|
||||
# the repository.
|
||||
docker exec $NEXTCLOUD_LOCAL_CONTAINER bash -c "cd nextcloud && git init"
|
||||
}
|
||||
|
||||
# Removes/stops temporal elements created/started by this script.
|
||||
function cleanUp() {
|
||||
# Disable (yes, "+" disables) exiting immediately on errors to ensure that
|
||||
# all the cleanup commands are executed (well, no errors should occur during
|
||||
# the cleanup anyway, but just in case).
|
||||
set +o errexit
|
||||
|
||||
echo "Cleaning up"
|
||||
|
||||
if [ -f "$NEXTCLOUD_LOCAL_TAR" ]; then
|
||||
echo "Removing $NEXTCLOUD_LOCAL_TAR"
|
||||
rm $NEXTCLOUD_LOCAL_TAR
|
||||
fi
|
||||
|
||||
# The name filter must be specified as "^/XXX$" to get an exact match; using
|
||||
# just "XXX" would match every name that contained "XXX".
|
||||
if [ -n "$(docker ps --all --quiet --filter name="^/$NEXTCLOUD_LOCAL_CONTAINER$")" ]; then
|
||||
echo "Removing Docker container $NEXTCLOUD_LOCAL_CONTAINER"
|
||||
docker rm --volumes --force $NEXTCLOUD_LOCAL_CONTAINER
|
||||
fi
|
||||
|
||||
if [ -n "$(docker ps --all --quiet --filter name="^/$SELENIUM_CONTAINER$")" ]; then
|
||||
echo "Removing Docker container $SELENIUM_CONTAINER"
|
||||
docker rm --volumes --force $SELENIUM_CONTAINER
|
||||
fi
|
||||
}
|
||||
|
||||
# Exit immediately on errors.
|
||||
set -o errexit
|
||||
|
||||
# Execute cleanUp when the script exits, either normally or due to an error.
|
||||
trap cleanUp EXIT
|
||||
|
||||
# Ensure working directory is script directory, as some actions (like copying
|
||||
# the Git working directory to the container) expect that.
|
||||
cd "$(dirname $0)"
|
||||
|
||||
# "--acceptance-tests-dir XXX" option can be provided to set the directory
|
||||
# (relative to the root directory of the Nextcloud server) used to look for the
|
||||
# Behat configuration and the Nextcloud installation script.
|
||||
# By default it is "tests/acceptance", that is, the acceptance tests for the
|
||||
# Nextcloud server itself.
|
||||
ACCEPTANCE_TESTS_DIR_OPTION=""
|
||||
if [ "$1" = "--acceptance-tests-dir" ]; then
|
||||
ACCEPTANCE_TESTS_DIR_OPTION="--acceptance-tests-dir $2"
|
||||
|
||||
shift 2
|
||||
fi
|
||||
|
||||
# "--timeout-multiplier N" option can be provided before the specific scenario
|
||||
# to run, if any, to set the timeout multiplier to be used in the acceptance
|
||||
# tests.
|
||||
TIMEOUT_MULTIPLIER_OPTION=""
|
||||
if [ "$1" = "--timeout-multiplier" ]; then
|
||||
if [[ ! "$2" =~ ^[0-9]+$ ]]; then
|
||||
echo "--timeout-multiplier must be followed by a positive integer"
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TIMEOUT_MULTIPLIER_OPTION="--timeout-multiplier $2"
|
||||
|
||||
shift 2
|
||||
fi
|
||||
|
||||
# If no parameter is provided to this script all the acceptance tests are run.
|
||||
SCENARIO_TO_RUN=$1
|
||||
|
||||
setOperatingSystemAbstractionVariables
|
||||
|
||||
prepareSelenium
|
||||
prepareDocker
|
||||
|
||||
echo "Running tests"
|
||||
docker exec $NEXTCLOUD_LOCAL_CONTAINER bash -c "cd nextcloud && tests/acceptance/run-local.sh $ACCEPTANCE_TESTS_DIR_OPTION $TIMEOUT_MULTIPLIER_OPTION allow-git-repository-modifications $SCENARIO_TO_RUN"
|
Loading…
Reference in New Issue