Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle-tool_lifecycle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elc
moodle-tool_lifecycle
Commits
ba57c851
Unverified
Commit
ba57c851
authored
5 years ago
by
Tobias Reischmann
Browse files
Options
Downloads
Patches
Plain Diff
Fix behat tests for action menues under javascript
parent
4c398f79
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/behat/behat_tool_lifecycle.php
+60
-2
60 additions, 2 deletions
tests/behat/behat_tool_lifecycle.php
with
60 additions
and
2 deletions
tests/behat/behat_tool_lifecycle.php
+
60
−
2
View file @
ba57c851
...
@@ -49,6 +49,7 @@ class behat_tool_lifecycle extends behat_base {
...
@@ -49,6 +49,7 @@ class behat_tool_lifecycle extends behat_base {
* @throws Exception
* @throws Exception
*/
*/
public
function
click_on_the_tool_in_the_row_of_the_table
(
$tool
,
$rowname
,
$tablename
)
{
public
function
click_on_the_tool_in_the_row_of_the_table
(
$tool
,
$rowname
,
$tablename
)
{
$this
->
open_or_close_action_menu
(
$tool
,
$rowname
,
$tablename
);
$xpathelement
=
$this
->
i_should_see_the_tool_in_the_row_of_the_table
(
$tool
,
$rowname
,
$tablename
);
$xpathelement
=
$this
->
i_should_see_the_tool_in_the_row_of_the_table
(
$tool
,
$rowname
,
$tablename
);
$this
->
execute
(
'behat_general::i_click_on'
,
[
$xpathelement
,
'xpath_element'
]);
$this
->
execute
(
'behat_general::i_click_on'
,
[
$xpathelement
,
'xpath_element'
]);
...
@@ -66,10 +67,14 @@ class behat_tool_lifecycle extends behat_base {
...
@@ -66,10 +67,14 @@ class behat_tool_lifecycle extends behat_base {
* @throws Exception
* @throws Exception
*/
*/
public
function
i_should_see_the_tool_in_the_row_of_the_table
(
$tool
,
$rowname
,
$tablename
)
{
public
function
i_should_see_the_tool_in_the_row_of_the_table
(
$tool
,
$rowname
,
$tablename
)
{
$xpathelement
=
$this
->
get_xpath_of_tool_in_table
(
$tool
,
$rowname
,
$tablename
);
$xpathelement
=
$this
->
get_xpath_of_tool_in_table
(
$tool
,
$rowname
,
$tablename
);
$this
->
open_or_close_action_menu
(
$tool
,
$rowname
,
$tablename
);
try
{
try
{
$this
->
find
(
'xpath'
,
$xpathelement
);
$this
->
find
(
'xpath'
,
$xpathelement
);
$this
->
open_or_close_action_menu
(
$tool
,
$rowname
,
$tablename
);
}
catch
(
ElementNotFoundException
$e
)
{
}
catch
(
ElementNotFoundException
$e
)
{
throw
new
ExpectationException
(
'"The tool "'
.
$tool
.
'" was not found for the row "'
.
$rowname
.
throw
new
ExpectationException
(
'"The tool "'
.
$tool
.
'" was not found for the row "'
.
$rowname
.
'" of the table '
.
$tablename
,
$this
->
getSession
());
'" of the table '
.
$tablename
,
$this
->
getSession
());
...
@@ -175,10 +180,13 @@ class behat_tool_lifecycle extends behat_base {
...
@@ -175,10 +180,13 @@ class behat_tool_lifecycle extends behat_base {
* @throws Exception
* @throws Exception
*/
*/
public
function
i_should_not_see_the_tool_in_the_row_of_the_table
(
$tool
,
$rowname
,
$tablename
)
{
public
function
i_should_not_see_the_tool_in_the_row_of_the_table
(
$tool
,
$rowname
,
$tablename
)
{
$this
->
open_or_close_action_menu
(
$tool
,
$rowname
,
$tablename
);
$xpathelement
=
$this
->
get_xpath_of_tool_in_table
(
$tool
,
$rowname
,
$tablename
);
$xpathelement
=
$this
->
get_xpath_of_tool_in_table
(
$tool
,
$rowname
,
$tablename
);
try
{
try
{
$this
->
find
(
'xpath'
,
$xpathelement
);
$this
->
find
(
'xpath'
,
$xpathelement
);
$this
->
open_or_close_action_menu
(
$tool
,
$rowname
,
$tablename
);
}
catch
(
ElementNotFoundException
$e
)
{
}
catch
(
ElementNotFoundException
$e
)
{
return
;
return
;
}
}
...
@@ -186,6 +194,25 @@ class behat_tool_lifecycle extends behat_base {
...
@@ -186,6 +194,25 @@ class behat_tool_lifecycle extends behat_base {
'" of the table '
.
$tablename
,
$this
->
getSession
());
'" of the table '
.
$tablename
,
$this
->
getSession
());
}
}
/**
* If Javascript is active, this function tries to click on an action dropdown, to reveal the underlying actions.
* @param $tool string identifier of the tool
* @param $rowname string identifier of the row
* @param $tablename string identifier of the table
* @throws Exception
*/
protected
function
open_or_close_action_menu
(
$tool
,
$rowname
,
$tablename
)
{
if
(
$this
->
running_javascript
())
{
$actionelement
=
$this
->
get_xpath_of_action_menu_in_table
(
$tool
,
$rowname
,
$tablename
);
try
{
$element
=
$this
->
find
(
'xpath'
,
$actionelement
);
$element
->
click
();
}
catch
(
ElementNotFoundException
$e
)
{
return
;
}
}
}
/**
/**
* Build the xpath to the table element with class tablename, throws exceptions if not present.
* Build the xpath to the table element with class tablename, throws exceptions if not present.
...
@@ -245,7 +272,7 @@ class behat_tool_lifecycle extends behat_base {
...
@@ -245,7 +272,7 @@ class behat_tool_lifecycle extends behat_base {
throw
new
ExpectationException
(
'"The table '
.
$tablename
.
' was not found.'
,
$this
->
getSession
());
throw
new
ExpectationException
(
'"The table '
.
$tablename
.
' was not found.'
,
$this
->
getSession
());
}
}
$xpathelement
=
$xpathelement
.
"//*[contains(
text()
,'
$rowname
')]/ancestor::tr"
;
$xpathelement
=
$xpathelement
.
"//*[
text()[
contains(
.
,'
$rowname
')]
]
/ancestor::tr"
;
try
{
try
{
$this
->
find
(
'xpath'
,
$xpathelement
);
$this
->
find
(
'xpath'
,
$xpathelement
);
...
@@ -255,12 +282,43 @@ class behat_tool_lifecycle extends behat_base {
...
@@ -255,12 +282,43 @@ class behat_tool_lifecycle extends behat_base {
}
}
$xpathelement
=
$xpathelement
.
"//a[@title = '
$tool
']"
.
$xpathelement
=
$xpathelement
.
"//a[@title = '
$tool
']"
.
" | "
.
$xpathelement
.
"//span[contains(
text()
, '
$tool
')]/parent::a"
.
" | "
.
$xpathelement
.
"//span[
text()[
contains(
.
, '
$tool
')]
]
/parent::a"
.
" | "
.
$xpathelement
.
"//button[text() = '
$tool
']"
;
" | "
.
$xpathelement
.
"//button[text() = '
$tool
']"
;
return
$xpathelement
;
return
$xpathelement
;
}
}
/**
* Build the xpath to the action menu and throws exceptions if either the table or the row are not present.
* @param $tool string identifier of the tool
* @param $rowname string identifier of the row
* @param $tablename string identifier of the table
* @return string xpath of the tool
* @throws ExpectationException
*/
private
function
get_xpath_of_action_menu_in_table
(
$tool
,
$rowname
,
$tablename
)
{
$xpathelement
=
"//table/tbody/tr[contains(@id, '
$tablename
')]"
;
try
{
$this
->
find
(
'xpath'
,
$xpathelement
);
}
catch
(
ElementNotFoundException
$e
)
{
throw
new
ExpectationException
(
'"The table '
.
$tablename
.
' was not found.'
,
$this
->
getSession
());
}
$xpathelement
=
$xpathelement
.
"//*[text()[contains(.,'
$rowname
')]]/ancestor::tr"
;
try
{
$this
->
find
(
'xpath'
,
$xpathelement
);
}
catch
(
ElementNotFoundException
$e
)
{
throw
new
ExpectationException
(
'"The row "'
.
$rowname
.
'" of the table '
.
$tablename
.
' was not found.'
,
$this
->
getSession
());
}
$xpathelement
=
$xpathelement
.
"//a[text()[contains(.,'Action')]]"
;
return
$xpathelement
;
}
/**
/**
* I should not see a tool for a entry of a table.
* I should not see a tool for a entry of a table.
*
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment