Skip to content

Commit 92ca484

Browse files
browser: add browserUrl to set browser only base url
1 parent a76c17a commit 92ca484

4 files changed

Lines changed: 32 additions & 1 deletion

File tree

webtau-browser/src/main/java/org/testingisdocumenting/webtau/browser/Browser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ private String createFullUrl(String url) {
143143
return url;
144144
}
145145

146+
if (!BrowserConfig.getBrowserUrl().isEmpty()) {
147+
return UrlUtils.concat(BrowserConfig.getBrowserUrl(), url);
148+
}
149+
146150
return UrlUtils.concat(getCfg().getBaseUrl(), url);
147151
}
148152

webtau-browser/src/main/java/org/testingisdocumenting/webtau/browser/BrowserConfig.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
public class BrowserConfig implements WebTauConfigHandler {
3030
private static final Supplier<Object> NULL_DEFAULT = () -> null;
3131

32+
private static final ConfigValue browserUrl = declare("browserUrl", "browser base url for application under test. It is being used" +
33+
" instead of url when provided", () -> "");
34+
3235
private static final ConfigValue windowWidth = declare("windowWidth", "browser window width", () -> 1000);
3336
private static final ConfigValue windowHeight = declare("windowHeight", "browser window height", () -> 800);
3437
private static final ConfigValue headless = declareBoolean("headless", "run headless mode");
@@ -47,6 +50,10 @@ public static String getBrowser() {
4750
return browser.getAsString();
4851
}
4952

53+
public static String getBrowserUrl() {
54+
return browserUrl.getAsString();
55+
}
56+
5057
public static int getWindowWidth() {
5158
return windowWidth.getAsInt();
5259
}
@@ -87,6 +94,7 @@ public static Path getFirefoxDriverPath() {
8794
public Stream<ConfigValue> additionalConfigValues() {
8895
return Stream.of(
8996
browser,
97+
browserUrl,
9098
windowWidth,
9199
windowHeight,
92100
headless,

webtau-docs/znai/UI/basic-configuration.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ Define base URL portion either inside a `webtau.cfg` file
1111

1212
or pass as a command line argument `--url=http://...`
1313

14+
# Browser Only Base URL
15+
16+
When you use `url` parameter you set base url for both `REST` and `UI` testing.
17+
18+
Use `browserUrl` to specify `UI` only base url. This can be handy when your backend and frontend live separately.
19+

webtau-feature-testing/src/test/groovy/org/testingisdocumenting/webtau/featuretesting/WebTauBrowserFeaturesTest.groovy

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ class WebTauBrowserFeaturesTest {
7070
runCli('basic.groovy', 'webtau.cfg')
7171
}
7272

73+
@Test
74+
void "open browser using browser url"() {
75+
runCliWithBrowserUrlOverride('basic.groovy', 'webtau.cfg')
76+
}
77+
7378
@Test
7479
void "lazy declaration"() {
7580
runCli('basicDeclareFirst.groovy', 'webtau.cfg')
@@ -277,8 +282,16 @@ class WebTauBrowserFeaturesTest {
277282
}
278283

279284
private static void runCli(String uiTestName, String configFileName) {
285+
runCliWithArgs(uiTestName, configFileName, "--url=${testRunner.testServer.uri}")
286+
}
287+
288+
private static void runCliWithBrowserUrlOverride(String uiTestName, String configFileName) {
289+
runCliWithArgs(uiTestName, configFileName, "--url=http://localhost:-1", "--browserUrl=${testRunner.testServer.uri}")
290+
}
291+
292+
private static void runCliWithArgs(String uiTestName, String configFileName, String... args) {
280293
testRunner.runCli("scenarios/ui/$uiTestName",
281-
"scenarios/ui/$configFileName", "--url=${testRunner.testServer.uri}")
294+
"scenarios/ui/$configFileName", args)
282295
}
283296

284297
private static TestServerHtmlResponse htmlResponse(String resourceName) {

0 commit comments

Comments
 (0)