Skip to content

Commit c3359ef

Browse files
committed
test(browser): remover/refactor out every usage of SeleniumQueryBrowserTest.html
[run sauce][run-sauce]
1 parent 6d5e9a3 commit c3359ef

6 files changed

Lines changed: 65 additions & 79 deletions

File tree

src/test/java/endtoend/browser/SeleniumQueryBrowserTest.html

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/test/java/endtoend/browser/SeleniumQueryBrowserTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@ public class SeleniumQueryBrowserTest {
3030

3131
@Test
3232
public void multiple_browser_instances_should_work_OK() {
33+
// given
3334
chrome.$.driver().useHtmlUnit().emulatingChrome();
34-
BrowserAgentTestHelper.openAgentTestHelperUrl(chrome);
35+
// when
36+
BrowserAgentTestHelper.openBrowserAgentTestHelperUrl(chrome);
3537

38+
// given
3639
firefox.$.driver().useHtmlUnit().emulatingFirefox();
37-
BrowserAgentTestHelper.openAgentTestHelperUrl(firefox);
40+
// when
41+
BrowserAgentTestHelper.openBrowserAgentTestHelperUrl(firefox);
3842

43+
// then
3944
BrowserAgentTestHelper.assertBrowserAgent(chrome, HtmlUnitDriverBuilderTest.HTMLUNIT_CHROME_AGENT_STRING);
4045
BrowserAgentTestHelper.assertBrowserAgent(firefox, HtmlUnitDriverBuilderTest.HTMLUNIT_FF_AGENT_STRING);
4146
}

src/test/java/endtoend/browser/driver/builders/ChromeDriverBuilderTest.java

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015 seleniumQuery authors
2+
* Copyright (c) 2017 seleniumQuery authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,24 +16,23 @@
1616

1717
package endtoend.browser.driver.builders;
1818

19-
import endtoend.browser.SeleniumQueryBrowserTest;
19+
import static io.github.seleniumquery.SeleniumQuery.$;
20+
import static org.hamcrest.Matchers.containsString;
21+
import static org.hamcrest.Matchers.not;
22+
import static org.junit.Assume.assumeTrue;
23+
import static testinfrastructure.testutils.EnvironmentTestUtils.isNotWindowsOS;
24+
25+
import java.util.HashMap;
26+
import java.util.Map;
27+
2028
import org.junit.After;
2129
import org.junit.Before;
2230
import org.junit.Test;
2331
import org.openqa.selenium.chrome.ChromeOptions;
2432
import org.openqa.selenium.remote.DesiredCapabilities;
25-
import testinfrastructure.junitrule.SetUpAndTearDownDriver;
2633

27-
import java.util.HashMap;
28-
import java.util.Map;
29-
30-
import static io.github.seleniumquery.SeleniumQuery.$;
31-
import static org.hamcrest.Matchers.containsString;
32-
import static org.hamcrest.Matchers.not;
33-
import static org.junit.Assert.assertThat;
34-
import static org.junit.Assume.assumeTrue;
35-
import static testinfrastructure.EndToEndTestUtils.classNameToTestFileUrl;
36-
import static testinfrastructure.testutils.EnvironmentTestUtils.isNotWindowsOS;
34+
import endtoend.helpers.BrowserAgentTestHelper;
35+
import testinfrastructure.junitrule.SetUpAndTearDownDriver;
3736

3837
public class ChromeDriverBuilderTest {
3938

@@ -60,8 +59,7 @@ public void withOptions() {
6059
// when
6160
$.driver().useChrome().withOptions(options);
6261
// then
63-
$.url(classNameToTestFileUrl(SeleniumQueryBrowserTest.class));
64-
assertThat($("#agent").text(), containsString(CHROME_MOBILE_EMULATION_EXPECTED_AGENT_STRING));
62+
BrowserAgentTestHelper.assertBrowserAgent(containsString(CHROME_MOBILE_EMULATION_EXPECTED_AGENT_STRING));
6563
}
6664

6765
@Test
@@ -74,8 +72,7 @@ public void withCapabilities() {
7472
// when
7573
$.driver().useChrome().withCapabilities(capabilities);
7674
// then
77-
$.url(classNameToTestFileUrl(SeleniumQueryBrowserTest.class));
78-
assertThat($("#agent").text(), containsString(CHROME_MOBILE_EMULATION_EXPECTED_AGENT_STRING));
75+
BrowserAgentTestHelper.assertBrowserAgent(containsString(CHROME_MOBILE_EMULATION_EXPECTED_AGENT_STRING));
7976
}
8077

8178
private ChromeOptions createChromeOptionsWithMobileEmulation() {
@@ -93,8 +90,7 @@ public void withoutCapabilities() {
9390
// when
9491
$.driver().useChrome();
9592
// then
96-
$.url(classNameToTestFileUrl(SeleniumQueryBrowserTest.class));
97-
assertThat($("#agent").text(), not(containsString(CHROME_MOBILE_EMULATION_EXPECTED_AGENT_STRING)));
93+
BrowserAgentTestHelper.assertBrowserAgent(not(containsString(CHROME_MOBILE_EMULATION_EXPECTED_AGENT_STRING)));
9894
}
9995

10096
@Test
@@ -108,7 +104,7 @@ public void withPathToChromeDriver() {
108104
// so this test is really effective, the chromedriver executable shouldnt be in $PATH
109105
$.driver().useChrome().withPathToChromeDriver(getChromeDriverExecutablePath());
110106
// when
111-
$.url(classNameToTestFileUrl(SeleniumQueryBrowserTest.class));
107+
BrowserAgentTestHelper.openBrowserAgentTestHelperUrl();
112108
// then
113109
// no exception is thrown while opening a page
114110
}
@@ -128,7 +124,7 @@ public void useChrome__should_fall_back_to_systemProperty_when_executable_not_fo
128124
System.setProperty("webdriver.chrome.driver", getChromeDriverExecutablePath());
129125
// when
130126
$.driver().useChrome();
131-
$.url(classNameToTestFileUrl(SeleniumQueryBrowserTest.class));
127+
BrowserAgentTestHelper.openBrowserAgentTestHelperUrl();
132128
// then
133129
// no exception is thrown while opening a page
134130
}

src/test/java/endtoend/browser/driver/builders/HtmlUnitDriverBuilderTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void useHtmlUnit__should_emulate_CHROME_by_default() throws Exception {
5353
// when
5454
$.driver().useHtmlUnit();
5555
// then
56-
BrowserAgentTestHelper.assertAgentString(HTMLUNIT_CHROME_AGENT_STRING);
56+
BrowserAgentTestHelper.assertBrowserAgent(HTMLUNIT_CHROME_AGENT_STRING);
5757
}
5858

5959
@Test
@@ -82,7 +82,7 @@ public void emulatingFirefox__should_emulate_latest_firefox__that_is__FIREFOX_45
8282
// when
8383
$.driver().useHtmlUnit().emulatingFirefox();
8484
// then
85-
BrowserAgentTestHelper.assertAgentString(HTMLUNIT_FF_AGENT_STRING);
85+
BrowserAgentTestHelper.assertBrowserAgent(HTMLUNIT_FF_AGENT_STRING);
8686
}
8787

8888
@Test
@@ -91,7 +91,7 @@ public void emulatingChrome__should_emulate_CHROME() {
9191
// when
9292
$.driver().useHtmlUnit().emulatingChrome();
9393
// then
94-
BrowserAgentTestHelper.assertAgentString(HTMLUNIT_CHROME_AGENT_STRING);
94+
BrowserAgentTestHelper.assertBrowserAgent(HTMLUNIT_CHROME_AGENT_STRING);
9595
}
9696

9797
@Test
@@ -100,7 +100,7 @@ public void emulatingInternetExplorer__should_emulate_latest_IE() {
100100
// when
101101
$.driver().useHtmlUnit().emulatingInternetExplorer();
102102
// then
103-
BrowserAgentTestHelper.assertAgentString(HTMLUNIT_IE_AGENT_STRING);
103+
BrowserAgentTestHelper.assertBrowserAgent(HTMLUNIT_IE_AGENT_STRING);
104104
}
105105

106106
}

