|
| 1 | +package com.seleniumboot.unit; |
| 2 | + |
| 3 | +import com.seleniumboot.config.SeleniumBootConfig; |
| 4 | +import org.openqa.selenium.chrome.ChromeOptions; |
| 5 | +import org.openqa.selenium.firefox.FirefoxOptions; |
| 6 | +import org.testng.annotations.Test; |
| 7 | + |
| 8 | +import static org.testng.Assert.assertEquals; |
| 9 | +import static org.testng.Assert.assertNull; |
| 10 | + |
| 11 | +/** {@code browser.version} is passed to local driver options only when set. */ |
| 12 | +public class BrowserVersionPinTest { |
| 13 | + |
| 14 | + private static void apply(Object options, String version) throws Exception { |
| 15 | + Class<?> pin = Class.forName("com.seleniumboot.driver.BrowserVersionPin"); |
| 16 | + var m = pin.getDeclaredMethod("apply", org.openqa.selenium.remote.AbstractDriverOptions.class, String.class); |
| 17 | + m.setAccessible(true); |
| 18 | + m.invoke(null, options, version); |
| 19 | + } |
| 20 | + |
| 21 | + @Test |
| 22 | + public void chrome_versionSet_isPassedThrough() throws Exception { |
| 23 | + ChromeOptions o = new ChromeOptions(); |
| 24 | + apply(o, "120.0.6099.109"); |
| 25 | + assertEquals(o.getBrowserVersion(), "120.0.6099.109"); |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + public void firefox_versionSet_isPassedThrough() throws Exception { |
| 30 | + FirefoxOptions o = new FirefoxOptions(); |
| 31 | + apply(o, " 121.0 "); |
| 32 | + assertEquals(o.getBrowserVersion(), "121.0"); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void nullOrBlank_leavesVersionUnset() throws Exception { |
| 37 | + ChromeOptions a = new ChromeOptions(); |
| 38 | + apply(a, null); |
| 39 | + ChromeOptions b = new ChromeOptions(); |
| 40 | + apply(b, " "); |
| 41 | + assertEquals(a.getBrowserVersion(), new ChromeOptions().getBrowserVersion()); |
| 42 | + assertEquals(b.getBrowserVersion(), new ChromeOptions().getBrowserVersion()); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void config_defaultsToNull_andRoundTrips() { |
| 47 | + SeleniumBootConfig.Browser b = new SeleniumBootConfig.Browser(); |
| 48 | + assertNull(b.getVersion()); |
| 49 | + b.setVersion("120"); |
| 50 | + assertEquals(b.getVersion(), "120"); |
| 51 | + } |
| 52 | +} |
0 commit comments