3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Analytics \Test \Constraint ;
7
8
8
9
use Magento \Mtf \Client \BrowserInterface ;
9
10
use Magento \Mtf \Constraint \AbstractConstraint ;
11
+ use Magento \Backend \Test \Page \Adminhtml \Dashboard ;
10
12
11
13
/**
12
14
* Assert BI Essentials Sign Up page is opened by admin menu link
13
15
*/
14
16
class AssertBIEssentialsLink extends AbstractConstraint
15
17
{
18
+ /**
19
+ * Count of try for choose menu item.
20
+ */
21
+ const MAX_TRY_COUNT = 2 ;
22
+
16
23
/**
17
24
* Browser instance.
18
25
*
@@ -25,19 +32,46 @@ class AssertBIEssentialsLink extends AbstractConstraint
25
32
*
26
33
* @param BrowserInterface $browser
27
34
* @param string $businessIntelligenceLink
35
+ * @param Dashboard $dashboard
36
+ * @param string $menuItem
37
+ * @param bool $waitMenuItemNotVisible
28
38
* @return void
29
39
*/
30
- public function processAssert (BrowserInterface $ browser , $ businessIntelligenceLink )
31
- {
40
+ public function processAssert (
41
+ BrowserInterface $ browser ,
42
+ $ businessIntelligenceLink ,
43
+ Dashboard $ dashboard ,
44
+ $ menuItem ,
45
+ $ waitMenuItemNotVisible = false
46
+ ) {
47
+ /**
48
+ * In the parallel run case new windows that adding to selenium grid windows handler
49
+ * are in competition with another windows in another browsers in the same selenium grid.
50
+ * During this case need to have some algorithm for retrying some operations that changed
51
+ * current window for browser, because it's some times happens.
52
+ */
32
53
$ this ->browser = $ browser ;
33
- $ this ->browser ->selectWindow ();
34
- \PHPUnit_Framework_Assert::assertTrue (
35
- $ this ->browser ->waitUntil (
36
- function () use ($ businessIntelligenceLink ) {
54
+ $ count = 0 ;
55
+ $ isVisible = false ;
56
+ do {
57
+ try {
58
+ $ this ->browser ->selectWindow ();
59
+ $ isVisible = $ this ->browser ->waitUntil (function () use ($ businessIntelligenceLink ) {
37
60
return ($ this ->browser ->getUrl () === $ businessIntelligenceLink ) ?: null ;
38
- }
39
- ),
40
- 'BI Essentials Sign Up page was not opened by link. '
61
+ });
62
+ break ;
63
+ } catch (\Throwable $ e ) {
64
+ $ dashboard ->open ();
65
+ $ dashboard ->getMenuBlock ()->navigate ($ menuItem , $ waitMenuItemNotVisible );
66
+ $ count ++;
67
+ }
68
+ } while ($ count < self ::MAX_TRY_COUNT );
69
+
70
+ \PHPUnit_Framework_Assert::assertTrue (
71
+ $ isVisible ,
72
+ "BI Essentials Sign Up page was not opened by link. \n
73
+ Actual link is ' {$ this ->browser ->getUrl ()}' \n
74
+ Expected link is ' $ businessIntelligenceLink' "
41
75
);
42
76
}
43
77
0 commit comments