-
Notifications
You must be signed in to change notification settings - Fork 530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ATH IMPROVEMENT] Allow local Jenkins instance, simplified API #1484
Merged
Merged
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
87ecc77
Update ATH tests for new flow
kzantow 33ccc9c
Handle more close cases for errors
kzantow f8f224d
Some refactoring
kzantow f070bbe
Add ability to read a properties file for ATH (~/.blueocean-ath-config)
kzantow 78aa546
Add ability to read a properties file for ATH (~/.blueocean-ath-config)
kzantow f605005
Add ability to read a properties file for ATH (~/.blueocean-ath-config)
kzantow 8d010e5
Whoops
kzantow 1c58498
Whoops, whoops
kzantow a17c707
Merge remote-tracking branch 'primary/master' into ATH-allow-local-dev
kzantow 97e6cf4
Whoops, whoops
kzantow 04bb80f
Missed a couple things
kzantow cdd1ed4
Merge remote-tracking branch 'primary/master' into ATH-allow-local-dev
kzantow 972f4a0
Tweaks based on PR feedback
kzantow d89172d
Consolidate `go` method
kzantow 2201f7a
Consolidate `go` method
kzantow 5cce6ec
Imports
kzantow 4cb6779
Merge remote-tracking branch 'primary/master' into ATH-allow-local-dev
kzantow aa434f2
Imports
kzantow c686b05
Merge remote-tracking branch 'primary/master' into ATH-allow-local-dev
kzantow fced2e0
Use 'improved' click logic for github pipeline create
kzantow 9922950
Merge remote-tracking branch 'primary/master' into ATH-allow-local-dev
kzantow add4f4a
Typo
kzantow dbf0fc2
Merge remote-tracking branch 'primary/master' into ATH-allow-local-dev
kzantow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
255 changes: 255 additions & 0 deletions
255
acceptance-tests/src/main/java/io/blueocean/ath/LocalDriverElement.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,255 @@ | ||
package io.blueocean.ath; | ||
|
||
import org.openqa.selenium.*; | ||
import org.openqa.selenium.support.ui.ExpectedConditions; | ||
import org.openqa.selenium.support.ui.FluentWait; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Wrapper around an underlying WebDriver that | ||
* consistently handles waits automatically. | ||
* | ||
* Accepts expressions for css and xpath, if the provided lookup starts with a /, XPath is used | ||
*/ | ||
public class LocalDriverElement implements WebElement { | ||
private static ThreadLocal<WebDriver> CURRENT_WEB_DRIVER = new ThreadLocal<>(); | ||
|
||
protected String expr; | ||
|
||
public LocalDriverElement(String expr) { | ||
this.expr = expr; | ||
} | ||
|
||
public static void setCurrent(WebDriver driver) { | ||
CURRENT_WEB_DRIVER.set(driver); | ||
} | ||
|
||
public static void close() { | ||
WebDriver driver = CURRENT_WEB_DRIVER.get(); | ||
if (driver != null) { | ||
try { | ||
driver.close(); | ||
} catch(Exception e) { | ||
// ignore, this happens when running individual tests sometimes | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Finds an element by the provided expression {@see LocalDriverElement} | ||
* @param expr css or xpath; if it starts with a /, XPath is used | ||
* @return a new LocalDriverElement | ||
*/ | ||
public static LocalDriverElement find(String expr) { | ||
return new LocalDriverElement(expr); | ||
} | ||
|
||
/** | ||
* Executes javascript, returns the result | ||
* @param script javascript to execute | ||
* @return the result | ||
*/ | ||
public static Object eval(String script) { | ||
return new FluentWait<>(CURRENT_WEB_DRIVER.get()) | ||
.pollingEvery(100, TimeUnit.MILLISECONDS) | ||
.withTimeout(WaitUtil.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS) | ||
.ignoring(NoSuchElementException.class) | ||
.until(ExpectedConditions.jsReturnsValue(script)); | ||
} | ||
|
||
/** | ||
* Navigates to a specified url | ||
* @param url where to go | ||
*/ | ||
public static void go(String url) { | ||
CURRENT_WEB_DRIVER.get().get(url); | ||
} | ||
|
||
/** | ||
* Gets a WebDriver instance | ||
* @return from threadlocal | ||
*/ | ||
protected WebDriver getDriver() { | ||
return CURRENT_WEB_DRIVER.get(); | ||
} | ||
|
||
/** | ||
* Gets elements | ||
* @return the elements found | ||
*/ | ||
public List<WebElement> getElements() { | ||
By by; | ||
if (expr.startsWith("/")) { | ||
by = By.xpath(expr); | ||
} else { | ||
by = By.cssSelector(expr); | ||
} | ||
return new FluentWait<>(getDriver()) | ||
.pollingEvery(100, TimeUnit.MILLISECONDS) | ||
.withTimeout(WaitUtil.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS) | ||
.ignoring(NoSuchElementException.class) | ||
//.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(by)); | ||
.until(ExpectedConditions.numberOfElementsToBeMoreThan(by, 0)); | ||
} | ||
|
||
/** | ||
* Gets the first matching element | ||
* @return see description | ||
*/ | ||
public WebElement getElement() { | ||
return getElements().iterator().next(); | ||
} | ||
|
||
/** | ||
* Iterates over all found elements with the given function | ||
* @param fn to perform on the elements | ||
*/ | ||
public void forEach(java.util.function.Consumer<WebElement> fn) { | ||
for (WebElement e : getElements()) { | ||
fn.accept(e); | ||
} | ||
} | ||
|
||
public boolean isVisible() { | ||
return getElement().isDisplayed(); | ||
} | ||
|
||
@Override | ||
public void click() { | ||
forEach(e -> e.click()); | ||
} | ||
|
||
@Override | ||
public void submit() { | ||
forEach(e -> e.submit()); | ||
} | ||
|
||
@Override | ||
public void sendKeys(CharSequence... charSequences) { | ||
forEach(e -> e.sendKeys(charSequences)); | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
forEach(e -> e.clear()); | ||
} | ||
|
||
@Override | ||
public String getTagName() { | ||
WebElement el = getElement(); | ||
if (el == null) { | ||
return null; | ||
} | ||
return el.getTagName(); | ||
} | ||
|
||
@Override | ||
public String getAttribute(String s) { | ||
WebElement el = getElement(); | ||
if (el == null) { | ||
return null; | ||
} | ||
return el.getAttribute(s); | ||
} | ||
|
||
@Override | ||
public boolean isSelected() { | ||
WebElement el = getElement(); | ||
if (el == null) { | ||
return false; | ||
} | ||
return el.isSelected(); | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
WebElement el = getElement(); | ||
if (el == null) { | ||
return false; | ||
} | ||
return el.isEnabled(); | ||
} | ||
|
||
@Override | ||
public String getText() { | ||
WebElement el = getElement(); | ||
if (el == null) { | ||
return null; | ||
} | ||
return el.getText(); | ||
} | ||
|
||
@Override | ||
public List<WebElement> findElements(By by) { | ||
WebElement el = getElement(); | ||
if (el == null) { | ||
return null; | ||
} | ||
return el.findElements(by); | ||
} | ||
|
||
@Override | ||
public WebElement findElement(By by) { | ||
WebElement el = getElement(); | ||
if (el == null) { | ||
return null; | ||
} | ||
return el.findElement(by); | ||
} | ||
|
||
@Override | ||
public boolean isDisplayed() { | ||
WebElement el = getElement(); | ||
if (el == null) { | ||
return false; | ||
} | ||
return el.isDisplayed(); | ||
} | ||
|
||
@Override | ||
public Point getLocation() { | ||
WebElement el = getElement(); | ||
if (el == null) { | ||
return null; | ||
} | ||
return el.getLocation(); | ||
} | ||
|
||
@Override | ||
public Dimension getSize() { | ||
WebElement el = getElement(); | ||
if (el == null) { | ||
return null; | ||
} | ||
return el.getSize(); | ||
} | ||
|
||
@Override | ||
public Rectangle getRect() { | ||
WebElement el = getElement(); | ||
if (el == null) { | ||
return null; | ||
} | ||
return el.getRect(); | ||
} | ||
|
||
@Override | ||
public String getCssValue(String s) { | ||
WebElement el = getElement(); | ||
if (el == null) { | ||
return null; | ||
} | ||
return el.getCssValue(s); | ||
} | ||
|
||
@Override | ||
public <X> X getScreenshotAs(OutputType<X> outputType) throws WebDriverException { | ||
WebElement el = getElement(); | ||
if (el == null) { | ||
return null; | ||
} | ||
return el.getScreenshotAs(outputType); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I seem to recall that using wildcard imports violates some style rules in Jenkins projects, I think @vivek pointed that out to me once. If you're using IDEA and search for "class count to use import with" in settings, you'll find an option. I set it to 100.