cyrjano / auquery Goto Github PK
View Code? Open in Web Editor NEWJQuery-Like Browser based automation based on Webdriver
JQuery-Like Browser based automation based on Webdriver
Following code does not work:
var lib = require('auQuery');
var wd = require('wd');
var assert = require('assert');
var Browser = lib.browser;
var AuQuery = lib.auQuery;
var webDriver = wd.remote();
var browser = new Browser(webDriver);
browser.drive(function($, browser){
browser.init({browserName:'chrome'});
browser.get('http://www.bing.com');
var searchBox = browser.elementById('sb_form_q');
searchBox.type('GoodData');
var searchButton = browser.elementById('sb_form_go');
console.log(searchButton.value);
browser.moveTo(searchButton, 0, 0);
browser.click();
}
, function(err, res){
if(err){
console.log(err);
}
});
The reason is that moveTo method is wrapped in the sync version only at the beginning during init. But it needs to know the element.value for successful moveTo operation.
When elementById response arrives the sync wrapper does not find moveTo in the object so it does not create appropriate closure and moveTo fails with:
17:11:14.098 INFO - Executing: [mousemove: [object Object] true] at URL: /session/d03286e2-8d4f-46df-b6bb-a89cd01b65c4/moveto)
17:11:14.098 WARN - Exception thrown
java.lang.NullPointerException
at org.openqa.selenium.remote.server.handler.interactions.MouseMoveToLocation.call(MouseMoveToLocation.java:51)
at org.openqa.selenium.remote.server.handler.interactions.MouseMoveToLocation.call(MouseMoveToLocation.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:169)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:680)
17:11:14.099 WARN - Exception: null
because it does not receive appropriate element id from auQuery.
Currently, I do not know how to fix this? How can we reach the moveTo after parsing the findElement' response?
I have added a fn.wait() method which calls browser.waitForElement() method to ensure it is already available.
Further I monkey patched the fn.init() method to ensure to call the .wait() method before construction of the $() instance.
I can see this .wait() called from within the .init() as an option that could be switched via an option to the browser.drive() method. Or simply having it there by default.
If this is something you would consider a good idea I would however appreciate help with integrating into the source code. Here is a gist of my patch code https://gist.github.com/opichals/5916347
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.