From bff5526f5635a086fca4ea67dd4e79410d373c1e Mon Sep 17 00:00:00 2001 From: Alec Henninger Date: Wed, 8 Jul 2015 18:26:45 -0400 Subject: [PATCH 01/42] Use latest version of darcy-web --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fe63abb..f95a488 100644 --- a/pom.xml +++ b/pom.xml @@ -59,7 +59,7 @@ com.redhat.darcy darcy-web - 0.2.2-SNAPSHOT + 0.2.3-SNAPSHOT com.redhat.synq From 654e8d10537dfa03ba55b4b7e3253a45e2e6d387 Mon Sep 17 00:00:00 2001 From: Alec Henninger Date: Sat, 11 Jul 2015 18:22:29 -0400 Subject: [PATCH 02/42] Add sudo:false to .travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 963ad52..23f0f1c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: java jdk: - oraclejdk8 +sudo: false before_script: - git clone -b travis `git config --get remote.origin.url` target/travis From 81b6fc8e6c641d89b5b6bed1d2b6c3f3565af1a9 Mon Sep 17 00:00:00 2001 From: Alec Henninger Date: Sun, 12 Jul 2015 14:03:13 -0400 Subject: [PATCH 03/42] Implement FindsByUrl --- .../darcy/webdriver/WebDriverBrowser.java | 11 +++ .../webdriver/WebDriverParentContext.java | 3 +- .../internal/DelegatingWebContext.java | 25 ++++++ .../TargetedWebDriverParentContext.java | 52 +++++++++++- .../webdriver/internal/WebDriverTargets.java | 77 ++++++++++++++++- .../TargetedWebDriverParentContextTest.java | 55 +++++++++++- .../WindowTitleWebDriverTargetTest.java | 1 - .../WindowUrlWebDriverTargetTest.java | 84 +++++++++++++++++++ .../doubles/StubWebDriverParentContext.java | 12 +++ 9 files changed, 311 insertions(+), 9 deletions(-) create mode 100644 src/test/java/com/redhat/darcy/webdriver/internal/WindowUrlWebDriverTargetTest.java diff --git a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java index fb6bea2..e5c045c 100644 --- a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java +++ b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java @@ -41,6 +41,7 @@ import com.redhat.darcy.webdriver.internal.WrapsTargetedDriver; import com.redhat.synq.Event; +import org.hamcrest.Matcher; import org.openqa.selenium.NoSuchFrameException; import org.openqa.selenium.NoSuchWindowException; import org.openqa.selenium.remote.SessionNotFoundException; @@ -327,6 +328,16 @@ public T findByTitle(Class type, String title) { return attemptAndGet(() -> webContext.findByTitle(type, title)); } + @Override + public List findAllByUrl(Class type, Matcher urlMatcher) { + return attemptAndGet(() -> webContext.findAllByUrl(type, urlMatcher)); + } + + @Override + public T findByUrl(Class type, Matcher urlMatcher) { + return attemptAndGet(() -> webContext.findByUrl(type, urlMatcher)); + } + @Override public TargetedWebDriver getWrappedDriver() { return driver; diff --git a/src/main/java/com/redhat/darcy/webdriver/WebDriverParentContext.java b/src/main/java/com/redhat/darcy/webdriver/WebDriverParentContext.java index e6808f0..8b916d9 100644 --- a/src/main/java/com/redhat/darcy/webdriver/WebDriverParentContext.java +++ b/src/main/java/com/redhat/darcy/webdriver/WebDriverParentContext.java @@ -25,8 +25,9 @@ import com.redhat.darcy.ui.internal.FindsByTitle; import com.redhat.darcy.ui.internal.FindsByView; import com.redhat.darcy.web.api.Alert; +import com.redhat.darcy.web.internal.FindsByUrl; public interface WebDriverParentContext extends ParentContext, FindsById, FindsByName, FindsByView, - FindsByTitle { + FindsByTitle, FindsByUrl { Alert alert(); } diff --git a/src/main/java/com/redhat/darcy/webdriver/internal/DelegatingWebContext.java b/src/main/java/com/redhat/darcy/webdriver/internal/DelegatingWebContext.java index 359e53a..7af97b1 100644 --- a/src/main/java/com/redhat/darcy/webdriver/internal/DelegatingWebContext.java +++ b/src/main/java/com/redhat/darcy/webdriver/internal/DelegatingWebContext.java @@ -39,9 +39,12 @@ import com.redhat.darcy.web.internal.FindsByClassName; import com.redhat.darcy.web.internal.FindsByCss; import com.redhat.darcy.web.internal.FindsByHtmlTag; +import com.redhat.darcy.web.internal.FindsByUrl; import com.redhat.darcy.webdriver.WebDriverElementContext; import com.redhat.darcy.webdriver.WebDriverParentContext; +import org.hamcrest.Matcher; + import java.util.List; import java.util.Objects; @@ -382,6 +385,28 @@ public T findByTitle(Class type, String title) { } } + @Override + public List findAllByUrl(Class type, Matcher urlMatcher) { + try { + FindsByUrl context = (FindsByUrl) contextForType(type); + + return context.findAllByUrl(type, urlMatcher); + } catch (ClassCastException e) { + throw unsupportedLocatorForType("url matching, " + urlMatcher, type); + } + } + + @Override + public T findByUrl(Class type, Matcher urlMatcher) { + try { + FindsByUrl context = (FindsByUrl) contextForType(type); + + return context.findByUrl(type, urlMatcher); + } catch (ClassCastException e) { + throw unsupportedLocatorForType("url matching, " + urlMatcher, type); + } + } + /** * Returns the ElementContext or PraentContext depending on if the type of thing we're looking * for is an element or a context. diff --git a/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContext.java b/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContext.java index 0401233..82d4f48 100644 --- a/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContext.java +++ b/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContext.java @@ -32,6 +32,7 @@ import com.redhat.darcy.webdriver.WebDriverBrowser; import com.redhat.darcy.webdriver.WebDriverParentContext; +import org.hamcrest.Matcher; import org.openqa.selenium.WebDriver.TargetLocator; import java.util.ArrayList; @@ -41,7 +42,7 @@ import java.util.function.Supplier; /** - * {@link ParentContext} for {@link TargetedWebDriver}s that instantiates other + * {@link ParentContext} for {@link TargetedWebDriver}s that instantiates other * {@link com.redhat.darcy.webdriver.WebDriverBrowser}s with {@link TargetedWebDriver}s assigned to * them that point to the found driver. */ @@ -168,6 +169,34 @@ public T findByTitle(Class type, String title) { return (T) newBrowser(WebDriverTargets.windowByTitle(title)); } + @Override + public List findAllByUrl(Class type, Matcher urlMatcher) { + if (!type.isAssignableFrom(WebDriverBrowser.class)) { + throw new DarcyException("Cannot find contexts of type: " + type); + } + + if (Frame.class.equals(type)) { + throw new DarcyException("Cannot find Frames by url. Unable to iterate through all " + + "available frames."); + } + + return (List) new LazyList(new FoundByUrlSupplier(urlMatcher)); + } + + @Override + public T findByUrl(Class type, Matcher urlMatcher) { + if (!type.isAssignableFrom(WebDriverBrowser.class)) { + throw new DarcyException("Cannot find contexts of type: " + type); + } + + if (Frame.class.equals(type)) { + throw new DarcyException("Cannot find Frames by url. Unable to iterate through all " + + "available frames."); + } + + return (T) newBrowser(WebDriverTargets.windowByUrl(urlMatcher)); + } + @Override public boolean equals(Object o) { if (this == o) { @@ -254,4 +283,25 @@ public List get() { return found; } } + + private class FoundByUrlSupplier implements Supplier> { + private final Matcher urlMatcher; + + public FoundByUrlSupplier(Matcher urlMatcher) { + this.urlMatcher = urlMatcher; + } + + @Override + public List get() { + List found = new ArrayList<>(); + + for (String windowHandle : locator.defaultContent().getWindowHandles()) { + if (urlMatcher.matches(locator.window(windowHandle).getCurrentUrl())) { + found.add(findById(Browser.class, windowHandle)); + } + } + + return found; + } + } } diff --git a/src/main/java/com/redhat/darcy/webdriver/internal/WebDriverTargets.java b/src/main/java/com/redhat/darcy/webdriver/internal/WebDriverTargets.java index 062d04f..208eb75 100644 --- a/src/main/java/com/redhat/darcy/webdriver/internal/WebDriverTargets.java +++ b/src/main/java/com/redhat/darcy/webdriver/internal/WebDriverTargets.java @@ -26,6 +26,7 @@ import com.redhat.darcy.util.Caching; import com.redhat.darcy.web.api.Browser; +import org.hamcrest.Matcher; import org.openqa.selenium.NoSuchWindowException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver.TargetLocator; @@ -65,6 +66,10 @@ public static WebDriverTarget windowByTitle(String title) { return new WindowTitleWebDriverTarget(title); } + public static WebDriverTarget windowByUrl(Matcher urlMatcher) { + return new WindowUrlWebDriverTarget(urlMatcher); + } + /** * Determines the parent target of the specified * {@link com.redhat.darcy.webdriver.internal.WebDriverTarget}. If the target has no parent @@ -348,8 +353,11 @@ public boolean equals(Object o) { @Override public String toString() { - return "ViewWebDriverTarget: {view: " + view + ", parentContext: " - + parentContext + "}"; + return "ViewWebDriverTarget{" + + "view=" + view + + ", parentContext=" + parentContext + + ", windowHandle='" + windowHandle + '\'' + + '}'; } private String findWindow(TargetLocator targetLocator) { @@ -416,6 +424,7 @@ public int hashCode() { public String toString() { return "WindowTitleWebDriverTarget{" + "title='" + title + '\'' + + ", windowHandle='" + windowHandle + '\'' + '}'; } @@ -429,4 +438,68 @@ private String findWindow(TargetLocator targetLocator) { throw new NoSuchWindowException("No window in driver found which has title: " + title); } } + + public static class WindowUrlWebDriverTarget implements WebDriverTarget, Caching { + private final Matcher urlMatcher; + + /** + * Stores window handle of window which has the title so subsequent lookups always refer to + * the same window. + */ + private String windowHandle; + + public WindowUrlWebDriverTarget(Matcher urlMatcher) { + this.urlMatcher = Objects.requireNonNull(urlMatcher, "urlMatcher"); + } + + @Override + public WebDriver switchTo(TargetLocator targetLocator) { + if (windowHandle == null) { + windowHandle = findWindow(targetLocator); + } + + return targetLocator.window(windowHandle); + } + + @Override + public void invalidateCache() { + windowHandle = null; + } + + private String findWindow(TargetLocator targetLocator) { + for (String windowHandle : targetLocator.defaultContent().getWindowHandles()) { + if (urlMatcher.matches(targetLocator.window(windowHandle).getCurrentUrl())) { + return windowHandle; + } + } + + throw new NoSuchWindowException("No window in driver found which has url matching: " + urlMatcher); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + WindowUrlWebDriverTarget that = (WindowUrlWebDriverTarget) o; + return Objects.equals(urlMatcher, that.urlMatcher) && + Objects.equals(windowHandle, that.windowHandle); + } + + @Override + public int hashCode() { + return Objects.hash(urlMatcher, windowHandle); + } + + @Override + public String toString() { + return "WindowUrlWebDriverTarget{" + + "urlMatcher=" + urlMatcher + + ", windowHandle='" + windowHandle + '\'' + + '}'; + } + } } diff --git a/src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContextTest.java b/src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContextTest.java index 7ec2efe..da21aeb 100644 --- a/src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContextTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContextTest.java @@ -22,6 +22,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.junit.Assert.assertFalse; @@ -170,10 +171,56 @@ public void shouldFindAllBrowsersByTitle() { List browsers = context.findAllByTitle(Browser.class, "shared title"); assertThat(browsers.stream() - .map(b -> (WebDriverBrowser) b) - .map(WebDriverBrowser::getWrappedDriver) - .map(TargetedWebDriver::getWebDriverTarget) - .collect(Collectors.toList()), + .map(b -> (WebDriverBrowser) b) + .map(WebDriverBrowser::getWrappedDriver) + .map(TargetedWebDriver::getWebDriverTarget) + .collect(Collectors.toList()), + containsInAnyOrder(WebDriverTargets.window("window1"), + WebDriverTargets.window("window2"))); + } + + @Test + public void shouldFindBrowsersByUrl() { + TargetedWebDriver fooWindow = mock(TargetedWebDriver.class); + TargetedWebDriver barWindow = mock(TargetedWebDriver.class); + + when(fooWindow.getCurrentUrl()).thenReturn("foo"); + when(barWindow.getCurrentUrl()).thenReturn("bar"); + + when(mockTargetedDriver.getWindowHandles()) + .thenReturn(new HashSet<>(Arrays.asList("fooWindow", "barWindow"))); + when(mockTargetedLocator.window("fooWindow")).thenReturn(fooWindow); + when(mockTargetedLocator.window("barWindow")).thenReturn(barWindow); + + Browser browser = context.findByUrl(Browser.class, equalTo("awesome window")); + + assertFalse(browser.isPresent()); + + when(fooWindow.getCurrentUrl()).thenReturn("awesome window"); + + assertTrue(browser.isPresent()); + } + + @Test + public void shouldFindAllBrowsersByUrl() { + TargetedWebDriver window1 = mock(TargetedWebDriver.class); + TargetedWebDriver window2 = mock(TargetedWebDriver.class); + + when(window1.getCurrentUrl()).thenReturn("shared title"); + when(window2.getCurrentUrl()).thenReturn("shared title"); + + when(mockTargetedDriver.getWindowHandles()) + .thenReturn(new HashSet<>(Arrays.asList("window1", "window2"))); + when(mockTargetedLocator.window("window1")).thenReturn(window1); + when(mockTargetedLocator.window("window2")).thenReturn(window2); + + List browsers = context.findAllByUrl(Browser.class, equalTo("shared title")); + + assertThat(browsers.stream() + .map(b -> (WebDriverBrowser) b) + .map(WebDriverBrowser::getWrappedDriver) + .map(TargetedWebDriver::getWebDriverTarget) + .collect(Collectors.toList()), containsInAnyOrder(WebDriverTargets.window("window1"), WebDriverTargets.window("window2"))); } diff --git a/src/test/java/com/redhat/darcy/webdriver/internal/WindowTitleWebDriverTargetTest.java b/src/test/java/com/redhat/darcy/webdriver/internal/WindowTitleWebDriverTargetTest.java index 40a5224..f6e3194 100644 --- a/src/test/java/com/redhat/darcy/webdriver/internal/WindowTitleWebDriverTargetTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/internal/WindowTitleWebDriverTargetTest.java @@ -37,7 +37,6 @@ @RunWith(JUnit4.class) public class WindowTitleWebDriverTargetTest { - private final WebDriver driver = mock(WebDriver.class); private final WebDriver fooWindow = mock(WebDriver.class); private final WebDriver barWindow = mock(WebDriver.class); diff --git a/src/test/java/com/redhat/darcy/webdriver/internal/WindowUrlWebDriverTargetTest.java b/src/test/java/com/redhat/darcy/webdriver/internal/WindowUrlWebDriverTargetTest.java new file mode 100644 index 0000000..be4cdc3 --- /dev/null +++ b/src/test/java/com/redhat/darcy/webdriver/internal/WindowUrlWebDriverTargetTest.java @@ -0,0 +1,84 @@ +/* + Copyright 2014 Red Hat, Inc. and/or its affiliates. + + This file is part of darcy-webdriver. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.redhat.darcy.webdriver.internal; + +import static java.util.Arrays.asList; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.openqa.selenium.NoSuchWindowException; +import org.openqa.selenium.WebDriver; + +import java.util.HashSet; + +@RunWith(JUnit4.class) +public class WindowUrlWebDriverTargetTest { + private final WebDriver driver = mock(WebDriver.class); + private final WebDriver fooWindow = mock(WebDriver.class); + private final WebDriver barWindow = mock(WebDriver.class); + private final WebDriver.TargetLocator locator = mock(WebDriver.TargetLocator.class); + + @Before + public void stubMocks() { + when(driver.getWindowHandles()).thenReturn(new HashSet<>(asList("fooWindow", "barWindow"))); + + when(fooWindow.getCurrentUrl()).thenReturn("foo"); + when(barWindow.getCurrentUrl()).thenReturn("bar"); + + when(locator.defaultContent()).thenReturn(driver); + when(locator.window("fooWindow")).thenReturn(fooWindow); + when(locator.window("barWindow")).thenReturn(barWindow); + } + + @Test + public void shouldTargetAWindowWhichMatchesTheUrlMatcher() { + WebDriverTarget target = WebDriverTargets.windowByUrl(equalTo("foo")); + WebDriver found = target.switchTo(locator); + + assertThat(found.getCurrentUrl(), is("foo")); + } + + @Test + public void shouldKeepFindingTheSameWindowEvenIfItsUrlLaterDoesNotMatch() { + WebDriverTarget target = WebDriverTargets.windowByUrl(equalTo("foo")); + + WebDriver found = target.switchTo(locator); + assertThat(found.getCurrentUrl(), is("foo")); + + when(fooWindow.getCurrentUrl()).thenReturn("no longer foo"); + + WebDriver foundAgain = target.switchTo(locator); + assertThat(foundAgain.getCurrentUrl(), is("no longer foo")); + } + + @Test(expected = NoSuchWindowException.class) + public void shouldThrowNoSuchWindowExceptionIfNoWindowsCanBeFoundMatchingTheUrlMatcher() { + WebDriverTarget target = WebDriverTargets.windowByUrl(equalTo("awesome window")); + + target.switchTo(locator); + } +} diff --git a/src/test/java/com/redhat/darcy/webdriver/testing/doubles/StubWebDriverParentContext.java b/src/test/java/com/redhat/darcy/webdriver/testing/doubles/StubWebDriverParentContext.java index d7d8d7d..4e9cb5c 100644 --- a/src/test/java/com/redhat/darcy/webdriver/testing/doubles/StubWebDriverParentContext.java +++ b/src/test/java/com/redhat/darcy/webdriver/testing/doubles/StubWebDriverParentContext.java @@ -23,6 +23,8 @@ import com.redhat.darcy.web.api.Alert; import com.redhat.darcy.webdriver.WebDriverParentContext; +import org.hamcrest.Matcher; + import java.util.List; public class StubWebDriverParentContext implements WebDriverParentContext { @@ -70,4 +72,14 @@ public List findAllByTitle(Class type, String title) { public T findByTitle(Class type, String title) { throw new UnsupportedOperationException("findByTitle"); } + + @Override + public List findAllByUrl(Class type, Matcher url) { + throw new UnsupportedOperationException("findAllByUrl"); + } + + @Override + public T findByUrl(Class type, Matcher url) { + throw new UnsupportedOperationException("findByUrl"); + } } From db4fbe5e6187ce45249550b1cfcbb8b3ed93d567 Mon Sep 17 00:00:00 2001 From: Alec Henninger Date: Sun, 12 Jul 2015 14:05:21 -0400 Subject: [PATCH 04/42] Correct odd formatting --- .../TargetedWebDriverParentContextTest.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContextTest.java b/src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContextTest.java index da21aeb..0fadce1 100644 --- a/src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContextTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContextTest.java @@ -171,10 +171,10 @@ public void shouldFindAllBrowsersByTitle() { List browsers = context.findAllByTitle(Browser.class, "shared title"); assertThat(browsers.stream() - .map(b -> (WebDriverBrowser) b) - .map(WebDriverBrowser::getWrappedDriver) - .map(TargetedWebDriver::getWebDriverTarget) - .collect(Collectors.toList()), + .map(b -> (WebDriverBrowser) b) + .map(WebDriverBrowser::getWrappedDriver) + .map(TargetedWebDriver::getWebDriverTarget) + .collect(Collectors.toList()), containsInAnyOrder(WebDriverTargets.window("window1"), WebDriverTargets.window("window2"))); } @@ -217,10 +217,10 @@ public void shouldFindAllBrowsersByUrl() { List browsers = context.findAllByUrl(Browser.class, equalTo("shared title")); assertThat(browsers.stream() - .map(b -> (WebDriverBrowser) b) - .map(WebDriverBrowser::getWrappedDriver) - .map(TargetedWebDriver::getWebDriverTarget) - .collect(Collectors.toList()), + .map(b -> (WebDriverBrowser) b) + .map(WebDriverBrowser::getWrappedDriver) + .map(TargetedWebDriver::getWebDriverTarget) + .collect(Collectors.toList()), containsInAnyOrder(WebDriverTargets.window("window1"), WebDriverTargets.window("window2"))); } From d30f49cc3e89d3553bf1fd779d6b20fc1cc54540 Mon Sep 17 00:00:00 2001 From: Andrew Bocz Date: Tue, 14 Jul 2015 14:11:28 -0400 Subject: [PATCH 05/42] Use selenium 2.46.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f95a488..b0ca5c8 100644 --- a/pom.xml +++ b/pom.xml @@ -69,7 +69,7 @@ org.seleniumhq.selenium selenium-server - 2.45.0 + 2.46.0 com.google.guiceberry From b46d7f43cf13164513f7524fac0462bde9c22ccf Mon Sep 17 00:00:00 2001 From: Andrew Bocz Date: Thu, 16 Jul 2015 11:22:18 -0400 Subject: [PATCH 06/42] Fix issues with selenium missing dependency for apache commons-exec artifact --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index b0ca5c8..e7916b4 100644 --- a/pom.xml +++ b/pom.xml @@ -71,6 +71,11 @@ selenium-server 2.46.0 + + org.apache.commons + commons-exec + 1.3 + com.google.guiceberry guiceberry From 16c3babe027e65def5b00f45332ba1c3b836a37a Mon Sep 17 00:00:00 2001 From: Andrew Bocz Date: Thu, 16 Jul 2015 16:26:08 -0400 Subject: [PATCH 07/42] Exclude out of date commons-exec dependency --- pom.xml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index e7916b4..e86e628 100644 --- a/pom.xml +++ b/pom.xml @@ -71,11 +71,6 @@ selenium-server 2.46.0 - - org.apache.commons - commons-exec - 1.3 - com.google.guiceberry guiceberry @@ -90,6 +85,12 @@ com.opera operadriver 1.5 + + + org.apache.commons + commons-exec + + org.mockito From d96b642ccd53cdd9486bead5bef4965b9a938e8b Mon Sep 17 00:00:00 2001 From: Andrew Bocz Date: Mon, 20 Jul 2015 10:46:52 -0400 Subject: [PATCH 08/42] Use After method to ensure browsers close in Browser factory tests, fixes #52 --- .../darcy/webdriver/ChromeBrowserFactoryTest.java | 11 +++++++++-- .../darcy/webdriver/FirefoxBrowserFactoryTest.java | 10 +++++++++- .../darcy/webdriver/HtmlUnitBrowserFactoryTest.java | 10 ++++++++-- .../InternetExplorerBrowserFactoryTest.java | 11 +++++++++-- .../darcy/webdriver/OperaBrowserFactoryTest.java | 12 ++++++++++-- .../darcy/webdriver/SafariBrowserFactoryTest.java | 11 +++++++++-- 6 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/redhat/darcy/webdriver/ChromeBrowserFactoryTest.java b/src/test/java/com/redhat/darcy/webdriver/ChromeBrowserFactoryTest.java index 0ebe6e4..410bbb2 100644 --- a/src/test/java/com/redhat/darcy/webdriver/ChromeBrowserFactoryTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/ChromeBrowserFactoryTest.java @@ -26,25 +26,32 @@ import com.redhat.darcy.webdriver.internal.CachingTargetLocator; import com.redhat.darcy.webdriver.internal.ForwardingTargetedWebDriver; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.chrome.ChromeDriver; public class ChromeBrowserFactoryTest { + private WebDriverBrowser browser; + @Before public void checkForDriver() { assumeNotNull(System.getProperty("webdriver.chrome.driver")); } + @After + public void closeBrowser() { + browser.close(); + } + @Test public void shouldBeInstanceOfUntargetedChromeDriver() { WebDriverBrowserFactory browserFactory = new ChromeBrowserFactory(); - WebDriverBrowser browser = (WebDriverBrowser) browserFactory.newBrowser(); + browser = (WebDriverBrowser) browserFactory.newBrowser(); ForwardingTargetedWebDriver webDriver = (ForwardingTargetedWebDriver) browser.getWrappedDriver(); CachingTargetLocator targetLocator = (CachingTargetLocator) webDriver.getTargetLocator(); assertThat(targetLocator.getUntargetedDriver(), instanceOf(ChromeDriver.class)); - browser.close(); } } diff --git a/src/test/java/com/redhat/darcy/webdriver/FirefoxBrowserFactoryTest.java b/src/test/java/com/redhat/darcy/webdriver/FirefoxBrowserFactoryTest.java index 1a33673..7d4c81e 100644 --- a/src/test/java/com/redhat/darcy/webdriver/FirefoxBrowserFactoryTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/FirefoxBrowserFactoryTest.java @@ -26,21 +26,29 @@ import com.redhat.darcy.webdriver.internal.CachingTargetLocator; import com.redhat.darcy.webdriver.internal.ForwardingTargetedWebDriver; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.firefox.FirefoxDriver; public class FirefoxBrowserFactoryTest { + WebDriverBrowser browser; + @Before public void checkForDriver() { assumeTrue(System.getProperty("java.class.path").contains("firefox-driver")); } + @After + public void closeBrowser() { + browser.close(); + } + @Test public void shouldBeInstanceOfUntargetedFirefoxDriver() { WebDriverBrowserFactory browserFactory = new FirefoxBrowserFactory(); - WebDriverBrowser browser = (WebDriverBrowser) browserFactory.newBrowser(); + browser = (WebDriverBrowser) browserFactory.newBrowser(); ForwardingTargetedWebDriver webDriver = (ForwardingTargetedWebDriver) browser.getWrappedDriver(); CachingTargetLocator targetLocator = (CachingTargetLocator) webDriver.getTargetLocator(); diff --git a/src/test/java/com/redhat/darcy/webdriver/HtmlUnitBrowserFactoryTest.java b/src/test/java/com/redhat/darcy/webdriver/HtmlUnitBrowserFactoryTest.java index 5a2b370..74f1c63 100644 --- a/src/test/java/com/redhat/darcy/webdriver/HtmlUnitBrowserFactoryTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/HtmlUnitBrowserFactoryTest.java @@ -25,19 +25,25 @@ import com.redhat.darcy.webdriver.internal.CachingTargetLocator; import com.redhat.darcy.webdriver.internal.ForwardingTargetedWebDriver; +import org.junit.After; import org.junit.Test; import org.openqa.selenium.htmlunit.HtmlUnitDriver; public class HtmlUnitBrowserFactoryTest { + private WebDriverBrowser browser; + + @After + public void closeDriver() { + browser.close(); + } @Test public void shouldBeInstanceOfUntargetedHtmlUnitDriver() { WebDriverBrowserFactory browserFactory = new HtmlUnitBrowserFactory(); - WebDriverBrowser browser = (WebDriverBrowser) browserFactory.newBrowser(); + browser = (WebDriverBrowser) browserFactory.newBrowser(); ForwardingTargetedWebDriver webDriver = (ForwardingTargetedWebDriver) browser.getWrappedDriver(); CachingTargetLocator targetLocator = (CachingTargetLocator) webDriver.getTargetLocator(); assertThat(targetLocator.getUntargetedDriver(), instanceOf(HtmlUnitDriver.class)); - browser.close(); } } diff --git a/src/test/java/com/redhat/darcy/webdriver/InternetExplorerBrowserFactoryTest.java b/src/test/java/com/redhat/darcy/webdriver/InternetExplorerBrowserFactoryTest.java index 0b01919..b35aa44 100644 --- a/src/test/java/com/redhat/darcy/webdriver/InternetExplorerBrowserFactoryTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/InternetExplorerBrowserFactoryTest.java @@ -26,25 +26,32 @@ import com.redhat.darcy.webdriver.internal.CachingTargetLocator; import com.redhat.darcy.webdriver.internal.ForwardingTargetedWebDriver; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.ie.InternetExplorerDriver; public class InternetExplorerBrowserFactoryTest { + private WebDriverBrowser browser; + @Before public void checkForDriver() { assumeNotNull(System.getProperty("webdriver.ie.driver")); } + @After + public void closeBrowser() { + browser.close(); + } + @Test public void shouldBeInstanceOfUntargetedInternetExplorerDriver() { WebDriverBrowserFactory browserFactory = new InternetExplorerBrowserFactory(); - WebDriverBrowser browser = (WebDriverBrowser) browserFactory.newBrowser(); + browser = (WebDriverBrowser) browserFactory.newBrowser(); ForwardingTargetedWebDriver webDriver = (ForwardingTargetedWebDriver) browser.getWrappedDriver(); CachingTargetLocator targetLocator = (CachingTargetLocator) webDriver.getTargetLocator(); assertThat(targetLocator.getUntargetedDriver(), instanceOf(InternetExplorerDriver.class)); - browser.close(); } } diff --git a/src/test/java/com/redhat/darcy/webdriver/OperaBrowserFactoryTest.java b/src/test/java/com/redhat/darcy/webdriver/OperaBrowserFactoryTest.java index a4d7e20..8a281b1 100644 --- a/src/test/java/com/redhat/darcy/webdriver/OperaBrowserFactoryTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/OperaBrowserFactoryTest.java @@ -28,24 +28,32 @@ import com.redhat.darcy.webdriver.internal.ForwardingTargetedWebDriver; import com.opera.core.systems.OperaDriver; +import org.junit.After; import org.junit.Before; import org.junit.Test; public class OperaBrowserFactoryTest { + private WebDriverBrowser browser; + @Before public void checkForDriver() { assumeTrue(System.getProperty("java.class.path").contains("operadriver")); assumeNotNull(System.getProperty("webdriver.opera.driver")); } + + @After + public void closeDriver() { + browser.close(); + } + @Test public void shouldBeInstanceOfUntargetedOperaDriver() { WebDriverBrowserFactory browserFactory = new OperaBrowserFactory(); - WebDriverBrowser browser = (WebDriverBrowser) browserFactory.newBrowser(); + browser = (WebDriverBrowser) browserFactory.newBrowser(); ForwardingTargetedWebDriver webDriver = (ForwardingTargetedWebDriver) browser.getWrappedDriver(); CachingTargetLocator targetLocator = (CachingTargetLocator) webDriver.getTargetLocator(); assertThat(targetLocator.getUntargetedDriver(), instanceOf(OperaDriver.class)); - browser.close(); } } diff --git a/src/test/java/com/redhat/darcy/webdriver/SafariBrowserFactoryTest.java b/src/test/java/com/redhat/darcy/webdriver/SafariBrowserFactoryTest.java index d1155e4..b95a7ac 100644 --- a/src/test/java/com/redhat/darcy/webdriver/SafariBrowserFactoryTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/SafariBrowserFactoryTest.java @@ -26,25 +26,32 @@ import com.redhat.darcy.webdriver.internal.CachingTargetLocator; import com.redhat.darcy.webdriver.internal.ForwardingTargetedWebDriver; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.safari.SafariDriver; public class SafariBrowserFactoryTest { + private WebDriverBrowser browser; + @Before public void checkForDriver() { assumeNotNull(System.getProperty("webdriver.safari.driver")); } + @After + public void closeDriver() { + browser.close(); + } + @Test public void shouldBeInstanceOfUntargetedSafariDriver() { WebDriverBrowserFactory browserFactory = new SafariBrowserFactory(); - WebDriverBrowser browser = (WebDriverBrowser) browserFactory.newBrowser(); + browser = (WebDriverBrowser) browserFactory.newBrowser(); ForwardingTargetedWebDriver webDriver = (ForwardingTargetedWebDriver) browser.getWrappedDriver(); CachingTargetLocator targetLocator = (CachingTargetLocator) webDriver.getTargetLocator(); assertThat(targetLocator.getUntargetedDriver(), instanceOf(SafariDriver.class)); - browser.close(); } } From 8603a98856ef0cee7b4f6c6589e4307ea4360e51 Mon Sep 17 00:00:00 2001 From: Andrew Bocz Date: Mon, 20 Jul 2015 14:08:19 -0400 Subject: [PATCH 09/42] Only close browser if the test is not skipped --- .../com/redhat/darcy/webdriver/ChromeBrowserFactoryTest.java | 4 +++- .../com/redhat/darcy/webdriver/FirefoxBrowserFactoryTest.java | 4 +++- .../redhat/darcy/webdriver/HtmlUnitBrowserFactoryTest.java | 4 +++- .../darcy/webdriver/InternetExplorerBrowserFactoryTest.java | 4 +++- .../com/redhat/darcy/webdriver/OperaBrowserFactoryTest.java | 4 +++- .../com/redhat/darcy/webdriver/SafariBrowserFactoryTest.java | 4 +++- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/redhat/darcy/webdriver/ChromeBrowserFactoryTest.java b/src/test/java/com/redhat/darcy/webdriver/ChromeBrowserFactoryTest.java index 410bbb2..679e816 100644 --- a/src/test/java/com/redhat/darcy/webdriver/ChromeBrowserFactoryTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/ChromeBrowserFactoryTest.java @@ -41,7 +41,9 @@ public void checkForDriver() { @After public void closeBrowser() { - browser.close(); + if (browser != null) { + browser.close(); + } } @Test diff --git a/src/test/java/com/redhat/darcy/webdriver/FirefoxBrowserFactoryTest.java b/src/test/java/com/redhat/darcy/webdriver/FirefoxBrowserFactoryTest.java index 7d4c81e..7e780e5 100644 --- a/src/test/java/com/redhat/darcy/webdriver/FirefoxBrowserFactoryTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/FirefoxBrowserFactoryTest.java @@ -41,7 +41,9 @@ public void checkForDriver() { @After public void closeBrowser() { - browser.close(); + if (browser != null) { + browser.close(); + } } @Test diff --git a/src/test/java/com/redhat/darcy/webdriver/HtmlUnitBrowserFactoryTest.java b/src/test/java/com/redhat/darcy/webdriver/HtmlUnitBrowserFactoryTest.java index 74f1c63..0d7edf2 100644 --- a/src/test/java/com/redhat/darcy/webdriver/HtmlUnitBrowserFactoryTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/HtmlUnitBrowserFactoryTest.java @@ -34,7 +34,9 @@ public class HtmlUnitBrowserFactoryTest { @After public void closeDriver() { - browser.close(); + if (browser != null) { + browser.close(); + } } @Test public void shouldBeInstanceOfUntargetedHtmlUnitDriver() { diff --git a/src/test/java/com/redhat/darcy/webdriver/InternetExplorerBrowserFactoryTest.java b/src/test/java/com/redhat/darcy/webdriver/InternetExplorerBrowserFactoryTest.java index b35aa44..d8f76a3 100644 --- a/src/test/java/com/redhat/darcy/webdriver/InternetExplorerBrowserFactoryTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/InternetExplorerBrowserFactoryTest.java @@ -41,7 +41,9 @@ public void checkForDriver() { @After public void closeBrowser() { - browser.close(); + if (browser != null) { + browser.close(); + } } @Test diff --git a/src/test/java/com/redhat/darcy/webdriver/OperaBrowserFactoryTest.java b/src/test/java/com/redhat/darcy/webdriver/OperaBrowserFactoryTest.java index 8a281b1..5422d9e 100644 --- a/src/test/java/com/redhat/darcy/webdriver/OperaBrowserFactoryTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/OperaBrowserFactoryTest.java @@ -43,7 +43,9 @@ public void checkForDriver() { @After public void closeDriver() { - browser.close(); + if (browser != null) { + browser.close(); + } } @Test diff --git a/src/test/java/com/redhat/darcy/webdriver/SafariBrowserFactoryTest.java b/src/test/java/com/redhat/darcy/webdriver/SafariBrowserFactoryTest.java index b95a7ac..e788a0c 100644 --- a/src/test/java/com/redhat/darcy/webdriver/SafariBrowserFactoryTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/SafariBrowserFactoryTest.java @@ -41,7 +41,9 @@ public void checkForDriver() { @After public void closeDriver() { - browser.close(); + if (browser != null) { + browser.close(); + } } @Test From e8cb5331b438d9b81e9d70f39bfba4e78aac58db Mon Sep 17 00:00:00 2001 From: Derek McNeil Date: Tue, 25 Aug 2015 15:20:15 -0400 Subject: [PATCH 10/42] Screenshot API implementations --- .../darcy/webdriver/ScreenshotOutputType.java | 68 +++++++++++++++++++ .../darcy/webdriver/WebDriverBrowser.java | 6 ++ .../internal/ForwardingTargetedWebDriver.java | 2 +- .../webdriver/internal/TargetedWebDriver.java | 3 +- .../darcy/webdriver/GetScreenshotTest.java | 49 +++++++++++++ 5 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/redhat/darcy/webdriver/ScreenshotOutputType.java create mode 100644 src/test/java/com/redhat/darcy/webdriver/GetScreenshotTest.java diff --git a/src/main/java/com/redhat/darcy/webdriver/ScreenshotOutputType.java b/src/main/java/com/redhat/darcy/webdriver/ScreenshotOutputType.java new file mode 100644 index 0000000..0716f0c --- /dev/null +++ b/src/main/java/com/redhat/darcy/webdriver/ScreenshotOutputType.java @@ -0,0 +1,68 @@ +/* + Modified by Red Hat + + Copyright 2007-2009 Selenium committers + + 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.redhat.darcy.webdriver; + +import com.redhat.darcy.web.api.OutputType; + +import java.io.File; + +public interface ScreenshotOutputType extends OutputType, org.openqa.selenium.OutputType { + ScreenshotOutputType BASE64 = new ScreenshotOutputType() { + @Override + public String convertFromBase64Png(String base64Png) { + return org.openqa.selenium.OutputType.BASE64.convertFromBase64Png(base64Png); + } + + @Override + public String convertFromPngBytes(byte[] png) { + return org.openqa.selenium.OutputType.BASE64.convertFromPngBytes(png); + } + }; + + /** + * Obtain the screenshot as raw bytes. + */ + ScreenshotOutputType BYTES = new ScreenshotOutputType() { + @Override + public byte[] convertFromBase64Png(String base64Png) { + return org.openqa.selenium.OutputType.BYTES.convertFromBase64Png(base64Png); + } + + @Override + public byte[] convertFromPngBytes(byte[] png) { + return org.openqa.selenium.OutputType.BYTES.convertFromPngBytes(png); + } + }; + + /** + * Obtain the screenshot into a temporary file that will be deleted once the JVM exits. It is up + * to users to make a copy of this file. + */ + ScreenshotOutputType FILE = new ScreenshotOutputType() { + @Override + public File convertFromBase64Png(String base64Png) { + return org.openqa.selenium.OutputType.FILE.convertFromBase64Png(base64Png); + } + + @Override + public File convertFromPngBytes(byte[] png) { + return org.openqa.selenium.OutputType.FILE.convertFromPngBytes(png); + } + }; +} diff --git a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java index e5c045c..23dbb27 100644 --- a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java +++ b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java @@ -31,6 +31,7 @@ import com.redhat.darcy.web.api.Browser; import com.redhat.darcy.web.api.CookieManager; import com.redhat.darcy.web.api.Frame; +import com.redhat.darcy.web.api.OutputType; import com.redhat.darcy.web.api.ViewUrl; import com.redhat.darcy.web.api.WebSelection; import com.redhat.darcy.webdriver.internal.DelegatingWebContext; @@ -173,6 +174,11 @@ public void closeAll() { driver.quit(); } + @Override + public T takeScreenshot(OutputType target) { + return driver.getScreenshotAs((ScreenshotOutputType) target); + } + @Override public WebSelection find() { return new WebDriverWebSelection(this); diff --git a/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedWebDriver.java b/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedWebDriver.java index 8c345eb..43d233b 100644 --- a/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedWebDriver.java +++ b/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedWebDriver.java @@ -44,7 +44,7 @@ public class ForwardingTargetedWebDriver implements TargetedWebDriver, FindsByClassName, FindsByCssSelector, FindsById, FindsByLinkText, FindsByName, FindsByTagName, FindsByXPath, - TakesScreenshot, JavascriptExecutor, WrapsDriver { + JavascriptExecutor, WrapsDriver { private final TargetLocator locator; private final WebDriverTarget target; diff --git a/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebDriver.java b/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebDriver.java index 942b7b1..978108a 100644 --- a/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebDriver.java +++ b/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebDriver.java @@ -21,6 +21,7 @@ import com.redhat.darcy.ui.api.elements.Findable; +import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; /** @@ -33,7 +34,7 @@ * Elements found by this driver should also be targeted. That is, elements are associated with a * driver and target and will ensure the driver is switched before interacting with the element. */ -public interface TargetedWebDriver extends WebDriver, Findable { +public interface TargetedWebDriver extends WebDriver, Findable, TakesScreenshot { WebDriverTarget getWebDriverTarget(); /** diff --git a/src/test/java/com/redhat/darcy/webdriver/GetScreenshotTest.java b/src/test/java/com/redhat/darcy/webdriver/GetScreenshotTest.java new file mode 100644 index 0000000..f10ceea --- /dev/null +++ b/src/test/java/com/redhat/darcy/webdriver/GetScreenshotTest.java @@ -0,0 +1,49 @@ +package com.redhat.darcy.webdriver; + +import static org.mockito.Mockito.verify; + +import com.redhat.darcy.web.api.Browser; +import com.redhat.darcy.webdriver.internal.TargetedWebDriver; +import com.redhat.darcy.webdriver.testing.doubles.StubWebDriverElementContext; +import com.redhat.darcy.webdriver.testing.doubles.StubWebDriverParentContext; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class GetScreenshotTest { + @Mock + TargetedWebDriver mockedDriver; + + Browser browser; + + @Before + public void setupBrowser() { + if (browser == null) { + browser = new WebDriverBrowser(mockedDriver, + new StubWebDriverParentContext(), + new StubWebDriverElementContext()); + } + } + + @Test + public void shouldGetScreenAsFile() { + browser.takeScreenshot(ScreenshotOutputType.FILE); + verify(mockedDriver).getScreenshotAs(ScreenshotOutputType.FILE); + } + + @Test + public void shouldGetScreenAsBase64() { + browser.takeScreenshot(ScreenshotOutputType.BASE64); + verify(mockedDriver).getScreenshotAs(ScreenshotOutputType.BASE64); + } + + @Test + public void shouldGetScreenAsBinary() { + browser.takeScreenshot(ScreenshotOutputType.BYTES); + verify(mockedDriver).getScreenshotAs(ScreenshotOutputType.BYTES); + } +} From 000d9387ddf1fc3ab272d0180dcda8f925a79b12 Mon Sep 17 00:00:00 2001 From: Derek McNeil Date: Fri, 28 Aug 2015 10:08:15 -0400 Subject: [PATCH 11/42] Adjust implementations, rename GetScreenshotTest to TakeScreenshotTest for a closer fit to the method it is testing --- .../darcy/webdriver/ScreenshotOutputType.java | 68 ------------------- .../darcy/webdriver/WebDriverBrowser.java | 7 +- ...nshotTest.java => TakeScreenshotTest.java} | 21 ++---- 3 files changed, 9 insertions(+), 87 deletions(-) delete mode 100644 src/main/java/com/redhat/darcy/webdriver/ScreenshotOutputType.java rename src/test/java/com/redhat/darcy/webdriver/{GetScreenshotTest.java => TakeScreenshotTest.java} (59%) diff --git a/src/main/java/com/redhat/darcy/webdriver/ScreenshotOutputType.java b/src/main/java/com/redhat/darcy/webdriver/ScreenshotOutputType.java deleted file mode 100644 index 0716f0c..0000000 --- a/src/main/java/com/redhat/darcy/webdriver/ScreenshotOutputType.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - Modified by Red Hat - - Copyright 2007-2009 Selenium committers - - 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.redhat.darcy.webdriver; - -import com.redhat.darcy.web.api.OutputType; - -import java.io.File; - -public interface ScreenshotOutputType extends OutputType, org.openqa.selenium.OutputType { - ScreenshotOutputType BASE64 = new ScreenshotOutputType() { - @Override - public String convertFromBase64Png(String base64Png) { - return org.openqa.selenium.OutputType.BASE64.convertFromBase64Png(base64Png); - } - - @Override - public String convertFromPngBytes(byte[] png) { - return org.openqa.selenium.OutputType.BASE64.convertFromPngBytes(png); - } - }; - - /** - * Obtain the screenshot as raw bytes. - */ - ScreenshotOutputType BYTES = new ScreenshotOutputType() { - @Override - public byte[] convertFromBase64Png(String base64Png) { - return org.openqa.selenium.OutputType.BYTES.convertFromBase64Png(base64Png); - } - - @Override - public byte[] convertFromPngBytes(byte[] png) { - return org.openqa.selenium.OutputType.BYTES.convertFromPngBytes(png); - } - }; - - /** - * Obtain the screenshot into a temporary file that will be deleted once the JVM exits. It is up - * to users to make a copy of this file. - */ - ScreenshotOutputType FILE = new ScreenshotOutputType() { - @Override - public File convertFromBase64Png(String base64Png) { - return org.openqa.selenium.OutputType.FILE.convertFromBase64Png(base64Png); - } - - @Override - public File convertFromPngBytes(byte[] png) { - return org.openqa.selenium.OutputType.FILE.convertFromPngBytes(png); - } - }; -} diff --git a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java index 23dbb27..cb266f2 100644 --- a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java +++ b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java @@ -31,7 +31,6 @@ import com.redhat.darcy.web.api.Browser; import com.redhat.darcy.web.api.CookieManager; import com.redhat.darcy.web.api.Frame; -import com.redhat.darcy.web.api.OutputType; import com.redhat.darcy.web.api.ViewUrl; import com.redhat.darcy.web.api.WebSelection; import com.redhat.darcy.webdriver.internal.DelegatingWebContext; @@ -45,8 +44,10 @@ import org.hamcrest.Matcher; import org.openqa.selenium.NoSuchFrameException; import org.openqa.selenium.NoSuchWindowException; +import org.openqa.selenium.OutputType; import org.openqa.selenium.remote.SessionNotFoundException; +import java.io.File; import java.util.List; import java.util.Objects; import java.util.function.Supplier; @@ -175,8 +176,8 @@ public void closeAll() { } @Override - public T takeScreenshot(OutputType target) { - return driver.getScreenshotAs((ScreenshotOutputType) target); + public File takeScreenshot() { + return driver.getScreenshotAs(OutputType.FILE); } @Override diff --git a/src/test/java/com/redhat/darcy/webdriver/GetScreenshotTest.java b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java similarity index 59% rename from src/test/java/com/redhat/darcy/webdriver/GetScreenshotTest.java rename to src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java index f10ceea..29de403 100644 --- a/src/test/java/com/redhat/darcy/webdriver/GetScreenshotTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java @@ -12,9 +12,10 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import org.openqa.selenium.OutputType; @RunWith(MockitoJUnitRunner.class) -public class GetScreenshotTest { +public class TakeScreenshotTest { @Mock TargetedWebDriver mockedDriver; @@ -30,20 +31,8 @@ public void setupBrowser() { } @Test - public void shouldGetScreenAsFile() { - browser.takeScreenshot(ScreenshotOutputType.FILE); - verify(mockedDriver).getScreenshotAs(ScreenshotOutputType.FILE); - } - - @Test - public void shouldGetScreenAsBase64() { - browser.takeScreenshot(ScreenshotOutputType.BASE64); - verify(mockedDriver).getScreenshotAs(ScreenshotOutputType.BASE64); - } - - @Test - public void shouldGetScreenAsBinary() { - browser.takeScreenshot(ScreenshotOutputType.BYTES); - verify(mockedDriver).getScreenshotAs(ScreenshotOutputType.BYTES); + public void shouldTakeScreenshot() { + browser.takeScreenshot(); + verify(mockedDriver).getScreenshotAs(OutputType.FILE); } } From 40d8ade471c7d823fe7ceb39a03d7afa51526cc3 Mon Sep 17 00:00:00 2001 From: Andrew Bocz Date: Mon, 12 Oct 2015 14:34:15 -0400 Subject: [PATCH 12/42] Use selenium 2.48.2 --- pom.xml | 4 ++-- .../java/com/redhat/darcy/webdriver/WebDriverBrowser.java | 6 ++++++ .../darcy/webdriver/internal/ForwardingTargetedAlert.java | 5 +++++ .../darcy/webdriver/internal/TargetedWebElement.java | 7 +++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e86e628..c2864ea 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ com.redhat.darcy darcy-webdriver - 0.2.2-SNAPSHOT + 0.2.3-SNAPSHOT jar ${project.groupId}:${project.artifactId} @@ -69,7 +69,7 @@ org.seleniumhq.selenium selenium-server - 2.46.0 + 2.48.2 com.google.guiceberry diff --git a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java index e5c045c..1f6e0b2 100644 --- a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java +++ b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java @@ -46,6 +46,7 @@ import org.openqa.selenium.NoSuchWindowException; import org.openqa.selenium.remote.SessionNotFoundException; +import java.io.File; import java.util.List; import java.util.Objects; import java.util.function.Supplier; @@ -173,6 +174,11 @@ public void closeAll() { driver.quit(); } + @Override + public File takeScreenshot() { + return null; + } + @Override public WebSelection find() { return new WebDriverWebSelection(this); diff --git a/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedAlert.java b/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedAlert.java index d56ad57..8f1deed 100644 --- a/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedAlert.java +++ b/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedAlert.java @@ -61,6 +61,11 @@ public void sendKeys(String keysToSend) { alert().sendKeys(keysToSend); } + @Override + public void setCredentials(Credentials credentials) { + alert().setCredentials(credentials); + } + @Override public void authenticateUsing(Credentials credentials) { alert().authenticateUsing(credentials); diff --git a/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebElement.java b/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebElement.java index 341a08b..ebfd5e6 100644 --- a/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebElement.java +++ b/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebElement.java @@ -23,7 +23,9 @@ import org.openqa.selenium.By; import org.openqa.selenium.Dimension; +import org.openqa.selenium.OutputType; import org.openqa.selenium.Point; +import org.openqa.selenium.WebDriverException; import org.openqa.selenium.WebElement; import org.openqa.selenium.internal.FindsByClassName; import org.openqa.selenium.internal.FindsByCssSelector; @@ -228,4 +230,9 @@ private List targetedWebElements(List elements) { .map(e -> new TargetedWebElement(locator, target, e)) .collect(Collectors.toList()); } + + @Override + public X getScreenshotAs(OutputType outputType) throws WebDriverException { + return null; + } } From b1c8d373bbba60be0c0018f5433c76774028e97f Mon Sep 17 00:00:00 2001 From: Derek McNeil Date: Thu, 15 Oct 2015 11:16:03 -0400 Subject: [PATCH 13/42] Wrap in attemptAndGet/unit test in case underlying driver isn't present --- .../com/redhat/darcy/webdriver/WebDriverBrowser.java | 2 +- .../redhat/darcy/webdriver/TakeScreenshotTest.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java index cb266f2..1bdfb3e 100644 --- a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java +++ b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java @@ -177,7 +177,7 @@ public void closeAll() { @Override public File takeScreenshot() { - return driver.getScreenshotAs(OutputType.FILE); + return attemptAndGet(() -> driver.getScreenshotAs(OutputType.FILE)); } @Override diff --git a/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java index 29de403..a22fd62 100644 --- a/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java @@ -1,7 +1,9 @@ package com.redhat.darcy.webdriver; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import com.redhat.darcy.ui.FindableNotPresentException; import com.redhat.darcy.web.api.Browser; import com.redhat.darcy.webdriver.internal.TargetedWebDriver; import com.redhat.darcy.webdriver.testing.doubles.StubWebDriverElementContext; @@ -12,6 +14,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import org.openqa.selenium.NoSuchWindowException; import org.openqa.selenium.OutputType; @RunWith(MockitoJUnitRunner.class) @@ -35,4 +38,12 @@ public void shouldTakeScreenshot() { browser.takeScreenshot(); verify(mockedDriver).getScreenshotAs(OutputType.FILE); } + + @SuppressWarnings("unchecked") + @Test(expected = FindableNotPresentException.class) + public void shouldThrowFindableNotPresentExceptionIfDriverIsNotPresent() { + when(mockedDriver.getScreenshotAs(OutputType.FILE)) + .thenThrow(NoSuchWindowException.class); + browser.takeScreenshot(); + } } From 83a5cc0c2d103fa545f6c9fb467fa7e73830d165 Mon Sep 17 00:00:00 2001 From: Derek McNeil Date: Fri, 23 Oct 2015 22:28:55 -0400 Subject: [PATCH 14/42] Update implementations for screenshot API OutputStream updates --- .../darcy/webdriver/WebDriverBrowser.java | 14 ++++- .../darcy/webdriver/TakeScreenshotTest.java | 55 +++++++++++-------- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java index 1bdfb3e..abb34a9 100644 --- a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java +++ b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java @@ -47,7 +47,8 @@ import org.openqa.selenium.OutputType; import org.openqa.selenium.remote.SessionNotFoundException; -import java.io.File; +import java.io.IOException; +import java.io.OutputStream; import java.util.List; import java.util.Objects; import java.util.function.Supplier; @@ -176,8 +177,15 @@ public void closeAll() { } @Override - public File takeScreenshot() { - return attemptAndGet(() -> driver.getScreenshotAs(OutputType.FILE)); + public void takeScreenshot(OutputStream outputStream) { + byte[] data = attemptAndGet(() -> driver.getScreenshotAs(OutputType.BYTES)); + try { + outputStream.write(data); + outputStream.flush(); + outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } } @Override diff --git a/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java index a22fd62..de4b037 100644 --- a/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java @@ -1,5 +1,6 @@ package com.redhat.darcy.webdriver; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -9,41 +10,49 @@ import com.redhat.darcy.webdriver.testing.doubles.StubWebDriverElementContext; import com.redhat.darcy.webdriver.testing.doubles.StubWebDriverParentContext; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.junit.runners.JUnit4; import org.openqa.selenium.NoSuchWindowException; import org.openqa.selenium.OutputType; -@RunWith(MockitoJUnitRunner.class) -public class TakeScreenshotTest { - @Mock - TargetedWebDriver mockedDriver; - - Browser browser; - - @Before - public void setupBrowser() { - if (browser == null) { - browser = new WebDriverBrowser(mockedDriver, - new StubWebDriverParentContext(), - new StubWebDriverElementContext()); - } - } +import java.io.IOException; +import java.io.OutputStream; +@RunWith(JUnit4.class) +public class TakeScreenshotTest { @Test - public void shouldTakeScreenshot() { - browser.takeScreenshot(); - verify(mockedDriver).getScreenshotAs(OutputType.FILE); + public void shouldTakeScreenshotAndWriteToOutputStream() throws IOException { + TargetedWebDriver mockedDriver = mock(TargetedWebDriver.class); + OutputStream mockedOutputStream = mock(OutputStream.class); + Browser browser = new WebDriverBrowser(mockedDriver, + new StubWebDriverParentContext(), + new StubWebDriverElementContext()); + + byte[] data = new byte[] { 1, 2, 3 }; + + when(mockedDriver.getScreenshotAs(OutputType.BYTES)) + .thenReturn(data); + + browser.takeScreenshot(mockedOutputStream); + + verify(mockedDriver).getScreenshotAs(OutputType.BYTES); + verify(mockedOutputStream).write(data); + verify(mockedOutputStream).flush(); + verify(mockedOutputStream).close(); } @SuppressWarnings("unchecked") @Test(expected = FindableNotPresentException.class) public void shouldThrowFindableNotPresentExceptionIfDriverIsNotPresent() { - when(mockedDriver.getScreenshotAs(OutputType.FILE)) + TargetedWebDriver mockedDriver = mock(TargetedWebDriver.class); + OutputStream mockedOutputStream = mock(OutputStream.class); + Browser browser = new WebDriverBrowser(mockedDriver, + new StubWebDriverParentContext(), + new StubWebDriverElementContext()); + + when(mockedDriver.getScreenshotAs(OutputType.BYTES)) .thenThrow(NoSuchWindowException.class); - browser.takeScreenshot(); + browser.takeScreenshot(mockedOutputStream); } } From 2aebaf27c71257808534624c47b87080918fd5e6 Mon Sep 17 00:00:00 2001 From: Derek McNeil Date: Sun, 25 Oct 2015 11:21:17 -0400 Subject: [PATCH 15/42] Update TakeScreenshotTest for takeScreenshot API changes --- .../redhat/darcy/webdriver/TakeScreenshotTest.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java index de4b037..41139e5 100644 --- a/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java @@ -1,5 +1,7 @@ package com.redhat.darcy.webdriver; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -16,6 +18,7 @@ import org.openqa.selenium.NoSuchWindowException; import org.openqa.selenium.OutputType; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -24,7 +27,7 @@ public class TakeScreenshotTest { @Test public void shouldTakeScreenshotAndWriteToOutputStream() throws IOException { TargetedWebDriver mockedDriver = mock(TargetedWebDriver.class); - OutputStream mockedOutputStream = mock(OutputStream.class); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); Browser browser = new WebDriverBrowser(mockedDriver, new StubWebDriverParentContext(), new StubWebDriverElementContext()); @@ -34,12 +37,10 @@ public void shouldTakeScreenshotAndWriteToOutputStream() throws IOException { when(mockedDriver.getScreenshotAs(OutputType.BYTES)) .thenReturn(data); - browser.takeScreenshot(mockedOutputStream); + browser.takeScreenshot(baos); verify(mockedDriver).getScreenshotAs(OutputType.BYTES); - verify(mockedOutputStream).write(data); - verify(mockedOutputStream).flush(); - verify(mockedOutputStream).close(); + assertThat(baos.toByteArray(), equalTo(data)); } @SuppressWarnings("unchecked") From e3ea764e742c10fe0213e94dd209aa28d08da5f1 Mon Sep 17 00:00:00 2001 From: Derek McNeil Date: Sun, 25 Oct 2015 13:09:18 -0400 Subject: [PATCH 16/42] Throw DarcyException on IOException, update tests --- .../redhat/darcy/webdriver/WebDriverBrowser.java | 3 ++- .../darcy/webdriver/TakeScreenshotTest.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java index abb34a9..8aee280 100644 --- a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java +++ b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java @@ -21,6 +21,7 @@ import static com.redhat.synq.Synq.after; +import com.redhat.darcy.ui.DarcyException; import com.redhat.darcy.ui.FindableNotPresentException; import com.redhat.darcy.ui.api.Locator; import com.redhat.darcy.ui.api.Transition; @@ -184,7 +185,7 @@ public void takeScreenshot(OutputStream outputStream) { outputStream.flush(); outputStream.close(); } catch (IOException e) { - e.printStackTrace(); + throw new DarcyException("Could not take screenshot", e); } } diff --git a/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java index 41139e5..4866dfb 100644 --- a/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java @@ -2,10 +2,12 @@ import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import com.redhat.darcy.ui.DarcyException; import com.redhat.darcy.ui.FindableNotPresentException; import com.redhat.darcy.web.api.Browser; import com.redhat.darcy.webdriver.internal.TargetedWebDriver; @@ -56,4 +58,17 @@ public void shouldThrowFindableNotPresentExceptionIfDriverIsNotPresent() { .thenThrow(NoSuchWindowException.class); browser.takeScreenshot(mockedOutputStream); } + + @Test(expected = DarcyException.class) + public void shouldThrowDarcyExceptionWhenAnIOExceptionOccurs() throws IOException { + TargetedWebDriver mockedDriver = mock(TargetedWebDriver.class); + Browser browser = new WebDriverBrowser(mockedDriver, + new StubWebDriverParentContext(), + new StubWebDriverElementContext()); + + OutputStream outputStream = mock(OutputStream.class); + doThrow(new IOException()).when(outputStream).close(); + + browser.takeScreenshot(outputStream); + } } From 113c3e77793405c83a55af71060cdf008995592b Mon Sep 17 00:00:00 2001 From: Derek McNeil Date: Thu, 29 Oct 2015 08:50:33 -0400 Subject: [PATCH 17/42] Bump versioning, darcy-web dependency, add OutputStream inOrder test --- pom.xml | 4 +-- .../darcy/webdriver/TakeScreenshotTest.java | 25 +++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index f95a488..86e0564 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ com.redhat.darcy darcy-webdriver - 0.2.2-SNAPSHOT + 0.3.0-SNAPSHOT jar ${project.groupId}:${project.artifactId} @@ -59,7 +59,7 @@ com.redhat.darcy darcy-web - 0.2.3-SNAPSHOT + 0.3.0-SNAPSHOT com.redhat.synq diff --git a/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java index 4866dfb..b844542 100644 --- a/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java @@ -3,8 +3,8 @@ import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.redhat.darcy.ui.DarcyException; @@ -17,6 +17,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import org.mockito.InOrder; import org.openqa.selenium.NoSuchWindowException; import org.openqa.selenium.OutputType; @@ -41,10 +42,30 @@ public void shouldTakeScreenshotAndWriteToOutputStream() throws IOException { browser.takeScreenshot(baos); - verify(mockedDriver).getScreenshotAs(OutputType.BYTES); assertThat(baos.toByteArray(), equalTo(data)); } + @Test + public void shouldTakeScreenshotAndWriteToOutputStreamThenFlushAndCloseInOrder() throws IOException { + TargetedWebDriver mockedDriver = mock(TargetedWebDriver.class); + OutputStream outputStream = mock(OutputStream.class); + Browser browser = new WebDriverBrowser(mockedDriver, + new StubWebDriverParentContext(), + new StubWebDriverElementContext()); + + byte[] data = new byte[] { 1, 2, 3 }; + + when(mockedDriver.getScreenshotAs(OutputType.BYTES)) + .thenReturn(data); + InOrder inOrder = inOrder(outputStream); + + browser.takeScreenshot(outputStream); + + inOrder.verify(outputStream).write(data); + inOrder.verify(outputStream).flush(); + inOrder.verify(outputStream).close(); + } + @SuppressWarnings("unchecked") @Test(expected = FindableNotPresentException.class) public void shouldThrowFindableNotPresentExceptionIfDriverIsNotPresent() { From e383807ce679d1d0d311150d0cb8fb2d1482073b Mon Sep 17 00:00:00 2001 From: Derek McNeil Date: Fri, 30 Oct 2015 01:00:58 -0400 Subject: [PATCH 18/42] Use try-with-resources block, update tests --- .../darcy/webdriver/WebDriverBrowser.java | 9 +++--- .../darcy/webdriver/TakeScreenshotTest.java | 28 ++++++++++--------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java index 8aee280..60833a4 100644 --- a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java +++ b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java @@ -177,13 +177,14 @@ public void closeAll() { driver.quit(); } + @Override public void takeScreenshot(OutputStream outputStream) { byte[] data = attemptAndGet(() -> driver.getScreenshotAs(OutputType.BYTES)); - try { - outputStream.write(data); - outputStream.flush(); - outputStream.close(); + + try (OutputStream stream = outputStream) { + stream.write(data); + stream.flush(); } catch (IOException e) { throw new DarcyException("Could not take screenshot", e); } diff --git a/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java index b844542..29a57c9 100644 --- a/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java @@ -2,9 +2,11 @@ import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; +import static org.mockito.Matchers.any; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.redhat.darcy.ui.DarcyException; @@ -53,37 +55,35 @@ public void shouldTakeScreenshotAndWriteToOutputStreamThenFlushAndCloseInOrder() new StubWebDriverParentContext(), new StubWebDriverElementContext()); - byte[] data = new byte[] { 1, 2, 3 }; - - when(mockedDriver.getScreenshotAs(OutputType.BYTES)) - .thenReturn(data); InOrder inOrder = inOrder(outputStream); browser.takeScreenshot(outputStream); - inOrder.verify(outputStream).write(data); + inOrder.verify(outputStream).write(any(byte[].class)); inOrder.verify(outputStream).flush(); inOrder.verify(outputStream).close(); } @SuppressWarnings("unchecked") @Test(expected = FindableNotPresentException.class) - public void shouldThrowFindableNotPresentExceptionIfDriverIsNotPresent() { - TargetedWebDriver mockedDriver = mock(TargetedWebDriver.class); - OutputStream mockedOutputStream = mock(OutputStream.class); - Browser browser = new WebDriverBrowser(mockedDriver, + public void shouldThrowFindableNotPresentExceptionIfDriverIsNotPresent() throws IOException { + TargetedWebDriver driver = mock(TargetedWebDriver.class); + OutputStream outputStream = mock(OutputStream.class); + Browser browser = new WebDriverBrowser(driver, new StubWebDriverParentContext(), new StubWebDriverElementContext()); - when(mockedDriver.getScreenshotAs(OutputType.BYTES)) + when(driver.getScreenshotAs(OutputType.BYTES)) .thenThrow(NoSuchWindowException.class); - browser.takeScreenshot(mockedOutputStream); + browser.takeScreenshot(outputStream); + + verify(outputStream).close(); } @Test(expected = DarcyException.class) public void shouldThrowDarcyExceptionWhenAnIOExceptionOccurs() throws IOException { - TargetedWebDriver mockedDriver = mock(TargetedWebDriver.class); - Browser browser = new WebDriverBrowser(mockedDriver, + TargetedWebDriver driver = mock(TargetedWebDriver.class); + Browser browser = new WebDriverBrowser(driver, new StubWebDriverParentContext(), new StubWebDriverElementContext()); @@ -91,5 +91,7 @@ public void shouldThrowDarcyExceptionWhenAnIOExceptionOccurs() throws IOExceptio doThrow(new IOException()).when(outputStream).close(); browser.takeScreenshot(outputStream); + + verify(outputStream).close(); } } From 1a40ae79935fb114e5908b8841029b33d0148666 Mon Sep 17 00:00:00 2001 From: Derek McNeil Date: Sat, 31 Oct 2015 12:01:36 -0400 Subject: [PATCH 19/42] Use try-with-resources, update tests --- .../java/com/redhat/darcy/webdriver/WebDriverBrowser.java | 3 +-- .../com/redhat/darcy/webdriver/TakeScreenshotTest.java | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java index 60833a4..fbb68d2 100644 --- a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java +++ b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java @@ -180,9 +180,8 @@ public void closeAll() { @Override public void takeScreenshot(OutputStream outputStream) { - byte[] data = attemptAndGet(() -> driver.getScreenshotAs(OutputType.BYTES)); - try (OutputStream stream = outputStream) { + byte[] data = attemptAndGet(() -> driver.getScreenshotAs(OutputType.BYTES)); stream.write(data); stream.flush(); } catch (IOException e) { diff --git a/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java index 29a57c9..f0ad85f 100644 --- a/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java @@ -65,7 +65,7 @@ public void shouldTakeScreenshotAndWriteToOutputStreamThenFlushAndCloseInOrder() } @SuppressWarnings("unchecked") - @Test(expected = FindableNotPresentException.class) + @Test public void shouldThrowFindableNotPresentExceptionIfDriverIsNotPresent() throws IOException { TargetedWebDriver driver = mock(TargetedWebDriver.class); OutputStream outputStream = mock(OutputStream.class); @@ -75,7 +75,11 @@ public void shouldThrowFindableNotPresentExceptionIfDriverIsNotPresent() throws when(driver.getScreenshotAs(OutputType.BYTES)) .thenThrow(NoSuchWindowException.class); - browser.takeScreenshot(outputStream); + try { + browser.takeScreenshot(outputStream); + } catch (Exception e) { + assertThat(e.getClass(), equalTo(FindableNotPresentException.class)); + } verify(outputStream).close(); } From 6b862395eec4af69350e39d116a96a26be417bfc Mon Sep 17 00:00:00 2001 From: Derek McNeil Date: Sun, 1 Nov 2015 14:17:44 -0500 Subject: [PATCH 20/42] Fix other exception test, add messages --- .../redhat/darcy/webdriver/TakeScreenshotTest.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java index f0ad85f..2b6c016 100644 --- a/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java @@ -78,13 +78,14 @@ public void shouldThrowFindableNotPresentExceptionIfDriverIsNotPresent() throws try { browser.takeScreenshot(outputStream); } catch (Exception e) { - assertThat(e.getClass(), equalTo(FindableNotPresentException.class)); + assertThat("Expected FindableNotPresentException to be thrown", + e.getClass(), equalTo(FindableNotPresentException.class)); } verify(outputStream).close(); } - @Test(expected = DarcyException.class) + @Test public void shouldThrowDarcyExceptionWhenAnIOExceptionOccurs() throws IOException { TargetedWebDriver driver = mock(TargetedWebDriver.class); Browser browser = new WebDriverBrowser(driver, @@ -94,7 +95,12 @@ public void shouldThrowDarcyExceptionWhenAnIOExceptionOccurs() throws IOExceptio OutputStream outputStream = mock(OutputStream.class); doThrow(new IOException()).when(outputStream).close(); - browser.takeScreenshot(outputStream); + try { + browser.takeScreenshot(outputStream); + } catch (Exception e) { + assertThat("Expected DarcyException to be thrown" , + e.getClass(), equalTo(DarcyException.class)); + } verify(outputStream).close(); } From aed3c0e60a2de1d70396b1e2ee954cb84b6a6acc Mon Sep 17 00:00:00 2001 From: Derek McNeil Date: Tue, 3 Nov 2015 10:12:46 -0500 Subject: [PATCH 21/42] Add fail check in case exceptions are not thrown as expected --- .../java/com/redhat/darcy/webdriver/TakeScreenshotTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java index 2b6c016..1b5157e 100644 --- a/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/TakeScreenshotTest.java @@ -2,6 +2,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.inOrder; @@ -77,6 +78,7 @@ public void shouldThrowFindableNotPresentExceptionIfDriverIsNotPresent() throws .thenThrow(NoSuchWindowException.class); try { browser.takeScreenshot(outputStream); + fail("Expected FindableNotPresentException to be thrown"); } catch (Exception e) { assertThat("Expected FindableNotPresentException to be thrown", e.getClass(), equalTo(FindableNotPresentException.class)); @@ -97,6 +99,7 @@ public void shouldThrowDarcyExceptionWhenAnIOExceptionOccurs() throws IOExceptio try { browser.takeScreenshot(outputStream); + fail("Expected DarcyException to be thrown"); } catch (Exception e) { assertThat("Expected DarcyException to be thrown" , e.getClass(), equalTo(DarcyException.class)); From 26db3aec085c0680cfe8a7a755f02e56df62c0dd Mon Sep 17 00:00:00 2001 From: Andrew Bocz Date: Thu, 5 Nov 2015 16:03:18 -0500 Subject: [PATCH 22/42] Update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 49a4428..fa612ea 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ maven com.redhat.darcy darcy-webdriver - 0.2.2-SNAPSHOT + 0.3.0-SNAPSHOT ``` From 0ac182cbe13de8b41b2558b4f5b2d4532cfec0c4 Mon Sep 17 00:00:00 2001 From: Andrew Bocz Date: Mon, 9 Nov 2015 09:33:51 -0500 Subject: [PATCH 23/42] Implement getScreenshotAs and bump to 0.3.1-SNAPSHOT --- README.md | 2 +- pom.xml | 2 +- .../darcy/webdriver/internal/TargetedWebElement.java | 11 ++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index fa612ea..3fe0c8a 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ maven com.redhat.darcy darcy-webdriver - 0.3.0-SNAPSHOT + 0.3.1-SNAPSHOT ``` diff --git a/pom.xml b/pom.xml index a1bbd30..648ce48 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ com.redhat.darcy darcy-webdriver - 0.3.0-SNAPSHOT + 0.3.1-SNAPSHOT jar ${project.groupId}:${project.artifactId} diff --git a/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebElement.java b/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebElement.java index ebfd5e6..3641c2d 100644 --- a/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebElement.java +++ b/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebElement.java @@ -211,6 +211,12 @@ public List findElementsByXPath(String using) { return targetedWebElements(((FindsByXPath) element()).findElementsByXPath(using)); } + + @Override + public X getScreenshotAs(OutputType outputType) throws WebDriverException { + return element().getScreenshotAs(outputType); + } + /** * @return The backing {@link org.openqa.selenium.WebElement}, with the driver switched to the * appropriate target. @@ -230,9 +236,4 @@ private List targetedWebElements(List elements) { .map(e -> new TargetedWebElement(locator, target, e)) .collect(Collectors.toList()); } - - @Override - public X getScreenshotAs(OutputType outputType) throws WebDriverException { - return null; - } } From a68eeb70587f1babb72ba22e87e62a7b44b2bd96 Mon Sep 17 00:00:00 2001 From: Alec Henninger Date: Sun, 22 Nov 2015 22:05:58 -0500 Subject: [PATCH 24/42] Get window handles without switching targets (fixes #62) --- .../webdriver/WebDriverBrowserFactory.java | 2 +- .../TargetedWebDriverParentContext.java | 24 +++++++++++++------ .../TargetedWebDriverParentContextTest.java | 4 +--- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowserFactory.java b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowserFactory.java index 55c3db8..70e7cde 100644 --- a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowserFactory.java +++ b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowserFactory.java @@ -55,7 +55,7 @@ protected static Browser makeBrowser(WebDriver driver, ElementConstructorMap ele CachingTargetLocator cachingLocator = new CachingTargetLocator(target, driver); WebDriverParentContext context = new TargetedWebDriverParentContext(target, cachingLocator, - elementMap); + driver::getWindowHandles, elementMap); return context.findById(Browser.class, currentWindowHandle); } diff --git a/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContext.java b/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContext.java index 82d4f48..3bf0c6c 100644 --- a/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContext.java +++ b/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContext.java @@ -39,6 +39,7 @@ import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.Set; import java.util.function.Supplier; /** @@ -50,6 +51,12 @@ public class TargetedWebDriverParentContext implements WebDriverParentContext { private final WebDriverTarget myTarget; private final TargetLocator locator; private final ElementConstructorMap elementMap; + private final KnowsWindowHandles knowsWindowHandles; + + @FunctionalInterface + public interface KnowsWindowHandles { + Set getWindowHandles(); + } /** * @param myTarget Parent contexts must be targeted because frame targets depend on another, @@ -57,13 +64,16 @@ public class TargetedWebDriverParentContext implements WebDriverParentContext { * associated with, because this state is used when finding frames. * @param locator Means of finding other WebDrivers for new targets. Each new browser shares the * same locator. - * @param elementMap Each new browser must have an element constructor map so it may create - * element objects. Each new browser shares the same map. + * @param knowsWindowHandles Finds open windows' handles. Must be associated with the same + * driver as the {@code locator}. + * @param elementMap Each new browser must have an element conFunction or type which can provide the current set of window + * handles of the driver associated with the locator.structor map so it may create */ public TargetedWebDriverParentContext(WebDriverTarget myTarget, TargetLocator locator, - ElementConstructorMap elementMap) { + KnowsWindowHandles knowsWindowHandles, ElementConstructorMap elementMap) { this.myTarget = myTarget; this.locator = locator; + this.knowsWindowHandles = knowsWindowHandles; this.elementMap = elementMap; } @@ -229,7 +239,7 @@ private WebDriverBrowser newBrowser(WebDriverTarget target) { TargetedWebDriver targetedDriver = new ForwardingTargetedWebDriver(locator, target); return new WebDriverBrowser(targetedDriver, - new TargetedWebDriverParentContext(target, locator, elementMap), + new TargetedWebDriverParentContext(target, locator, knowsWindowHandles, elementMap), new DefaultWebDriverElementContext(targetedDriver, elementMap)); } @@ -244,7 +254,7 @@ class FoundByViewSupplier implements Supplier> { public List get() { List found = new ArrayList<>(); - for (String windowHandle : locator.defaultContent().getWindowHandles()) { + for (String windowHandle : knowsWindowHandles.getWindowHandles()) { Browser forWindowHandle = findById(Browser.class, windowHandle); ElementContext priorContext = view.getContext(); @@ -274,7 +284,7 @@ class FoundByTitleSupplier implements Supplier> { public List get() { List found = new ArrayList<>(); - for (String windowHandle : locator.defaultContent().getWindowHandles()) { + for (String windowHandle : knowsWindowHandles.getWindowHandles()) { if (locator.window(windowHandle).getTitle().equals(title)) { found.add(findById(Browser.class, windowHandle)); } @@ -295,7 +305,7 @@ public FoundByUrlSupplier(Matcher urlMatcher) { public List get() { List found = new ArrayList<>(); - for (String windowHandle : locator.defaultContent().getWindowHandles()) { + for (String windowHandle : knowsWindowHandles.getWindowHandles()) { if (urlMatcher.matches(locator.window(windowHandle).getCurrentUrl())) { found.add(findById(Browser.class, windowHandle)); } diff --git a/src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContextTest.java b/src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContextTest.java index 0fadce1..29c3239 100644 --- a/src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContextTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContextTest.java @@ -24,7 +24,6 @@ import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.sameInstance; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; @@ -43,7 +42,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.openqa.selenium.internal.WrapsDriver; import java.util.Arrays; import java.util.HashSet; @@ -58,7 +56,7 @@ public class TargetedWebDriverParentContextTest { private TargetedWebDriverParentContext context = new TargetedWebDriverParentContext(contextTarget, mockTargetedLocator, - mock(ElementConstructorMap.class)); + mockTargetedDriver::getWindowHandles, mock(ElementConstructorMap.class)); @Before public void stubMocks() { From ad34587837c3df1369856ed0252c8549f34f65f2 Mon Sep 17 00:00:00 2001 From: Andrew Bocz Date: Thu, 28 Jan 2016 10:13:12 -0500 Subject: [PATCH 25/42] Use selenium-server 2.50.0 --- README.md | 2 +- pom.xml | 4 ++-- .../redhat/darcy/webdriver/internal/TargetedWebElement.java | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3fe0c8a..1135d7b 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ maven com.redhat.darcy darcy-webdriver - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT ``` diff --git a/pom.xml b/pom.xml index 648ce48..2d5f874 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ com.redhat.darcy darcy-webdriver - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT jar ${project.groupId}:${project.artifactId} @@ -69,7 +69,7 @@ org.seleniumhq.selenium selenium-server - 2.48.2 + 2.50.0 com.google.guiceberry diff --git a/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebElement.java b/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebElement.java index 3641c2d..242b230 100644 --- a/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebElement.java +++ b/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebElement.java @@ -25,6 +25,7 @@ import org.openqa.selenium.Dimension; import org.openqa.selenium.OutputType; import org.openqa.selenium.Point; +import org.openqa.selenium.Rectangle; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.WebElement; import org.openqa.selenium.internal.FindsByClassName; @@ -126,6 +127,11 @@ public Dimension getSize() { return element().getSize(); } + @Override + public Rectangle getRect() { + return element().getRect(); + } + @Override public String getCssValue(String propertyName) { return element().getCssValue(propertyName); From dbb289f0b68fddb8083341525a178ccee4271082 Mon Sep 17 00:00:00 2001 From: Andrew Bocz Date: Thu, 28 Jan 2016 10:53:01 -0500 Subject: [PATCH 26/42] Unit test TargetedWebElement new method getRect() --- .../internal/TargetedWebElementTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebElementTest.java diff --git a/src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebElementTest.java b/src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebElementTest.java new file mode 100644 index 0000000..c1d19dc --- /dev/null +++ b/src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebElementTest.java @@ -0,0 +1,26 @@ +package com.redhat.darcy.webdriver.internal; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.junit.Test; +import org.openqa.selenium.Rectangle; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +public class TargetedWebElementTest { + + @Test + public void shouldCallGetRectOnUnderlyingWebElement() { + WebDriver.TargetLocator targetLocator = mock(WebDriver.TargetLocator.class); + WebDriverTarget webDriverTarget = mock(WebDriverTarget.class); + WebElement webElement = mock(WebElement.class); + when(webElement.getRect()).thenReturn(mock(Rectangle.class)); + TargetedWebElement targetedWebElement = new TargetedWebElement(targetLocator, webDriverTarget, webElement); + + targetedWebElement.getRect(); + verify(webElement.getRect()); + } + +} From 7dc5d1064bdf3a295980203a6c7bcee4d1332fcd Mon Sep 17 00:00:00 2001 From: Andrew Bocz Date: Thu, 28 Jan 2016 11:22:41 -0500 Subject: [PATCH 27/42] Fix error in TargetedWebElementTest --- .../internal/TargetedWebElementTest.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebElementTest.java b/src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebElementTest.java index c1d19dc..d5cad66 100644 --- a/src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebElementTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/internal/TargetedWebElementTest.java @@ -5,22 +5,23 @@ import static org.mockito.Mockito.when; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.openqa.selenium.Rectangle; import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; +@RunWith(JUnit4.class) public class TargetedWebElementTest { @Test public void shouldCallGetRectOnUnderlyingWebElement() { - WebDriver.TargetLocator targetLocator = mock(WebDriver.TargetLocator.class); - WebDriverTarget webDriverTarget = mock(WebDriverTarget.class); - WebElement webElement = mock(WebElement.class); - when(webElement.getRect()).thenReturn(mock(Rectangle.class)); - TargetedWebElement targetedWebElement = new TargetedWebElement(targetLocator, webDriverTarget, webElement); + WebDriver.TargetLocator locator = mock(WebDriver.TargetLocator.class); + WebDriverTarget target = mock(WebDriverTarget.class); + TargetedWebElement element = mock(TargetedWebElement.class); + when(element.getRect()).thenReturn(mock(Rectangle.class)); + TargetedWebElement targetedWebElement = new TargetedWebElement(locator, target, element); targetedWebElement.getRect(); - verify(webElement.getRect()); + verify(element).getRect(); } - } From d416d33a4d71a212896586d47077bc4a26a0135e Mon Sep 17 00:00:00 2001 From: Alec Henninger Date: Sun, 7 Feb 2016 15:22:31 -0500 Subject: [PATCH 28/42] Cleanup pom Removes deprecated sonatype parent, reorganizes, and allows release to central with mvn release plugin. --- pom.xml | 229 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 179 insertions(+), 50 deletions(-) diff --git a/pom.xml b/pom.xml index 2d5f874..7c2ac57 100644 --- a/pom.xml +++ b/pom.xml @@ -1,12 +1,6 @@ 4.0.0 - - org.sonatype.oss - oss-parent - 7 - - com.redhat.darcy darcy-webdriver 0.3.2-SNAPSHOT @@ -16,75 +10,61 @@ An implementation of darcy and darcy-web that uses Selenium WebDriver as the automation library backend. https://github.com/darcy-framework/darcy-webdriver - - - GNU General Public License, Version 3 - https://www.gnu.org/licenses/gpl-3.0.txt - repo - - + + 0.1.2-SNAPSHOT + 0.3.0-SNAPSHOT + 2.50.0 + 1.5 + 4.0-beta5 + 3.3.1 - - scm:git:https://github.com/darcy-framework/darcy-webdriver.git - scm:git:git@github.com:darcy-framework/darcy-webdriver.git - https://github.com/darcy-framework/darcy-webdriver - + 4.12 + 2.0.26-beta - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - true - - 1.8 - 1.8 - - - - org.eluder.coveralls - coveralls-maven-plugin - 2.2.0 - - - org.jacoco - jacoco-maven-plugin - 0.7.1.201405082137 - - - + 3.5 + 2.19.1 + 2.4 + 2.5.3 + 2.10.3 + 4.1.0 + 0.7.5.201505241946 + 1.6 + 1.6.6 + + 3.0.4 + UTF-8 + com.redhat.darcy darcy-web - 0.3.0-SNAPSHOT + ${version.darcy-web} com.redhat.synq synq - 0.1.2-SNAPSHOT + ${version.synq} org.seleniumhq.selenium selenium-server - 2.50.0 + ${version.selenium} com.google.guiceberry guiceberry - 3.3.1 + ${version.guiceberry} com.google.inject guice - 4.0-beta5 + ${version.guice} com.opera operadriver - 1.5 + ${version.operadriver} org.apache.commons @@ -95,15 +75,164 @@ org.mockito mockito-core - 2.0.26-beta + ${version.mockito} test junit junit - 4.11 + ${version.junit} test + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${version.maven-compiler-plugin} + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-surefire-plugin + ${version.maven-surefire-plugin} + + + org.apache.maven.plugins + maven-source-plugin + ${version.maven-source-plugin} + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-release-plugin + ${version.maven-release-plugin} + + true + false + release + deploy + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${version.nexus-staging-maven-plugin} + true + + ossrh + https://oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${version.maven-javadoc-plugin} + + + attach-javadocs + + jar + + + + + + org.eluder.coveralls + coveralls-maven-plugin + ${version.coveralls-maven-plugin} + + + org.jacoco + jacoco-maven-plugin + ${version.jacoco-maven-plugin} + + + prepare-agent + + prepare-agent + + + + + + + + + + release + + + + org.apache.maven.plugins + maven-gpg-plugin + ${version.maven-gpg-plugin} + + + sign-artifacts + verify + + sign + + + + + + + + + + + ${prerequisites.maven} + + + + scm:git:https://github.com/darcy-framework/darcy-webdriver.git + scm:git:git@github.com:darcy-framework/darcy-webdriver.git + https://github.com/darcy-framework/darcy-webdriver + HEAD + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + + + + GNU General Public License, Version 3 + https://www.gnu.org/licenses/gpl-3.0.txt + repo + + + + + + alechenninger + Alec Henninger + alechenninger@gmail.com + Red Hat + + architect + developer + + -5 + + From fd9da3ed7c08d40d3f04ac9da3579d902bca412a Mon Sep 17 00:00:00 2001 From: Alec Henninger Date: Sun, 7 Feb 2016 15:25:14 -0500 Subject: [PATCH 29/42] Fix coveralls and deploy travis script bits --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 23f0f1c..8ecc9f8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,11 +8,10 @@ before_script: - "export DISPLAY=:99.0" - "sh -e /etc/init.d/xvfb start" - -script: '[ ${TRAVIS_PULL_REQUEST} = ''false'' ] && mvn clean deploy -P sonatype-oss-release -Dgpg.skip=true --settings target/travis/settings.xml || mvn clean verify --settings target/travis/settings.xml' +script: '[ ${TRAVIS_PULL_REQUEST} = ''false'' ] && mvn clean deploy --settings target/travis/settings.xml || mvn clean verify --settings target/travis/settings.xml' after_success: - - mvn clean jacoco:prepare-agent test jacoco:report coveralls:jacoco + - mvn clean test jacoco:report coveralls:report branches: only: From f5bd63ae1d3c7f655e425b96c968ef7285f1fd87 Mon Sep 17 00:00:00 2001 From: Alec Henninger Date: Sun, 7 Feb 2016 15:32:16 -0500 Subject: [PATCH 30/42] Add release artifacts to gitignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0e640b8..7a87ce5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ .classpath *.iml /bin/ -.idea \ No newline at end of file +.idea +*.releaseBackup +release.properties From 7e04462ffcb4829fdfd8ec3a799a1420b960b4d1 Mon Sep 17 00:00:00 2001 From: Alec Henninger Date: Sun, 7 Feb 2016 16:02:01 -0500 Subject: [PATCH 31/42] [maven-release-plugin] prepare release 0.3.2 --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 7c2ac57..0db771b 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.redhat.darcy darcy-webdriver - 0.3.2-SNAPSHOT + 0.3.2 jar ${project.groupId}:${project.artifactId} @@ -39,12 +39,12 @@ com.redhat.darcy darcy-web - ${version.darcy-web} + 0.3.0 com.redhat.synq synq - ${version.synq} + 0.1.3 org.seleniumhq.selenium @@ -203,7 +203,7 @@ scm:git:https://github.com/darcy-framework/darcy-webdriver.git scm:git:git@github.com:darcy-framework/darcy-webdriver.git https://github.com/darcy-framework/darcy-webdriver - HEAD + 0.3.2 From 70e21d57a1f251252d0ee255026691a34b07dfbf Mon Sep 17 00:00:00 2001 From: Alec Henninger Date: Sun, 7 Feb 2016 16:02:05 -0500 Subject: [PATCH 32/42] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 0db771b..495769a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.redhat.darcy darcy-webdriver - 0.3.2 + 0.3.3-SNAPSHOT jar ${project.groupId}:${project.artifactId} @@ -203,7 +203,7 @@ scm:git:https://github.com/darcy-framework/darcy-webdriver.git scm:git:git@github.com:darcy-framework/darcy-webdriver.git https://github.com/darcy-framework/darcy-webdriver - 0.3.2 + HEAD From bb4a02e5083069071717540646d624086d4a3b9b Mon Sep 17 00:00:00 2001 From: abocz Date: Fri, 12 Feb 2016 12:47:12 -0500 Subject: [PATCH 33/42] Use selenium-server 2.52.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 495769a..1d2197f 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ 0.1.2-SNAPSHOT 0.3.0-SNAPSHOT - 2.50.0 + 2.52.0 1.5 4.0-beta5 3.3.1 From cee23b150c72cfc3235a1d36ccb8bf146202d67c Mon Sep 17 00:00:00 2001 From: Faisal Hameed Date: Thu, 24 Mar 2016 23:02:03 +0500 Subject: [PATCH 34/42] Fixing squid:S1155, squid:S229, squid:S2259 --- .../webdriver/internal/TargetedWebDriverParentContext.java | 6 +++--- .../java/com/redhat/darcy/webdriver/locators/ByChained.java | 2 +- .../com/redhat/darcy/webdriver/locators/ByVisibleText.java | 2 +- .../darcy/webdriver/locators/ByVisibleTextIgnoreCase.java | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContext.java b/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContext.java index 3bf0c6c..8f0f122 100644 --- a/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContext.java +++ b/src/main/java/com/redhat/darcy/webdriver/internal/TargetedWebDriverParentContext.java @@ -131,7 +131,7 @@ public List findAllByView(Class type, View view) { + "available frames."); } - return (List) new LazyList(new FoundByViewSupplier(view)); + return (List) new LazyList<>(new FoundByViewSupplier(view)); } @SuppressWarnings("unchecked") @@ -161,7 +161,7 @@ public List findAllByTitle(Class type, String title) { + "available frames."); } - return (List) new LazyList(new FoundByTitleSupplier(title)); + return (List) new LazyList<>(new FoundByTitleSupplier(title)); } @SuppressWarnings("unchecked") @@ -190,7 +190,7 @@ public List findAllByUrl(Class type, Matcher urlMatche + "available frames."); } - return (List) new LazyList(new FoundByUrlSupplier(urlMatcher)); + return (List) new LazyList<>(new FoundByUrlSupplier(urlMatcher)); } @Override diff --git a/src/main/java/com/redhat/darcy/webdriver/locators/ByChained.java b/src/main/java/com/redhat/darcy/webdriver/locators/ByChained.java index d572543..81a884d 100644 --- a/src/main/java/com/redhat/darcy/webdriver/locators/ByChained.java +++ b/src/main/java/com/redhat/darcy/webdriver/locators/ByChained.java @@ -71,7 +71,7 @@ public List findElements(SearchContext context) { } } - return found.stream() + return found == null ? null : found.stream() .map(WebDriverElement::getWrappedElement) .collect(Collectors.toList()); } diff --git a/src/main/java/com/redhat/darcy/webdriver/locators/ByVisibleText.java b/src/main/java/com/redhat/darcy/webdriver/locators/ByVisibleText.java index 90656e0..f93c702 100644 --- a/src/main/java/com/redhat/darcy/webdriver/locators/ByVisibleText.java +++ b/src/main/java/com/redhat/darcy/webdriver/locators/ByVisibleText.java @@ -48,7 +48,7 @@ public ByVisibleText(String text) { @Override public List findElements(SearchContext context) { - List result = new ArrayList(); + List result = new ArrayList<>(); // First find any elements that *contain* this text. List elems = byPartialVisibleText.findElements(context); diff --git a/src/main/java/com/redhat/darcy/webdriver/locators/ByVisibleTextIgnoreCase.java b/src/main/java/com/redhat/darcy/webdriver/locators/ByVisibleTextIgnoreCase.java index fb4c55a..842dc4d 100644 --- a/src/main/java/com/redhat/darcy/webdriver/locators/ByVisibleTextIgnoreCase.java +++ b/src/main/java/com/redhat/darcy/webdriver/locators/ByVisibleTextIgnoreCase.java @@ -45,7 +45,7 @@ public ByVisibleTextIgnoreCase(String text) { @Override public List findElements(SearchContext context) { - List result = new ArrayList(); + List result = new ArrayList<>(); // First find any elements that *contain* this text. List elems = byPartialVisibleTextIgnoreCase.findElements(context); @@ -60,7 +60,7 @@ public List findElements(SearchContext context) { } } - if (result.size() == 0) { + if (result.isEmpty()) { throw new NoSuchElementException("Cannot locate an element using " + toString()); } From 412e5fbeda84585710534744eaed2bcf8df09646 Mon Sep 17 00:00:00 2001 From: abocz Date: Wed, 6 Jul 2016 13:16:30 -0400 Subject: [PATCH 35/42] Increase selenium version to 2.53.1 and remove redundant exception --- pom.xml | 2 +- .../darcy/webdriver/internal/ForwardingTargetedWebDriver.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 1d2197f..892805a 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ 0.1.2-SNAPSHOT 0.3.0-SNAPSHOT - 2.52.0 + 2.53.1 1.5 4.0-beta5 3.3.1 diff --git a/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedWebDriver.java b/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedWebDriver.java index 43d233b..32ce538 100644 --- a/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedWebDriver.java +++ b/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedWebDriver.java @@ -71,7 +71,7 @@ public boolean isPresent() { try { driver().getTitle(); return true; - } catch (NotFoundException | SessionNotFoundException e) { + } catch (NotFoundException e) { return false; } } From 30b8c1b6dd7e7d26ca285746e0ab540626aa9be1 Mon Sep 17 00:00:00 2001 From: abocz Date: Wed, 6 Jul 2016 13:19:40 -0400 Subject: [PATCH 36/42] Update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1135d7b..5a557a4 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ maven com.redhat.darcy darcy-webdriver - 0.3.2-SNAPSHOT + 0.3.3-SNAPSHOT ``` From 87c4710a48549000643b1347475cc5778a7e76e2 Mon Sep 17 00:00:00 2001 From: abocz Date: Wed, 6 Jul 2016 14:34:20 -0400 Subject: [PATCH 37/42] Fix missing exception identifier --- .../darcy/webdriver/internal/ForwardingTargetedWebDriver.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedWebDriver.java b/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedWebDriver.java index 32ce538..812b344 100644 --- a/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedWebDriver.java +++ b/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedWebDriver.java @@ -21,6 +21,7 @@ import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.NoSuchSessionException; import org.openqa.selenium.NotFoundException; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; From 5527ea40f2f5352abe13517884f981e4a626a9e8 Mon Sep 17 00:00:00 2001 From: abocz Date: Thu, 7 Jul 2016 10:06:20 -0400 Subject: [PATCH 38/42] Remove unused imports --- .../darcy/webdriver/internal/ForwardingTargetedWebDriver.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedWebDriver.java b/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedWebDriver.java index 812b344..b3ed627 100644 --- a/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedWebDriver.java +++ b/src/main/java/com/redhat/darcy/webdriver/internal/ForwardingTargetedWebDriver.java @@ -21,7 +21,6 @@ import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.NoSuchSessionException; import org.openqa.selenium.NotFoundException; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; @@ -36,7 +35,6 @@ import org.openqa.selenium.internal.FindsByTagName; import org.openqa.selenium.internal.FindsByXPath; import org.openqa.selenium.internal.WrapsDriver; -import org.openqa.selenium.remote.SessionNotFoundException; import java.util.List; import java.util.Objects; From 8b4b1803f480fd8c3923c319adedf4c8554b2909 Mon Sep 17 00:00:00 2001 From: Jimmy Ver Vaecke Date: Thu, 10 Aug 2017 15:26:59 -0400 Subject: [PATCH 39/42] Use Selenium 3.4.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 892805a..f1ee8dd 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ 0.1.2-SNAPSHOT 0.3.0-SNAPSHOT - 2.53.1 + 3.4.0 1.5 4.0-beta5 3.3.1 From 03d5509b7fbfc7f6d40f4f028df0ee6f22a73846 Mon Sep 17 00:00:00 2001 From: Jimmy Ver Vaecke Date: Thu, 10 Aug 2017 15:27:46 -0400 Subject: [PATCH 40/42] Replace SessionNotFoundException with NoSuchSessionException SessionNotFoundexception was previously depricated and then removed in Selenium 3.0.0 --- .../java/com/redhat/darcy/webdriver/WebDriverBrowser.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java index fbb68d2..3f2dc56 100644 --- a/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java +++ b/src/main/java/com/redhat/darcy/webdriver/WebDriverBrowser.java @@ -44,9 +44,9 @@ import org.hamcrest.Matcher; import org.openqa.selenium.NoSuchFrameException; +import org.openqa.selenium.NoSuchSessionException; import org.openqa.selenium.NoSuchWindowException; import org.openqa.selenium.OutputType; -import org.openqa.selenium.remote.SessionNotFoundException; import java.io.IOException; import java.io.OutputStream; @@ -365,7 +365,7 @@ public TargetedWebDriver getWrappedDriver() { private void attempt(Runnable action) { try { action.run(); - } catch (NoSuchFrameException | NoSuchWindowException | SessionNotFoundException e) { + } catch (NoSuchFrameException | NoSuchWindowException | NoSuchSessionException e) { throw new FindableNotPresentException(this, e); } } @@ -377,7 +377,7 @@ private void attempt(Runnable action) { private T attemptAndGet(Supplier action) { try { return action.get(); - } catch (NoSuchFrameException | NoSuchWindowException | SessionNotFoundException e) { + } catch (NoSuchFrameException | NoSuchWindowException | NoSuchSessionException e) { throw new FindableNotPresentException(this, e); } } From 972886e4586a838c86675309ededddbb187f00fe Mon Sep 17 00:00:00 2001 From: Jimmy Ver Vaecke Date: Thu, 10 Aug 2017 15:31:03 -0400 Subject: [PATCH 41/42] Update version It should technically be backwards compatibile if your automation project only references darcy apis. But if you were still referencing selenium-rc, that's going to break. --- README.md | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5a557a4..ce7103b 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ maven com.redhat.darcy darcy-webdriver - 0.3.3-SNAPSHOT + 0.4.0-SNAPSHOT ``` diff --git a/pom.xml b/pom.xml index f1ee8dd..5257b08 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.redhat.darcy darcy-webdriver - 0.3.3-SNAPSHOT + 0.4.0-SNAPSHOT jar ${project.groupId}:${project.artifactId} From 61dd915e8a649f474205706fd63a2d84cf09dfca Mon Sep 17 00:00:00 2001 From: Jimmy Ver Vaecke Date: Thu, 10 Aug 2017 15:53:35 -0400 Subject: [PATCH 42/42] Fix test failure when geckodriver doesn't exist --- .../com/redhat/darcy/webdriver/FirefoxBrowserFactoryTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/com/redhat/darcy/webdriver/FirefoxBrowserFactoryTest.java b/src/test/java/com/redhat/darcy/webdriver/FirefoxBrowserFactoryTest.java index 7e780e5..25c722e 100644 --- a/src/test/java/com/redhat/darcy/webdriver/FirefoxBrowserFactoryTest.java +++ b/src/test/java/com/redhat/darcy/webdriver/FirefoxBrowserFactoryTest.java @@ -21,6 +21,7 @@ import static org.hamcrest.Matchers.instanceOf; import static org.junit.Assert.assertThat; +import static org.junit.Assume.assumeNotNull; import static org.junit.Assume.assumeTrue; import com.redhat.darcy.webdriver.internal.CachingTargetLocator; @@ -37,6 +38,7 @@ public class FirefoxBrowserFactoryTest { @Before public void checkForDriver() { assumeTrue(System.getProperty("java.class.path").contains("firefox-driver")); + assumeNotNull(System.getProperty("webdriver.gecko.driver")); } @After