Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit e194634

Browse files
committed
Renamed most of the browser operations and changed the API to be non-fluent
- Names now reflect what the classes responsibilities are - getter methods on browser have not been changed since their names are based on API calls - Instead of returning the linked Browser instance most operation methods now return void. The fluent API had some drawbacks which need to be addressed in future releases.
1 parent ffe0c03 commit e194634

34 files changed

+212
-273
lines changed

webtester-core/src/main/java/info/novatec/testit/webtester/browser/Browser.java

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import org.openqa.selenium.WebDriver;
44

55
import info.novatec.testit.webtester.browser.operations.AlertHandler;
6-
import info.novatec.testit.webtester.browser.operations.Focus;
7-
import info.novatec.testit.webtester.browser.operations.JavaScript;
8-
import info.novatec.testit.webtester.browser.operations.Navigate;
9-
import info.novatec.testit.webtester.browser.operations.Open;
10-
import info.novatec.testit.webtester.browser.operations.PageSource;
11-
import info.novatec.testit.webtester.browser.operations.Screenshot;
12-
import info.novatec.testit.webtester.browser.operations.Window;
6+
import info.novatec.testit.webtester.browser.operations.FocusSetter;
7+
import info.novatec.testit.webtester.browser.operations.JavaScriptExecutor;
8+
import info.novatec.testit.webtester.browser.operations.Navigator;
9+
import info.novatec.testit.webtester.browser.operations.UrlOpener;
10+
import info.novatec.testit.webtester.browser.operations.PageSourceSaver;
11+
import info.novatec.testit.webtester.browser.operations.ScreenshotTaker;
12+
import info.novatec.testit.webtester.browser.operations.CurrentWindow;
1313
import info.novatec.testit.webtester.config.Configuration;
1414
import info.novatec.testit.webtester.events.EventSystem;
1515
import info.novatec.testit.webtester.pagefragments.PageFragment;
@@ -54,14 +54,14 @@
5454
* @see BrowserBuilder
5555
* @see BrowserFactory
5656
* @see Configuration
57-
* @see Open
58-
* @see Window
59-
* @see Navigate
60-
* @see Focus
57+
* @see UrlOpener
58+
* @see CurrentWindow
59+
* @see Navigator
60+
* @see FocusSetter
6161
* @see AlertHandler
62-
* @see Screenshot
63-
* @see PageSource
64-
* @see JavaScript
62+
* @see ScreenshotTaker
63+
* @see PageSourceSaver
64+
* @see JavaScriptExecutor
6565
* @since 2.0
6666
*/
6767
public interface Browser extends OffersPageCreation, OffersAdHocFinding {
@@ -98,44 +98,45 @@ public interface Browser extends OffersPageCreation, OffersAdHocFinding {
9898
9999
* @param url the URL to open
100100
* @return the same instance for fluent API use
101-
* @see Open#url(String)
101+
* @see UrlOpener#url(String)
102102
* @since 2.0
103103
*/
104104
default Browser open(String url) {
105-
return open().url(url);
105+
open().url(url);
106+
return this;
106107
}
107108

108109
/**
109-
* Returns this {@link Browser browser's} {@link Open open} operations.
110+
* Returns this {@link Browser browser's} {@link UrlOpener open} operations.
110111
*
111112
* @return the open operations
112113
* @since 2.0
113114
*/
114-
Open open();
115+
UrlOpener open();
115116

116117
/**
117-
* Returns this {@link Browser browser's} {@link Window window} operations.
118+
* Returns this {@link Browser browser's} {@link CurrentWindow window} operations.
118119
*
119120
* @return the window operations
120121
* @since 2.0
121122
*/
122-
Window currentWindow();
123+
CurrentWindow currentWindow();
123124

124125
/**
125-
* Returns this {@link Browser browser's} {@link Navigate navigation} operations.
126+
* Returns this {@link Browser browser's} {@link Navigator navigation} operations.
126127
*
127128
* @return the navigation operations
128129
* @since 2.0
129130
*/
130-
Navigate navigate();
131+
Navigator navigate();
131132

132133
/**
133-
* Returns this {@link Browser browser's} {@link Focus focus} operations.
134+
* Returns this {@link Browser browser's} {@link FocusSetter focus} operations.
134135
*
135136
* @return the focus operations
136137
* @since 2.0
137138
*/
138-
Focus focus();
139+
FocusSetter focus();
139140

140141
/**
141142
* Returns this {@link Browser browser's} {@link AlertHandler alert} operations.
@@ -146,28 +147,28 @@ default Browser open(String url) {
146147
AlertHandler alert();
147148

148149
/**
149-
* Returns this {@link Browser browser's} {@link Screenshot screenshot} operations.
150+
* Returns this {@link Browser browser's} {@link ScreenshotTaker screenshot} operations.
150151
*
151152
* @return the screenshot operations
152153
* @since 2.0
153154
*/
154-
Screenshot screenshot();
155+
ScreenshotTaker screenshot();
155156

156157
/**
157-
* Returns this {@link Browser browser's} {@link PageSource page source} operations.
158+
* Returns this {@link Browser browser's} {@link PageSourceSaver page source} operations.
158159
*
159160
* @return the page source operations
160161
* @since 2.0
161162
*/
162-
PageSource pageSource();
163+
PageSourceSaver pageSource();
163164

164165
/**
165-
* Returns this {@link Browser browser's} {@link JavaScript} operations.
166+
* Returns this {@link Browser browser's} {@link JavaScriptExecutor} operations.
166167
*
167168
* @return the JavaScript operations
168169
* @since 2.0
169170
*/
170-
JavaScript javaScript();
171+
JavaScriptExecutor javaScript();
171172

172173

173174
/**

webtester-core/src/main/java/info/novatec/testit/webtester/browser/WebDriverBrowser.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import lombok.extern.slf4j.Slf4j;
77

88
import info.novatec.testit.webtester.browser.operations.AlertHandler;
9-
import info.novatec.testit.webtester.browser.operations.Focus;
10-
import info.novatec.testit.webtester.browser.operations.JavaScript;
11-
import info.novatec.testit.webtester.browser.operations.Navigate;
12-
import info.novatec.testit.webtester.browser.operations.Open;
13-
import info.novatec.testit.webtester.browser.operations.PageSource;
14-
import info.novatec.testit.webtester.browser.operations.Screenshot;
15-
import info.novatec.testit.webtester.browser.operations.Window;
9+
import info.novatec.testit.webtester.browser.operations.FocusSetter;
10+
import info.novatec.testit.webtester.browser.operations.JavaScriptExecutor;
11+
import info.novatec.testit.webtester.browser.operations.Navigator;
12+
import info.novatec.testit.webtester.browser.operations.UrlOpener;
13+
import info.novatec.testit.webtester.browser.operations.PageSourceSaver;
14+
import info.novatec.testit.webtester.browser.operations.ScreenshotTaker;
15+
import info.novatec.testit.webtester.browser.operations.CurrentWindow;
1616
import info.novatec.testit.webtester.config.Configuration;
1717
import info.novatec.testit.webtester.config.builders.DefaultConfigurationBuilder;
1818
import info.novatec.testit.webtester.events.EventSystem;
@@ -47,33 +47,33 @@ public final class WebDriverBrowser implements Browser {
4747

4848
private final WebDriver webDriver;
4949

50-
private final Open open;
51-
private final Window window;
52-
private final Navigate navigate;
50+
private final UrlOpener open;
51+
private final CurrentWindow window;
52+
private final Navigator navigate;
5353
private final AlertHandler alert;
54-
private final Screenshot screenshot;
55-
private final PageSource pageSource;
56-
private final JavaScript javaScript;
54+
private final ScreenshotTaker screenshot;
55+
private final PageSourceSaver pageSource;
56+
private final JavaScriptExecutor javaScript;
5757
private final EventSystem eventSystem;
5858
private final AdHocFinder adHocFinder;
5959
private final PageFactory pageFactory;
6060

61-
private final Focus focus;
61+
private final FocusSetter focus;
6262
private boolean closed;
6363

6464
private WebDriverBrowser(Configuration configuration, WebDriver webDriver) {
6565

6666
this.configuration = configuration;
6767
this.webDriver = webDriver;
6868

69-
this.open = new Open(this);
70-
this.window = new Window(this);
71-
this.navigate = new Navigate(this);
69+
this.open = new UrlOpener(this);
70+
this.window = new CurrentWindow(this);
71+
this.navigate = new Navigator(this);
7272
this.alert = new AlertHandler(this);
73-
this.screenshot = new Screenshot(this);
74-
this.pageSource = new PageSource(this);
75-
this.javaScript = new JavaScript(this);
76-
this.focus = new Focus(this);
73+
this.screenshot = new ScreenshotTaker(this);
74+
this.pageSource = new PageSourceSaver(this);
75+
this.javaScript = new JavaScriptExecutor(this);
76+
this.focus = new FocusSetter(this);
7777
this.eventSystem = new EventSystemImpl(this);
7878
this.adHocFinder = new AdHocFinder(this);
7979
this.pageFactory = new PageFactory(this);
@@ -124,22 +124,22 @@ public WebDriver webDriver() {
124124
}
125125

126126
@Override
127-
public Open open() {
127+
public UrlOpener open() {
128128
return open;
129129
}
130130

131131
@Override
132-
public Window currentWindow() {
132+
public CurrentWindow currentWindow() {
133133
return window;
134134
}
135135

136136
@Override
137-
public Focus focus() {
137+
public FocusSetter focus() {
138138
return focus;
139139
}
140140

141141
@Override
142-
public Navigate navigate() {
142+
public Navigator navigate() {
143143
return navigate;
144144
}
145145

@@ -149,17 +149,17 @@ public AlertHandler alert() {
149149
}
150150

151151
@Override
152-
public Screenshot screenshot() {
152+
public ScreenshotTaker screenshot() {
153153
return screenshot;
154154
}
155155

156156
@Override
157-
public PageSource pageSource() {
157+
public PageSourceSaver pageSource() {
158158
return pageSource;
159159
}
160160

161161
@Override
162-
public JavaScript javaScript() {
162+
public JavaScriptExecutor javaScript() {
163163
return javaScript;
164164
}
165165

webtester-core/src/main/java/info/novatec/testit/webtester/browser/operations/AlertHandler.java

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,12 @@ public AlertHandler(Browser browser) {
4444
*
4545
* @param username the username to use
4646
* @param password the password to use
47-
* @return the original browser of this operation
4847
* @see Alert#authenticateUsing(Credentials)
4948
* @since 2.0
5049
*/
5150
@Beta
52-
public Browser authenticateWith(String username, String password) {
53-
return authenticateWith(new UserAndPassword(username, password));
51+
public void authenticateWith(String username, String password) {
52+
authenticateWith(new UserAndPassword(username, password));
5453
}
5554

5655
/**
@@ -59,15 +58,13 @@ public Browser authenticateWith(String username, String password) {
5958
* This operation is decalred as "BETA" by the Selenium developers and might break in the future in case it changes.
6059
*
6160
* @param credentials the credentials to use
62-
* @return the original browser of this operation
6361
* @see Alert#authenticateUsing(Credentials)
6462
* @since 2.0
6563
*/
6664
@Beta
67-
public Browser authenticateWith(Credentials credentials) {
65+
public void authenticateWith(Credentials credentials) {
6866
ActionTemplate.browser(browser()).execute(browser -> webDriver().switchTo().alert().authenticateUsing(credentials));
6967
log.debug("authenticated using credentials: {}", credentials);
70-
return browser();
7168
}
7269

7370
/**
@@ -76,38 +73,35 @@ public Browser authenticateWith(Credentials credentials) {
7673
* <p>
7774
* Fires {@link AcceptedAlertEvent} in case a alert was successfully accepted.
7875
*
79-
* @return the original browser of this operation
8076
* @see Alert#accept()
8177
* @since 2.0
8278
*/
83-
public Browser acceptIfPresent() {
79+
public void acceptIfPresent() {
8480
if (isPresent()) {
8581
log.debug("alert was visible");
86-
return accept();
82+
accept();
83+
} else {
84+
log.debug("alert was not visible");
8785
}
88-
log.debug("alert was not visible");
89-
return browser();
9086
}
9187

9288
/**
9389
* Accept any displayed alert message. If no alert is displayed, an exception will be thrown.
9490
* <p>
9591
* Fires {@link AcceptedAlertEvent} in case a alert was successfully accepted.
9692
*
97-
* @return the original browser of this operation
9893
* @throws NoAlertPresentException in case no alert is present
9994
* @see Alert#accept()
10095
* @since 2.0
10196
*/
102-
public Browser accept() throws NoAlertPresentException {
97+
public void accept() throws NoAlertPresentException {
10398
StringBuilder builder = new StringBuilder();
10499
ActionTemplate.browser(browser()).execute(browser -> {
105100
Alert alert = webDriver().switchTo().alert();
106101
builder.append(alert.getText());
107102
alert.accept();
108103
}).fireEvent(browser -> new AcceptedAlertEvent(builder.toString()));
109104
log.debug("alert was accepted");
110-
return browser();
111105
}
112106

113107
/**
@@ -116,38 +110,35 @@ public Browser accept() throws NoAlertPresentException {
116110
* <p>
117111
* Fires {@link DeclinedAlertEvent} in case a alert was successfully accepted.
118112
*
119-
* @return the original browser of this operation
120113
* @see Alert#dismiss()
121114
* @since 2.0
122115
*/
123-
public Browser declineIfPresent() {
116+
public void declineIfPresent() {
124117
if (isPresent()) {
125118
log.debug("alert was visible");
126-
return decline();
119+
decline();
120+
} else {
121+
log.debug("alert was not visible");
127122
}
128-
log.debug("alert was not visible");
129-
return browser();
130123
}
131124

132125
/**
133126
* Declines any displayed alert message. If no alert is displayed, an exception will be thrown.
134127
* <p>
135128
* Fires {@link DeclinedAlertEvent} in case a alert was successfully accepted.
136129
*
137-
* @return the original browser of this operation
138130
* @throws NoAlertPresentException in case no alert is present
139131
* @see Alert#dismiss()
140132
* @since 2.0
141133
*/
142-
public Browser decline() throws NoAlertPresentException {
134+
public void decline() throws NoAlertPresentException {
143135
StringBuilder builder = new StringBuilder();
144136
ActionTemplate.browser(browser()).execute(browser -> {
145137
Alert alert = webDriver().switchTo().alert();
146138
builder.append(alert.getText());
147139
alert.dismiss();
148140
}).fireEvent(browser -> new DeclinedAlertEvent(builder.toString()));
149141
log.debug("alert was declined");
150-
return browser();
151142
}
152143

153144
/**

webtester-core/src/main/java/info/novatec/testit/webtester/browser/operations/BaseBrowserOperation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ protected BaseBrowserOperation(Browser browser) {
1515
this.browser = browser;
1616
}
1717

18-
protected final Browser browser() {
18+
protected Browser browser() {
1919
return browser;
2020
}
2121

22-
protected final Configuration configuration() {
22+
protected Configuration configuration() {
2323
return browser.configuration();
2424
}
2525

26-
protected final WebDriver webDriver() {
26+
protected WebDriver webDriver() {
2727
return browser.webDriver();
2828
}
2929

0 commit comments

Comments
 (0)