-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start rewrite for thread safety, automatic stale element resolution
This is a huge refactoring motivated by: - Wanting to move away from unnecessary dynamic proxies - Needing thread safe access to driver - Needing to automatically refind elements if they are stale - Needing to have targeted drivers and elements - Needing to add locator information to toString (not done yet, but now possible) It works by creating various implementations of WebElement and WebDriver that accomplish each of those above needs (more or less). This allows each need to be focused and individually testable. On the downside, the real driver is heavily nested, something like: ThreadedWebDriver - driver: ForwardingTargetedWebDriver - driver: RefindingWebDriver - driver: FirefoxDriver -- real impl Likewise with WebElements: ThreadedWebElement - element: ForwardingTargetedWebElement - element: RefindingWebElement - element: RemoteWebElement -- real impl On the plus side, none of those implementations have to know about any other. Care must be taken in wiring them up the right way, however. As of now, not everything is completely tested or verified, but the fundamentals work. Known issues: - Lists of elements are not refinding. Not sure if it's possible. - Could/should at least create refinding element if list size == 1 - Could use javascript to associate each element in the list with xpath, and use that to relook up individual elements, but this is a little scary.
- Loading branch information
1 parent
18c2cb7
commit c9c4b85
Showing
25 changed files
with
2,060 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...n/java/com/redhat/darcy/webdriver/internal/ThreadSafeCachingTargetedWebDriverFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.redhat.darcy.webdriver.internal; | ||
|
||
import com.redhat.darcy.webdriver.internal.webdriver.ForwardingTargetedWebDriver; | ||
import com.redhat.darcy.webdriver.internal.webdriver.RefindingWebDriver; | ||
import com.redhat.darcy.webdriver.internal.webdriver.ThreadedTargetedWebDriver; | ||
|
||
import org.openqa.selenium.WebDriver; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
public class ThreadSafeCachingTargetedWebDriverFactory implements TargetedWebDriverFactory { | ||
// It's important that all access to driver is gated by same executor | ||
private final ExecutorService executor = Executors.newSingleThreadExecutor(); | ||
private final CachingTargetLocator cachingTargetLocator; | ||
|
||
public ThreadSafeCachingTargetedWebDriverFactory(WebDriver untargetedDriver, | ||
WebDriverTarget currentTarget) { | ||
cachingTargetLocator = new CachingTargetLocator(currentTarget, | ||
new RefindingWebDriver(untargetedDriver)); | ||
} | ||
|
||
@Override | ||
public TargetedWebDriver getTargetedWebDriver(WebDriverTarget target) { | ||
// Order is important here: we want atomic operations to be executed in a single threaded | ||
// queue, so driver switching needs to happen in the same queued task as the subsequent | ||
// action. This means that the outer most driver should queue the operations of the | ||
// forwarded driver -- which takes care of the switching. | ||
|
||
// Inner to outer: | ||
// 1. Refinding -- finds elements that can refind themselves if stale (these show up because | ||
// CachingTargetLocator is powered by a RefindingDriver). | ||
// 2. Targeted -- targets a specific driver before proceeding, creates elements that do same | ||
// (So with refinding, creates elements that target a driver, then can refind themselves | ||
// if stale). | ||
// 3. Threaded -- Assures atomic, single threaded interaction with driver from any source | ||
return new ThreadedTargetedWebDriver( | ||
new ForwardingTargetedWebDriver(cachingTargetLocator, target), executor); | ||
} | ||
} |
Oops, something went wrong.