Skip to content
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

upgraded to Selenium 4.x (4.5.3) #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.jprotractor</groupId>
<artifactId>jprotractor</artifactId>
<version>1.1-SNAPSHOT</version>
<version>1.1.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>jprotractor</name>
<url/>
Expand All @@ -26,7 +26,7 @@
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<java.version>1.7</java.version>
<selenium.version>2.47.0</selenium.version>
<selenium.version>4.5.3</selenium.version>
<selenium-firefox-driver.version>2.47.0</selenium-firefox-driver.version>
<junit.version>4.12</junit.version>
<phantomjsdriver.version>1.2.1</phantomjsdriver.version>
Expand Down Expand Up @@ -56,6 +56,11 @@
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jprotractor/JavaScriptBy.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.internal.WrapsDriver;
import org.openqa.selenium.WrapsDriver;

/**
* Javascript WebElement searcher.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jprotractor/NgWebDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.internal.WrapsDriver;
import org.openqa.selenium.WrapsDriver;

/**
* Angular WebDriver Implementation.
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/jprotractor/NgWebElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.Point;
import org.openqa.selenium.Rectangle;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.internal.WrapsElement;
import org.openqa.selenium.WrapsElement;

/**
* Angular Web Element.
Expand Down Expand Up @@ -145,4 +147,16 @@ public void submit() {
this.driver.waitForAngular();
this.element.submit();
}
// http://stackoverflow.com/questions/39310090/selenium-upgrade-error
@Override
public Rectangle getRect() {
return this.element.getRect();
}

@Override
public <T> T getScreenshotAs(OutputType<T> target) {
return this.element.getScreenshotAs(target);

}

}
46 changes: 23 additions & 23 deletions src/main/resources/allowAnimations.js
Original file line number Diff line number Diff line change
@@ -1,24 +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);
/**
* 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);
}
100 changes: 50 additions & 50 deletions src/main/resources/binding.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
/**
* Find a list of elements in the page by their angular binding.
*
* arguments[0] {Element} The scope of the search.
* arguments[1] {string} The binding, e.g. {{cat.name}}.
* arguments[2] {boolean} Whether the binding needs to be matched exactly.
* arguments[3] {string} The selector to use for the root app element.
*
* @return {Array.WebElement} The elements containing the binding.
*/
var findBindings = function(binding, exactMatch, using, rootSelector) {
var root = document.querySelector(rootSelector || 'body');
using = using || document;
if (angular.getTestability) {
return angular.getTestability(root).
findBindings(using, binding, exactMatch);
}
var bindings = using.getElementsByClassName('ng-binding');
var matches = [];
for (var i = 0; i < bindings.length; ++i) {
var dataBinding = angular.element(bindings[i]).data('$binding');
if (dataBinding) {
var bindingName = dataBinding.exp || dataBinding[0].exp || dataBinding;
if (exactMatch) {
var matcher = new RegExp('({|\\s|^|\\|)' +
/* See http://stackoverflow.com/q/3561711 */
binding.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&') +
'(}|\\s|$|\\|)');
if (matcher.test(bindingName)) {
matches.push(bindings[i]);
}
} else {
if (bindingName.indexOf(binding) != -1) {
matches.push(bindings[i]);
}
}
}
}
return matches; /* Return the whole array for webdriver.findElements. */
};

var using = arguments[0] || document;
var binding = arguments[1];
var rootSelector = arguments[2];

var exactMatch = arguments[3];
if (typeof exactMatch === 'undefined') {
exactMatch = true;
}