src/test/java/endtoend/browser/driver/builders/PhantomJSDriverBuilderTest.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016 seleniumQuery authors
2+
* Copyright (c) 2017 seleniumQuery authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,23 +16,23 @@
1616

1717
package endtoend.browser.driver.builders;
1818

19-
import endtoend.browser.SeleniumQueryBrowserTest;
20-
import io.github.seleniumquery.browser.driver.builders.PhantomJSDriverBuilder;
19+
import static io.github.seleniumquery.SeleniumQuery.$;
20+
import static org.hamcrest.CoreMatchers.is;
21+
import static org.hamcrest.Matchers.containsString;
22+
import static org.junit.Assert.assertThat;
23+
import static org.junit.Assume.assumeTrue;
24+
import static testinfrastructure.testutils.EnvironmentTestUtils.onlyRunIfDriverTestExecutableExists;
25+
2126
import org.apache.commons.lang3.SystemUtils;
2227
import org.junit.After;
2328
import org.junit.Before;
2429
import org.junit.Test;
2530
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
2631
import org.openqa.selenium.remote.DesiredCapabilities;
27-
import testinfrastructure.junitrule.SetUpAndTearDownDriver;
2832

29-
import static io.github.seleniumquery.SeleniumQuery.$;
30-
import static org.hamcrest.CoreMatchers.is;
31-
import static org.hamcrest.Matchers.containsString;
32-
import static org.junit.Assert.assertThat;
33-
import static org.junit.Assume.assumeTrue;
34-
import static testinfrastructure.EndToEndTestUtils.classNameToTestFileUrl;
35-
import static testinfrastructure.testutils.EnvironmentTestUtils.onlyRunIfDriverTestExecutableExists;
33+
import endtoend.helpers.BrowserAgentTestHelper;
34+
import io.github.seleniumquery.browser.driver.builders.PhantomJSDriverBuilder;
35+
import testinfrastructure.junitrule.SetUpAndTearDownDriver;
3636

