Skip to content

Commit

Permalink
Add test that verifies that used browsers are of expected version. (#…
Browse files Browse the repository at this point in the history
…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
caalador committed Sep 28, 2018
1 parent 3510c2d commit 6b0da5b
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
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);
}
}
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.");
}

}

0 comments on commit 6b0da5b

Please sign in to comment.