/**
* Find a list of elements in the page by their angular binding.
*
* arguments[0] {Element} The scope of the search.
* arguments[1] {string} The binding, e.g. {{cat.name}}.
* arguments[2] {boolean} Whether the binding needs to be matched exactly.
* arguments[3] {string} The selector to use for the root app element.
*
* @return {Array.WebElement} The elements containing the binding.
*/
var findBindings = function(binding, exactMatch, using, rootSelector) {
var root = document.querySelector(rootSelector || 'body');
using = using || document;
if (angular.getTestability) {
return angular.getTestability(root).
findBindings(using, binding, exactMatch);
}
var bindings = using.getElementsByClassName('ng-binding');
var matches = [];
for (var i = 0; i < bindings.length; ++i) {
var dataBinding = angular.element(bindings[i]).data('$binding');
if (dataBinding) {
var bindingName = dataBinding.exp || dataBinding[0].exp || dataBinding;
if (exactMatch) {
var matcher = new RegExp('({|\\s|^|\\|)' +
/* See http://stackoverflow.com/q/3561711 */
binding.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&') +
'(}|\\s|$|\\|)');
if (matcher.test(bindingName)) {
matches.push(bindings[i]);
}
} else {
if (bindingName.indexOf(binding) != -1) {
matches.push(bindings[i]);
}
}
}
}
return matches; /* Return the whole array for webdriver.findElements. */
};
var using = arguments[0] || document;
var binding = arguments[1];
var rootSelector = arguments[2];
var exactMatch = arguments[3];
if (typeof exactMatch === 'undefined') {
exactMatch = true;
}
return findBindings(binding, exactMatch, using, rootSelector);
56 changes: 28 additions & 28 deletions src/main/resources/buttonText.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
/**
* Find buttons by textual content.
*
* arguments[0] {Element} The scope of the search.
* arguments[1] {string} The exact text to match.
*
* @return {Array.Element} The matching elements.
*/
var findByButtonText = function(searchText, using) {
using = using || document;
var elements = using.querySelectorAll('button, input[type="button"], input[type="submit"]');
var matches = [];
for (var i = 0; i < elements.length; ++i) {
var element = elements[i];
var elementText;
if (element.tagName.toLowerCase() == 'button') {
elementText = element.textContent || element.innerText || '';
} else {
elementText = element.value;
}
if (elementText.trim() === searchText) {
matches.push(element);
}
}
return matches;
};
var using = arguments[0] || document;
var searchText = arguments[1];
/**
* Find buttons by textual content.
*
* arguments[0] {Element} The scope of the search.
* arguments[1] {string} The exact text to match.
*
* @return {Array.Element} The matching elements.
*/
var findByButtonText = function(searchText, using) {
using = using || document;
var elements = using.querySelectorAll('button, input[type="button"], input[type="submit"]');
var matches = [];
for (var i = 0; i < elements.length; ++i) {
var element = elements[i];
var elementText;
if (element.tagName.toLowerCase() == 'button') {
elementText = element.textContent || element.innerText || '';
} else {
elementText = element.value;
}
if (elementText.trim() === searchText) {
matches.push(element);
}
}
return matches;
};
var using = arguments[0] || document;
var searchText = arguments[1];
return findByButtonText(searchText, using);
20 changes: 10 additions & 10 deletions src/main/resources/evaluate.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Evaluate an Angular expression in the context of a given element.
*
* arguments[0] {Element} The element in whose scope to evaluate.
* arguments[1] {string} The expression to evaluate.
*
* @return {?Object} The result of the evaluation.
*/
var element = arguments[0];
var expression = arguments[1];
/**
* Evaluate an Angular expression in the context of a given element.
*
* arguments[0] {Element} The element in whose scope to evaluate.
* arguments[1] {string} The expression to evaluate.
*
* @return {?Object} The result of the evaluation.
*/
var element = arguments[0];
var expression = arguments[1];
return angular.element(element).scope().$eval(expression);
12 changes: 6 additions & 6 deletions src/main/resources/getLocationAbsUrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Return the current url using $location.absUrl().
*
* arguments[0] {string} The selector housing an ng-app
*/
var el = document.querySelector(arguments[0]);
/**
* Return the current url using $location.absUrl().
*
* arguments[0] {string} The selector housing an ng-app
*/
var el = document.querySelector(arguments[0]);
return angular.element(el).injector().get('$location').absUrl();
54 changes: 27 additions & 27 deletions src/main/resources/model.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
/**
* Find elements by model name.
*
* arguments[0] {Element} The scope of the search.
* arguments[1] {string} The model name.
*
* @return {Array.WebElement} The matching input elements.
*/
var findByModel = function(model, using, rootSelector) {
var root = document.querySelector(rootSelector || 'body');
using = using || '[ng-app]';
if (angular.getTestability) {
return angular.getTestability(root).
findModels(using, model, true);
}
var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
for (var p = 0; p < prefixes.length; ++p) {
var selector = '[' + prefixes[p] + 'model="' + model + '"]';
var elements = using.querySelectorAll(selector);
if (elements.length) {
return elements;
}
}
};
var using = arguments[0] || document;
var model = arguments[1];
var rootSelector = arguments[2];
/**
* Find elements by model name.
*
* arguments[0] {Element} The scope of the search.
* arguments[1] {string} The model name.
*
* @return {Array.WebElement} The matching input elements.
*/
var findByModel = function(model, using, rootSelector) {
var root = document.querySelector(rootSelector || 'body');
using = using || '[ng-app]';
if (angular.getTestability) {
return angular.getTestability(root).
findModels(using, model, true);
}
var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
for (var p = 0; p < prefixes.length; ++p) {
var selector = '[' + prefixes[p] + 'model="' + model + '"]';
var elements = using.querySelectorAll(selector);
if (elements.length) {
return elements;
}
}
};
var using = arguments[0] || document;
var model = arguments[1];
var rootSelector = arguments[2];
return findByModel(model, using, rootSelector);
Loading