Skip to content

Commit

Permalink
integrated the recent development wholesale for the PR, commenging th…
Browse files Browse the repository at this point in the history
…e failing tests for TRAVIS, pending investigation
  • Loading branch information
sergueik committed Dec 4, 2016
1 parent 69cc214 commit 526f937
Show file tree
Hide file tree
Showing 13 changed files with 762 additions and 128 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
language: java
script: mvn test integration-test
addons:
firefox: "34.0"
firefox: "40.0"
before_install:
- "export DISPLAY=:99.0"
- "export TRAVIS=true"
- "sh -e /etc/init.d/xvfb start"
after_script:
- "sh -e /etc/init.d/xvfb stop"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Being a JS testing tool, [Angular Protractor](https://github.com/angular/protra
On the other hand Protractor offers some [locator strategies](https://github.com/angular/protractor/blob/master/lib/clientsidescripts.js) that take advantage of Angular's features to testers - this project tries to keep these available.


Currently supported Antular Proractor methods:
Currently supported Angular Proractor methods:
```
binding.js
buttonText.js
Expand Down
24 changes: 24 additions & 0 deletions src/main/resources/allowAnimations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* invoke allowAnimations on Angular elements
*
* arguments[0] {Element} The scope of the search.
* arguments[1] {Bool} The animations setting.
*/

var elemetnt = arguments[0] || document;
var state = arguments[1];
try {
return (function(element, state) {
var ngElement = angular.element(element);
if (ngElement.allowAnimations) {
// AngularDart: $testability API.
return ngElement.allowAnimations(state);
} else {
// AngularJS
var enabledFn = ngElement.injector().get('$animate').enabled;
return (state == null) ? enabledFn() : enabledFn(state);
}
}).apply(this, arguments);
} catch (e) {
throw (e instanceof Error) ? e : new Error(e);
}
4 changes: 2 additions & 2 deletions src/main/resources/partialButtonText.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Find buttons by textual content.
* Find buttons by textual content fragment.
*
* arguments[0] {Element} The scope of the search.
* arguments[1] {string} The partial text to match.
Expand All @@ -26,4 +26,4 @@ var findByPartialButtonText = function(searchText, using) {
};
var using = arguments[0] || document;
var searchText = arguments[1];
return findByPartialButtonText(searchText, using);
return findByPartialButtonText(searchText, using);
47 changes: 33 additions & 14 deletions src/test/java/com/jprotractor/integration/CommonFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.IOException;

import java.util.Map;
import java.util.concurrent.TimeUnit;

Expand All @@ -26,8 +24,10 @@
import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

Expand Down Expand Up @@ -63,15 +63,15 @@ public static WebDriver getSeleniumDriver() throws IOException {
// For Vagrant box browser testing have localhost port 4444 forwarded to
// the hub 4444

DesiredCapabilities capabilities = new DesiredCapabilities("chrome", "",
DesiredCapabilities capabilities = new DesiredCapabilities("firefox", "",
Platform.ANY);
// seleniumDriver = new FirefoxDriver(capabilities);
// FirefoxProfile profile = new ProfilesIni().getProfile("default");
// profile.setEnableNativeEvents(false);
// capabilities.setCapability("firefox_profile", profile);

seleniumDriver = new RemoteWebDriver(new URL(
"http://127.0.0.1:4444/wd/hub"), capabilities);
seleniumDriver = new RemoteWebDriver(
new URL("http://127.0.0.1:4444/wd/hub"), capabilities);
return seleniumDriver;
} else {
DesiredCapabilities capabilities = new DesiredCapabilities("phantomjs",
Expand Down Expand Up @@ -127,15 +127,19 @@ public static void setHighlightTimeout(long value) {
highlightInterval = value;
}

public static void highlight(WebElement element) throws InterruptedException {
int flexibleWait = 5;
long pollingInterval = 500;
WebDriverWait wait = new WebDriverWait(seleniumDriver, flexibleWait);
wait.pollingEvery(pollingInterval, TimeUnit.MILLISECONDS);
wait.until(ExpectedConditions.visibilityOf(element));
executeScript("arguments[0].style.border='3px solid yellow'", element);
Thread.sleep(highlightInterval);
executeScript("arguments[0].style.border=''", element);
public static void highlight(WebElement element) {
if (wait == null) {
wait = new WebDriverWait(seleniumDriver, flexibleWait);
wait.pollingEvery(pollingInterval, TimeUnit.MILLISECONDS);
}
try {
wait.until(ExpectedConditions.visibilityOf(element));
executeScript("arguments[0].style.border='3px solid yellow'", element);
Thread.sleep(highlightInterval);
executeScript("arguments[0].style.border=''", element);
} catch (InterruptedException e) {
// System.err.println("Ignored: " + e.toString());
}
}

public static Object executeScript(String script, Object... args) {
Expand All @@ -146,4 +150,19 @@ public static Object executeScript(String script, Object... args) {
throw new RuntimeException("Script execution failed.");
}
}

// custom wait e.g. while Login light box is visible
public static void waitWhileElementIsVisible(By locator) {
final By _locator = locator;
new WebDriverWait(seleniumDriver, flexibleWait)
.pollingEvery(pollingInterval, TimeUnit.SECONDS)
.until(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver o) {
System.err.println("Size: " + o.findElements(_locator).size());
return (o.findElements(_locator).size() == 0);
}
});

}
}
Loading

0 comments on commit 526f937

Please sign in to comment.