3737
public class PhantomJSDriverBuilderTest {
3838

@@ -54,8 +54,7 @@ public void withCapabilities() {
5454
// when
5555
$.driver().usePhantomJS().withCapabilities(capabilities);
5656
// then
57-
$.url(classNameToTestFileUrl(SeleniumQueryBrowserTest.class));
58-
assertThat($("#agent").text(), containsString("JustAnotherAgent"));
57+
BrowserAgentTestHelper.assertBrowserAgent(containsString("JustAnotherAgent"));
5958
}
6059

6160
@Test
@@ -75,9 +74,9 @@ public void withPathToPhantomJS() {
7574
// given
7675
$.driver().usePhantomJS().withPathToPhantomJS("src/test/resources/phantomjs.exe");
7776
// when
78-
$.url(classNameToTestFileUrl(SeleniumQueryBrowserTest.class));
77+
BrowserAgentTestHelper.openBrowserAgentTestHelperUrl();
7978
// then
8079
// no exception is thrown while opening a page
8180
}
8281

83-
}
82+
}

src/test/java/endtoend/helpers/BrowserAgentTestHelper.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,43 @@
1616

1717
package endtoend.helpers;
1818

19-
import static org.junit.Assert.assertEquals;
19+
import static org.junit.Assert.assertThat;
2020
import static testinfrastructure.EndToEndTestUtils.classNameToTestFileUrl;
2121

22+
import org.hamcrest.Matcher;
23+
import org.hamcrest.Matchers;
24+
2225
import io.github.seleniumquery.SeleniumQuery;
2326
import io.github.seleniumquery.SeleniumQueryBrowser;
2427

2528
public class BrowserAgentTestHelper {
2629

2730
private static final String AGENT_TEST_URL = classNameToTestFileUrl(BrowserAgentTestHelper.class);
2831

29-
public static void assertAgentString(String agentString) {
30-
SeleniumQueryBrowser globalBrowser = SeleniumQuery.seleniumQueryBrowser();
31-
openAgentTestHelperUrl(globalBrowser);
32-
assertBrowserAgent(globalBrowser, agentString);
32+
public static void assertBrowserAgent(String agentString) {
33+
openBrowserAgentTestHelperUrl();
34+
assertBrowserAgent(SeleniumQuery.seleniumQueryBrowser(), agentString);
3335
}
3436

35-
public static void assertBrowserAgent(SeleniumQueryBrowser browser, String agentString) {
36-
assertEquals(agentString, browser.$("#agent").text());
37+
public static void assertBrowserAgent(Matcher<String> agentMatcher) {
38+
openBrowserAgentTestHelperUrl();
39+
assertBrowserAgent(SeleniumQuery.seleniumQueryBrowser(), agentMatcher);
3740
}
3841

39-
public static void openAgentTestHelperUrl(SeleniumQueryBrowser browser) {
42+
public static void openBrowserAgentTestHelperUrl() {
43+
openBrowserAgentTestHelperUrl(SeleniumQuery.seleniumQueryBrowser());
44+
}
45+
46+
public static void openBrowserAgentTestHelperUrl(SeleniumQueryBrowser browser) {
4047
browser.$.url(BrowserAgentTestHelper.AGENT_TEST_URL);
4148
}
4249

50+
public static void assertBrowserAgent(SeleniumQueryBrowser browser, String agentString) {
51+
assertBrowserAgent(browser, Matchers.equalTo(agentString));
52+
}
53+
54+
public static void assertBrowserAgent(SeleniumQueryBrowser browser, Matcher<String> agentMatcher) {
55+
assertThat(browser.$("#agent").text(), agentMatcher);
56+
}
57+
4358
}

0 commit comments

Comments
 (0)