-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test that verifies that used browsers are of expected version. (#…
…4643) If this fails then we know to check that everything works on the new versions or do a revert on the browser version.
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
flow-tests/test-root-context/src/main/java/com/vaadin/flow/VerifyBrowserVersionView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2000-2017 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow; | ||
|
||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.component.html.Span; | ||
import com.vaadin.flow.router.Route; | ||
import com.vaadin.flow.server.VaadinSession; | ||
import com.vaadin.flow.server.WebBrowser; | ||
|
||
@Route("com.vaadin.flow.VerifyBrowserVersionView") | ||
public class VerifyBrowserVersionView extends Div { | ||
|
||
public VerifyBrowserVersionView() { | ||
WebBrowser browser = VaadinSession.getCurrent().getBrowser(); | ||
Span userAgent = new Span(browser.getBrowserApplication()); | ||
userAgent.setId("userAgent"); | ||
|
||
Span touchDevice = new Span( | ||
"Touch device? " + (browser.isTouchDevice() ? "YES" : "No")); | ||
touchDevice.setId("touchDevice"); | ||
|
||
add(userAgent, touchDevice); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
flow-tests/test-root-context/src/test/java/com/vaadin/flow/VerifyBrowserVersionIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.vaadin.flow; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import org.junit.Test; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.remote.DesiredCapabilities; | ||
|
||
import com.vaadin.flow.testutil.ChromeBrowserTest; | ||
import com.vaadin.testbench.parallel.BrowserUtil; | ||
|
||
public class VerifyBrowserVersionIT extends ChromeBrowserTest { | ||
|
||
@Test | ||
public void verifyUserAgent() { | ||
open(); | ||
|
||
DesiredCapabilities desiredCapabilities = getDesiredCapabilities(); | ||
|
||
String userAgent = findElement(By.id("userAgent")).getText(); | ||
String browserIdentifier; | ||
|
||
if (BrowserUtil.isChrome(getDesiredCapabilities())) { | ||
// Chrome version does not necessarily match the desired version | ||
// because of auto updates... | ||
browserIdentifier = getExpectedUserAgentString( | ||
getDesiredCapabilities()) + "69"; | ||
} else if (BrowserUtil.isFirefox(getDesiredCapabilities())) { | ||
browserIdentifier = getExpectedUserAgentString( | ||
getDesiredCapabilities()) + "58"; | ||
} else { | ||
browserIdentifier = getExpectedUserAgentString(desiredCapabilities) | ||
+ desiredCapabilities.getVersion(); | ||
} | ||
|
||
assertThat(userAgent, containsString(browserIdentifier)); | ||
|
||
assertThat(findElement(By.id("touchDevice")).getText(), | ||
is("Touch device? No")); | ||
} | ||
|
||
private String getExpectedUserAgentString(DesiredCapabilities dCap) { | ||
if (BrowserUtil.isIE(dCap)) { | ||
// IE11 | ||
return "Trident/7.0; rv:"; | ||
} else if (BrowserUtil.isFirefox(dCap)) { | ||
return "Firefox/"; | ||
} else if (BrowserUtil.isChrome(dCap)) { | ||
return "Chrome/"; | ||
} | ||
throw new UnsupportedOperationException( | ||
"Test is being run on unknown browser."); | ||
} | ||
|
||
} |