NavigateAction extends AbstractSeleniumAction { @Override protected void execute(SeleniumBrowser browser, TestContext context) { if (page.equals("back")) { browser.getWebDriver().navigate().back(); } else if (page.equals("forward")) { browser.getWebDriver().navigate().forward(); } else if (page.equals("refresh")) { browser.getWebDriver().navigate().refresh(); } else { try { if (browser.getEndpointConfiguration().getBrowserType().equals(BrowserType.IE)) { String cachingSafeUrl = BrowserUtils.makeIECachingSafeUrl(context.replaceDynamicContentInString(page), new Date().getTime()); browser.getWebDriver().navigate().to(new URL(cachingSafeUrl)); } else { browser.getWebDriver().navigate().to(new URL(context.replaceDynamicContentInString(page))); } } catch (MalformedURLException ex) { String baseUrl = browser.getWebDriver().getCurrentUrl(); try { new URL(baseUrl); } catch (MalformedURLException e) { if (StringUtils.hasText(browser.getEndpointConfiguration().getStartPageUrl())) { baseUrl = browser.getEndpointConfiguration().getStartPageUrl(); } else { throw new CitrusRuntimeException("Failed to create relative page URL - must set start page on browser", ex); } } String lastChar = baseUrl.substring(baseUrl.length() - 1); if (!lastChar.equals("/")) { baseUrl = baseUrl + "/"; } browser.getWebDriver().navigate().to(baseUrl + context.replaceDynamicContentInString(page)); } } } NavigateAction(Builder builder); String getPage();  }
@Test public void testNavigatePageUrl() throws Exception { seleniumBrowser.getEndpointConfiguration().setBrowserType(BrowserType.CHROME); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Assert.assertEquals(invocation.getArguments()[0].toString(), "http: return null; } }).when(navigation).to(any(URL.class)); NavigateAction action = new NavigateAction.Builder() .browser(seleniumBrowser) .page("http: .build(); action.execute(context); verify(navigation).to(any(URL.class)); }
@Test public void testNavigatePageUrlInternetExplorer() throws Exception { seleniumBrowser.getEndpointConfiguration().setBrowserType(BrowserType.IE); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Assert.assertTrue(invocation.getArguments()[0].toString().startsWith("http: return null; } }).when(navigation).to(any(URL.class)); NavigateAction action = new NavigateAction.Builder() .browser(seleniumBrowser) .page("http: .build(); action.execute(context); verify(navigation).to(any(URL.class)); }
@Test public void testNavigateRelativePageUrl() throws Exception { seleniumBrowser.getEndpointConfiguration().setBrowserType(BrowserType.IE); seleniumBrowser.getEndpointConfiguration().setStartPageUrl("http: NavigateAction action = new NavigateAction.Builder() .browser(seleniumBrowser) .page("info") .build(); action.execute(context); verify(navigation).to("http: }
@Test public void testExecuteBack() throws Exception { NavigateAction action = new NavigateAction.Builder() .browser(seleniumBrowser) .page("back") .build(); action.execute(context); verify(navigation).back(); }
@Test public void testExecuteForward() throws Exception { NavigateAction action = new NavigateAction.Builder() .browser(seleniumBrowser) .page("forward") .build(); action.execute(context); verify(navigation).forward(); }
@Test public void testExecuteRefresh() throws Exception { NavigateAction action = new NavigateAction.Builder() .browser(seleniumBrowser) .page("refresh") .build(); action.execute(context); verify(navigation).refresh(); }