2
2
3
3
import com .octopus .AutomatedBrowser ;
4
4
import com .octopus .AutomatedBrowserFactory ;
5
+ import com .octopus .exceptions .BrowserException ;
5
6
import cucumber .api .java .en .And ;
6
7
import cucumber .api .java .en .Given ;
7
8
import org .openqa .selenium .WebDriver ;
@@ -14,6 +15,7 @@ public class AutomatedBrowserBase implements AutomatedBrowser {
14
15
static private final AutomatedBrowserFactory AUTOMATED_BROWSER_FACTORY = new AutomatedBrowserFactory ();
15
16
private Map <String , String > aliases = new HashMap <>();
16
17
private AutomatedBrowser automatedBrowser ;
18
+ private static AutomatedBrowser sharedAutomatedBrowser ;
17
19
18
20
public AutomatedBrowserBase () {
19
21
@@ -24,6 +26,9 @@ public AutomatedBrowserBase(final AutomatedBrowser automatedBrowser) {
24
26
}
25
27
26
28
public AutomatedBrowser getAutomatedBrowser () {
29
+ if (sharedAutomatedBrowser != null )
30
+ return sharedAutomatedBrowser ;
31
+
27
32
return automatedBrowser ;
28
33
}
29
34
@@ -32,10 +37,19 @@ public void setAliases(Map<String, String> aliases) {
32
37
this .aliases .putAll (aliases );
33
38
}
34
39
35
- @ Given ("^I open the browser \" ([^\" ]*)\" $" )
36
- public void openBrowser (String browser ) {
37
- automatedBrowser = AUTOMATED_BROWSER_FACTORY .getAutomatedBrowser (browser );
38
- automatedBrowser .init ();
40
+ @ Given ("^I open the( shared ) browser \" ([^\" ]*)\" $" )
41
+ public void openBrowser (String shared , String browser ) {
42
+ if (shared != null ) {
43
+ sharedAutomatedBrowser = AUTOMATED_BROWSER_FACTORY .getAutomatedBrowser (browser );
44
+ sharedAutomatedBrowser .init ();
45
+ } else {
46
+ if (sharedAutomatedBrowser != null ) {
47
+ throw new BrowserException ("Can not open a browser with an existing shared browser." );
48
+ }
49
+
50
+ automatedBrowser = AUTOMATED_BROWSER_FACTORY .getAutomatedBrowser (browser );
51
+ automatedBrowser .init ();
52
+ }
39
53
}
40
54
41
55
@ Given ("^I close the browser$" )
@@ -44,6 +58,11 @@ public void closeBrowser() {
44
58
automatedBrowser .destroy ();
45
59
automatedBrowser = null ;
46
60
}
61
+
62
+ if (sharedAutomatedBrowser != null ) {
63
+ sharedAutomatedBrowser .destroy ();
64
+ sharedAutomatedBrowser = null ;
65
+ }
47
66
}
48
67
49
68
@ And ("^I set the default explicit wait time to \" (\\ d+)\" seconds?$" )
0 commit comments