google / webdriver.dart Goto Github PK
View Code? Open in Web Editor NEWDart WebDriver client
Home Page: https://pub.dev/packages/webdriver
License: Apache License 2.0
Dart WebDriver client
Home Page: https://pub.dev/packages/webdriver
License: Apache License 2.0
I look up elements using
var elements = await driver.execute('return document.querySelector('someSelector')
.shadowRoot.querySelectorAll("otherSelector");', []).toList();
var cell = elements[3];
var text = await cell.text;
await cell.click();
The last line results in
StaleElementReferenceException (10): stale element reference: element is not attached to the page document
(Session info: chrome=44.0.2403.157)
(Driver info: chromedriver=2.19.346067 (6abd8652f8bc7a1d825962003ac88ec6a37a82f1),platform=Linux 4.1.0-1-amd64 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 16 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: '7705b8531113', ip: '172.17.1.91', os.name: 'Linux', os.arch: 'amd64', os.version: '4.1.0-1-amd64', java.version: '1.8.0_45-internal'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=/tmp/.com.google.Chrome.F3Ryk6}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=44.0.2403.157, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: f10548f173186772ad19f62227f175c5
package:webdriver WebElement.click
The same test worked previously with findElements(const By.cssSelector('selector /deep/ otherSelector'));
but this isn't supported in browsers except Chrome.
Should this work?
Could this be an issue in this package or is this an issue of the ChromeDriver?
I'm guessing we're blocked on migrating angular2
to test
, right?
There is some work around to achieve this: http://stackoverflow.com/questions/13832322/how-to-capture-the-screenshot-of-only-a-specific-element-using-selenium-webdrive/23087000#23087000.
It would be nice if there's a simple API to achieve it.
I'll help configure Travis for cron, etc
The W3C WebDriver spec is getting close to CR status, and some endpoints (notably GeckoDriver and EdgeDriver) will only support the new spec. There are some changes that will need to be made to this project to make it work as this transition is made, most notably:
responses no longer include a status field. Instead they include an error field with a text value if an error occurs.
The various low-level actions endpoints (e.g. keyboard and mouse actions) are no longer supported. Instead a single actions endpoint is defined that takes a message representing a sequence of keyboard, mouse, and touch screen actions.
https://github.com/google/webdriver.dart/blob/master/lib/src/target_locator.dart says:
/// Throws [NoAlertPresentException] if there is not currently an alert.
However,
https://github.com/google/webdriver.dart/blob/master/lib/src/exception.dart says:
case 27: // NoAlertOpenError
return new NoAlertOpenException(status, message);
Java WebDriver exception name is NoAlertPresentException.
http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/NoAlertPresentException.html
I prefer to use NoAlertPresentException, because it is also used in Java version. However, if you want to stick to use NoAlertOpenException, please fix the comment. Thanks!
In lib/io.dart:
Future<WebDriver> createDriver({Uri uri, Map<String, dynamic> desired})
consider renaming the desired
param to capabilities
.
For a nicer interface and better support consider using: https://github.com/google/dart-sync-webdriver
Probably no longer true?
couldn't find any "keyDown, keyUp" commands.
I'm using webdriver.dart to automate functional testing of a webpage with a back-end script written in GO. Upon submission of the form, the inputted fields get passed to a script implemented in a generation handler. This is done through an action like so:
<form id="fontfileinfo" action="/generate" method="POST" enctype="multipart/form-data">
Once this is complete, the page redirects to another page that displays the status and has its own handler.
However, webdriver keeps trying to navigate to /generate upon submission even though this is not an actual page or url that the user ever sees when done manually. It is simply used for back-end generation. Because of this, the test never reaches the /status page. I have tried waiting for the url to change, elements to become visible, and thread.sleep.
Are there any other options that I'm overlooking?
I haven't found a way to create a custom "WebDriver" class or extend WebDriver
.
I would like to have an extended WebDriver
class with additional methods (for example using common JS snippets with execute()
) but I have to copy a lot of code to make it work.
The main problems so far are _CommandProcessor
being private and WebElement
s private constructor. The next problem is probably _WebDriverBase
final url = 'http://localhost:${examplePubServePort}/testing/index.html';
// await driver.navigate.to(url);
await driver.get(url);
final WebElement someDiv =
await driver.findElement(const By.cssSelector('* /deep/ #some-div'));
// fails with PhantomJS (with driver.get()): InvalidElementStateException (12): {"errorMessage":"SyntaxError: DOM Exception 12"
// fails with Chrome (with driver.get()): NoSuchElementException (7): no such element
// succeeds with driver.navigate.to() with Chrome and PhantomJS
expect(title, equals('browser/webdriver test'));
expect(someDiv, isNotNull);
await someDiv.attributes['id']
// fails with PhantomJs with driver.navigate.to()
// > StaleElementReferenceException (10): {"errorMessage":"Element does not exist in cache"
// succeeds with Chrome with driver.navigate.to()
driver.get
and WebElement.attributes[]
call CommandProcessor.get()
while driver.navigate.to()
calls CommandProcessor.post()
I think driver.findElement()
fails because driver.get()
doesn't do anything and times out.
In Chrome I see the URL and the page load when driver.navigate.to()
is used. With driver.get
the URL is just data:,
and nothing else happens.
Am I doing something wrong or is this a bug?
driver.get()
and driver.navigate.to()
are supposed to do the same thing, aren't they?
Dart VM version: 1.11.0-edge.45304 (Mon Apr 20 18:15:39 2015) on "linux_x64"
async captureScreenshot is about ~40x slower than the synchronous version (taking a 800x600 screenshot takes ~20s vs 500ms). This is because captureScreenshot returns a Stream containing the bytes making up the png screenshot and we have to call Stream.toList() to write the screenshot to a file. Compared to returning the list directly, it is 5000x slower in a test. (100x slower because of wrapping it in a Stream and async_/yield_ and 50x slower because of unittest & stack_trace).
The suggested solution is to add a captureScreenshotAsList method back that returns a simple List.
See also captureScreenshotAsBase64 #112
I failed miserable trying to figure out how to pass something like 'reader.parse-on-load.enabled': false
to Firefox using desired
. There are examples how to use Java classes (like https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/firefox/FirefoxProfile.java), but I wasn't yet able to figure out how to do this with webdriver.dart.
Any hint would be appreciated.
webdriver.dart/lib/support/forwarder.dart
Line 137 in 89d68ec
cc @BlackHC
On my mac. W/ latest release.
It looks like this has been updated with fixes for Dart 2 (e.g. SCREAMING CAPS CONSTANT removal) but not published. Consider publishing?
@DrMarcII, any objections if I set up a CI (using travis) for webdriver?
The supplied code stops at instantiating the WebDriver instance. It should go further. Or direct the reader to a cohesive example-usage repo.
WebDriver create default
Test failed: Caught 13 Unknown: Connection refused
An unknown server-side error occurred while processing the command.
package:webdriver/src/web_driver.dart 59:15 WebDriver.createDriver.<fn>.<fn>
dart:async _createTimer.<fn>
timer_impl.dart 96:21 _Timer._createTimerHandler._handleTimeout
timer_impl.dart 112:23 _Timer._createTimerHandler.<fn>
dart:isolate _ReceivePortImpl._handleMessage
like http://watirwebdriver.com/sending-special-keys/ or http://stackoverflow.com/questions/3249583/selenium-webdriver-i-want-to-overwrite-value-in-field-instead-of-appending-to-i
For example I want to send Shift+Pos1
with notes about what changed from one release to the next
Problem: After updating from Selenium v3.6.0 to Selenium v3.8.1, the capabilities don't appear to work as expected. For example, downloads are no longer going to/shared/exports
using the snippet below.
Map capabilities = {
'platform': 'LINUX',
'browserName': 'chrome',
'chromeOptions': {
'args': ['window-size=1280,600', 'disable-infobars', 'enable-precise-memory-info'],
'prefs': {
'download': {'default_directory': '/shared/exports/', 'prompt_for_download': 'false'}
}
}
}
driver = await io.createDriver(desired: capabilities, uri: seleniumUri);
I assume the web driver implementation will need to support MutableCapabilities and ImmutableCapabilities?
I hope i can specify the chrome headless argument.
Thank you.
Looks like there is no any possibility to perfrom PUT (and any others HEAD, OPTIONS) http requests.
Exposed generic method "request( String method, Uri uri, [Map params] )" solved the issue completely.
00:53 +25 -1: WebDriver create default
Test failed: Caught 13 Unknown: Connection refused
An unknown server-side error occurred while processing the command.
package:webdriver/src/web_driver.dart 59:15 WebDriver.createDriver.<fn>.<fn>
dart:async _createTimer.<fn>
timer_impl.dart 96:21 _Timer._createTimerHandler._handleTimeout
timer_impl.dart 112:23 _Timer._createTimerHandler.<fn>
dart:isolate _ReceivePortImpl._handleMessage
02:10 +62 -2: Window location
Expected: <20>
Actual: <22>
package:unittest/src/expect.dart 75:29 expect
test/src/window_test.dart 35:21 WindowTest.main.<fn>.<fn>.<fn>
dart:async _createTimer.<fn>
timer_impl.dart 96:21 _Timer._createTimerHandler._handleTimeout
timer_impl.dart 112:23 _Timer._createTimerHandler.<fn>
dart:isolate _ReceivePortImpl._handleMessage
02:12 +62 -3: Window maximize
Expected: <0>
Actual: <26>
package:unittest/src/expect.dart 75:29 expect
test/src/window_test.dart 46:23 WindowTest.main.<fn>.<fn>.<fn>
dart:async _createTimer.<fn>
timer_impl.dart 96:21 _Timer._createTimerHandler._handleTimeout
timer_impl.dart 112:23 _Timer._createTimerHandler.<fn>
dart:isolate _ReceivePortImpl._handleMessage
02:13 +62 -3: Some tests failed.
62 PASSED, 2 FAILED, 1 ERRORS
There should be an example of getting webdriver set up with a project - probably in the readme.
Just a place-holder
webdriver.dart/lib/src/async/web_driver.dart
Lines 152 to 160 in 33ac552
These are the current failures I see when run with chromedriver on macos:
00:23 +14 -1: Navigation forward/back
Expected: contains 'Google'
Actual: ''
package:unittest/src/simple_configuration.dart 15:28 _ExpectFailureHandler.fail
package:matcher/src/expect.dart 121:9 DefaultFailureHandler.failMatch
package:matcher/src/expect.dart 95:29 expect
test/src/navigation_test.dart 26:19 main.<fn>.<fn>.<fn>
dart:isolate _RawReceivePortImpl._handleMessage
00:30 +16 -2: Cookies add complex cookie
Expected: true
Actual: <false>
package:unittest/src/simple_configuration.dart 15:28 _ExpectFailureHandler.fail
package:matcher/src/expect.dart 121:9 DefaultFailureHandler.failMatch
package:matcher/src/expect.dart 95:29 expect
test/src/options_test.dart 55:19 main.<fn>.<fn>.<fn>
dart:isolate _RawReceivePortImpl._handleMessage
01:41 +61 -3: Window location
Expected: <20>
Actual: <22>
package:unittest/src/simple_configuration.dart 15:28 _ExpectFailureHandler.fail
package:matcher/src/expect.dart 121:9 DefaultFailureHandler.failMatch
package:matcher/src/expect.dart 95:29 expect
test/src/window_test.dart 38:19 main.<fn>.<fn>.<fn>
dart:isolate _RawReceivePortImpl._handleMessage
01:42 +61 -4: Window maximize
Expected: <0>
Actual: <22>
package:unittest/src/simple_configuration.dart 15:28 _ExpectFailureHandler.fail
package:matcher/src/expect.dart 121:9 DefaultFailureHandler.failMatch
package:matcher/src/expect.dart 95:29 expect
test/src/window_test.dart 49:21 main.<fn>.<fn>.<fn>
dart:isolate _RawReceivePortImpl._handleMessage
01:42 +61 -4: Some tests failed.
61 PASSED, 4 FAILED, 0 ERRORS
webdriver.dart/lib/src/async/web_driver.dart
Lines 41 to 42 in 33ac552
Good to do before releasing a new version...
Likely platform differences?
PASS: Window size
FAIL: Window location
Expected: <20>
Actual: <22>
package:unittest/src/expect.dart 75:29 expect
test/src/window_test.dart 38:19 main.<fn>.<fn>.<fn>
dart:async _createTimer.<fn>
timer_impl.dart 96:21 _Timer._createTimerHandler._handleTimeout
timer_impl.dart 112:23 _Timer._createTimerHandler.<fn>
dart:isolate _ReceivePortImpl._handleMessage
FAIL: Window maximize
Expected: <0>
Actual: <26>
package:unittest/src/expect.dart 75:29 expect
test/src/window_test.dart 49:21 main.<fn>.<fn>.<fn>
dart:async _createTimer.<fn>
timer_impl.dart 96:21 _Timer._createTimerHandler._handleTimeout
timer_impl.dart 112:23 _Timer._createTimerHandler.<fn>
dart:isolate _ReceivePortImpl._handleMessage
1 PASSED, 2 FAILED, 0 ERRORS
https://github.com/google/webdriver.dart/blob/master/lib/src/web_element.dart#L36
and similar methods of WebElement
don't seem to be related to the element they are called on.
WebElement.click()
is forwarded to WebDriver._post('click')
.
I would expect it to move the mouse to the element or select the element before the click
is invoked.
I tried
WebElement startResizeHandle = await driver.findElement(const By.cssSelector('#handle'));
expect(startResizeHandle, isNotNull);
await driver.mouse.moveTo(element: startResizeHandle);
await driver.mouse.down(Mouse.left);
await driver.mouse.moveTo(xOffset: 50, yOffset: 0);
await driver.mouse.up(Mouse.left);
According to the highlighting the mouse seems to move correctly but no drag'n drop is happening. Should this work this way?
Perhaps rename these files if they are not meant to be run directly?
00:00 +0 -1: test/src/alert_test.dart: load error
Failed to load "test/src/alert_test.dart": No top-level main() function defined.
00:00 +0 -2: test/src/keyboard_test.dart: load error
Failed to load "test/src/keyboard_test.dart": No top-level main() function defined.
00:00 +1 -3: test/src/logs_test.dart: load error
Failed to load "test/src/logs_test.dart": No top-level main() function defined.
00:00 +1 -4: test/src/mouse_test.dart: load error
Failed to load "test/src/mouse_test.dart": No top-level main() function defined.
00:00 +2 -5: test/src/navigation_test.dart: load error
Failed to load "test/src/navigation_test.dart": No top-level main() function defined.
00:00 +2 -6: test/src/options_test.dart: load error
Failed to load "test/src/options_test.dart": No top-level main() function defined.
00:00 +2 -7: test/src/target_locator_test.dart: load error
Failed to load "test/src/target_locator_test.dart": No top-level main() function defined.
00:00 +2 -8: test/src/web_driver_test.dart: load error
Failed to load "test/src/web_driver_test.dart": No top-level main() function defined.
00:00 +2 -9: test/src/web_element_test.dart: load error
Failed to load "test/src/web_element_test.dart": No top-level main() function defined.
00:00 +2 -10: test/src/window_test.dart: load error
Failed to load "test/src/window_test.dart": No top-level main() function defined.
I'm having trouble getting this driver up and running with saucelabs. I'm using the latest non-dev release, 0.9.1
. What I'm seeing is that the result from the commandProcessor.post
call in WebDriver.createDriver()
is a string, not a valid json encoded map:
"OK,ondemand alive"
Here's the code I'm using:
import 'dart:io';
import 'package:webdriver/webdriver.dart';
main(List args) async {
if (args.length < 2) {
print('usage: sauce <username> <accesskey>');
exit(1);
}
String username = args[0];
String accessKey = args[1];
Map caps = Capabilities.firefox;
caps[Capabilities.version] = "17";
//capabilities.setCapability("platform", Platform.XP);
String uri = 'http://${username}:${accessKey}@ondemand.saucelabs.com:80/wd/hub';
print('Connecting to ${uri}...');
WebDriver driver = await WebDriver.createDriver(
uri: Uri.parse(uri),
desiredCapabilities: caps);
await driver.get("http://www.amazon.com/");
print(await driver.title);
driver.close();
}
The code fails when the createDriver call tries to access the sessionId
from the http post response, when the value is a string and not a map.
It explains condition
, matcher
, timeout
, but not interval
.
Line 18 in 3f71e3b
Would be great to get rid of this!
For consuming libraries to obey strong mode, we will need to enable the commented-out generics in the waitFor definition here. This would require bumping the SDK restriction to 1.21+. Is this a change you would be open to accepting?
Sometimes it is useful to remove the focus from any element on the page.
Webdriver infrastructure should have a support for "blur()" method.
In the 0.9.0 version of the package, we import:
import 'package:webdriver/io.dart';
in the new (unpublished) version, we import:
import 'package:webdriver/io.dart';
I think webdriver_io.dart
would be a more semantic import.
Hi,
I'm writing a test where I want to scroll an element (to test some infinite-scroll logic), but it doesn't look like there's any built-in way of doing that. The Mouse class doesn't seem to expose anything; there's a scroll method in the Touch class, but using that fails with "Underlying driver does not implement advanced user interactions yet.".
I can work around it by modifying the element's scrollTop manually, but it'd be nice to have something that'd trigger all the proper mouse/touch events.
We are not able to upload files on file input elements on remote services like Sauce Labs.
This is normally done by sending keys to the element. The Dart client doesn't appear to upload the file to remote services first like the others do. Python Example
If the keys being sent to an element are found to be a path that points to a local file, the file is upload to the WebDriver with a POST request to /session/$sessionId/file
, and the response to that request is what's actually sent to the element.
The sync webdriver provides both captureScreenshot and captureScreenshotAsBase64.
Atm:
/// Take a screenshot of the current page as PNG.
Stream<int> captureScreenshot() async* {
var encoded = await getRequest('screenshot');
yield* new Stream.fromIterable(CryptoUtils.base64StringToBytes(encoded));
}
This could be split up again into two methods.
I'm looking to use the FutureOr<T>
version of waitFor
, which was added in version 1.2.3 of this package: https://github.com/google/webdriver.dart/blob/v1.2.3/lib/support/async.dart#L28
However, that change doesn't seem to be present in the Pub archive of 1.2.3: https://storage.googleapis.com/pub-packages/packages/webdriver-1.2.3.tar.gz
While looking into this, I also noticed that 1.2.4 was tagged but not published (see published versions here: https://pub.dartlang.org/packages/webdriver#pub-pkg-tab-versions).
You can add a site URL – great to let folks see what's published
Why was this deprecated in favor of https://github.com/google/dart-sync-webdriver? It seems like dart-sync-webdriver
's use of a native lib put pretty heavy restrictions on how it can be used and how easy it is to get it set up.
@DrMarcII (and others)
I am trying to use webdriver.dart and i found this error
Unhandled exception:
InvalidRequestException (400): Bad Request
#0 processJsonWireResponse (package:webdriver/src/sync/json_wire_spec/response_processor.dart:33:5)
#1 SyncHttpCommandProcessor.post (package:webdriver/src/sync/command_processor.dart:57:12)
#2 createDriver (package:webdriver/sync_core.dart:65:34)
#3 createDriver (package:webdriver/sync_io.dart:32:5)
#4 main (file:///home/sclee/Context/___/___/bin/main.dart:138:22)
both w3c spec and json wire shows similar behavior.
Thank you.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.