How WebDriver Actions works - javascript

I am interested in mechanism of WebDriver actions.
For example
var actions = new Actions(driver);
var action = actions.MoveToElement(element).Build();
action.Perform();
How method MoveToElement() works? Is it a wrapper on javascript?
If yes, is it possible to get this javascript code?

So - I was actually curious about the mechanics myself, so I took a look through the selenium source, and my determination is that - no. It does not use javascript. It uses Java's ability to read / move the mouse positions / keyboard drivers / etc, and then when you call perform(), it has a queue of Actions that it will then perform.

moveToElement is implemented based on coordinates.
following is the code for moveToElement is the following
public Actions moveToElement(WebElement toElement) {
this.action.addAction(new MoveMouseAction(this.mouse,
(Locatable) toElement));
return this;
}
public abstract interface Locatable {
public abstract Coordinates getCoordinates();
}
public class MoveMouseAction extends MouseAction implements Action {
public MoveMouseAction(Mouse mouse, Locatable locationProvider) {
super(mouse, locationProvider);
if (locationProvider == null)
throw new IllegalArgumentException(
"Must provide a location for a move action.");
}
public void perform() {
this.mouse.mouseMove(getActionLocation());
}
}

No javascript. It uses coordinates to move mouse there. Check this link.

Related

Looking for Reference Guide with sample for JDT eclipse Content assist

I am trying to develop a JDT content assist for a custom framework, I am actually writing a plugin for JSDT but even if I can get good reference for JDT, I can relate to JSDT, so far I am able to get my list of type ahead content but not able to filter it out based on user entered text for e.g.
I have 1 object at root named "Object" so if the user presses Control + Space on an empty line he will get the only object in assist text if he does Control + Space after typing "Object." it should show an instance of variables inside "Object" it could be, Object.Name, Object.Feature. So far no matter what I have typed I am getting all the list and I don't know how to filter it out then put helper texts on Assists.
My code is as follows
public class CustomCompletionProposalComputer implements ICodeAssist,IJavaCompletionProposalComputer,
IJavadocCompletionProcessor,IQuickAssistProcessor,IQueryParticipant {
#Override
public void sessionStarted() {
}
#Override
public List computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
ArrayList<CompletionProposal> proposals = new ArrayList<CompletionProposal>();
proposals.add(new CompletionProposal("Facade", context.getInvocationOffset(), 0, "Object".length()));
proposals.add(new CompletionProposal("vivek", context.getInvocationOffset(), 0, "Name".length()));
......
return proposals;
}
#Override
public List computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) {
return null;
}
#Override
public String getErrorMessage() {
return null;
}
#Override
public void sessionEnded() {
}
I am not able to find any decent example around it, API doc is not much help, any reference or help is highly appreciated.
Have located decent resource around this. Link to Grail-IDE project

ActiveX / COM object event handler for Hardware Device

I am creating an ActiveX control for a hardware (card swiper) device. I have understanding of ActiveX development and working, but I am little stuck with my specific scenario. Device SKD (dll files) have method to activate swiper/chip reader in order to be in listening state. Assume the following:
SDK sdk = new SDK();
sdk.RegisterCallback(GlobalCallback);
sdk.ActivateSwiper();
public void GlobalCallback(op, .., ..)
{
switch(op) {
case Swiped:
readCardData();
break;
case TransactionData:
readData();
break;
//. . . .
}
Above code is just for example. SDK has a global callback method for any event triggered through device (eg, card swiped, ICC seated, etc). If the SDK is being used in WPF/WinForm app, it is super easy get it working. But in my case, I must need to handle the raised event in javascript on my web page.
So, I have exposed a method in ActiveX to turn on the device, which works perfect:
[Guid("4794D615-BE51-4a1e-B1BA-453F6E9337C4")]
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(IComEvents))]
public class MyComObject : IComObject
{
[ComVisible(true)]
public string ActivateDevice()
{
SDK sdk = new SDK();
sdk.RegisterCallback(GlobalCallback);
string resultCode = sdk.ActivateSwiper();
return resultCode;
}
//. . <other code> . . .
}
and use it in webpage as:
<object id="myComComponent" name="myComComponent" classid="clsid:4794D615-BE51-4a1e-B1BA-453F6E9337C4"></object>
<script language="javascript" type="text/javascript">
var returnCode = myComComponent.ActivateDevice(); //or by creating ActiveXObject
</script
I have also got the idea about how to handle events using ActiveX on webpage. I learnt it from HERE. But the event is handled by calling the exposed method to raise event. And in my case, when card is swiped, the call will go to GlobalCallback() method.
Questioins:
Is there any workaround, I can implement handler in my scenario, to make it usable on javascript?
I am thinking of something like PropertyChanged event, bound to a string property, which holds the derived card data. and the handlers returns this property value. Is there any workaround possible like this? I need little help with this.
I am thinking this as:
public static string CARD_DATA;
public void GlobalCallback(op, .., ..)
{
switch(op) {
case Swiped:
CARD_DATA = readCardData();
//and CARD_DATA is bound to property-changed event, and its handler returns its value.
//other code
Is this even possible? If so, What to be exposed? and How to use it? as this property will be changed internally, when card is swiped, and case Swiped: is executed. Is there any workaround?
Other Info:
Web App is MVC 4 famework based
Device is The Augusta (IDTech). (they don't have actieX/plugin for web)

Android Javascript Engine; Need to replace WebView with Rhino, J2V8, etc

We are trying to replace our webview and html with a layout file and a javascript engine of some sort. There is a TON of javascript that must be called and we have a rather large JavaScriptInterface that will need to be accessable by the JS engine. I have been trying out Rhino and J2V8 but cannot figure out a way to give javascript access to a full class of methods or an annotation that works similarly to how you annotate methods for WebView.
If anyone has any insight, it would be much appreciated!
Thanks,
Jon
AFAIK there is no "out-of-the-box" solution for this for JSV8.
But have a look at following example:
public class V8ConsoleBridge implements JavaVoidCallback {
#Override
public void invoke(V8Object receiver, V8Array parameters) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < parameters.length(); ++i) {
if (i > 0) {
sb.append(", ");
}
Object object = parameters.get(i);
if (object instanceof V8Object) {
V8Object v8Object = (V8Object) object;
sb.append(v8Object.toString());
v8Object.release();
} else {
sb.append(object);
}
}
Log.i("goebl-v8", sb.toString());
}
public static void register(V8 v8) {
V8ConsoleBridge console = new V8ConsoleBridge();
V8Object v8Console = new V8Object(v8);
v8.add("console", v8Console);
v8Console.registerJavaMethod(console, "debug");
v8Console.registerJavaMethod(console, "log");
v8Console.registerJavaMethod(console, "info");
v8Console.registerJavaMethod(console, "warn");
v8Console.registerJavaMethod(console, "error");
v8Console.release();
}
}
This is a hardcoded bridge for a JS console object to access Android logging system.
You could write generic code to
scan a class you want to expose in JavaScript, much like JavaScript-Interface for WebView, even with annotations like #JavascriptInterface to only include certain members
write generic code for the invoke which actually invokes members of the receiver class by using Java reflection.
Of course it would be great if J2V8 had this useful code, because it might be used by many projects. When you have a solid solution, create a pull request so I can use it too :-)
If you don't mind wading deep in source code, you might find it useful to check out NativeScript. They provide a generic way to access all Java classes known at compile time in JavaScript, which is internally done via reflection. Well, I've heard that they do it this way, I actually didn't read the source code of NativeScript. In NativeScript, you don't have to create bridges, it's done magically by the build- and runtime-system. Maybe the source inspires you to port the ideas to J2V8.

Highlight selenium clicks using AOP

I am trying to plug in js element highlighting to selenium framework. I have this code:
#Aspect
public class HighlightAspect {
#Pointcut("execution(* *.click())")
private void allClickMethods(){}
#Before("allClickMethods()")
public void proxyClick(ProceedingJoinPoint joinPoint){
WebElement element = (WebElement)joinPoint.getTarget();
highlight(element, "green");
}
private void highlight(WebElement element, String color) {
Browser.getBrowser().executeScript("arguments[0].style.backgroundColor = '"+color+"'", element);
}
}
I initialize spring context in 'main' class like:
private static ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("spring_config.xml");
And my src/main/resources/spring_config.xml looks like:
<aop:aspectj-autoproxy />
...
<bean
id="highlightAspect"
class="com.<my_name_space>.HighlightAspect">
</bean>
...
I don't receive any exceptions from JVM, but when I add a logger to proxyClick I see this method didn't happen to be executed.
Please, help me to make it work.
As far as I know,
ProceedingJoinPoint can't be used with #Before, it's only available with #Advice
Even in #Advice, as soon as you initiate the advice to proceed (i.e. click happens), there is NO guarantee that the element will be present in the DOM.

passing parameters to running silverlight application

The scenario is I have a list of items in HTML; when I click on an item I use JS to dynamically create the HTML to load a silverlight app passing in the specific item # (using initParams); and my silverlight app visualizes this in a nice way. I do this on the same page rather than loading a new webpage, and the transition is smooth.
I know it is possible to have silverlight call a JS function on my page (opposite to what I need). I'm thinking it is also possible for my JS function to raise an event/call a method in silverlight, but not exactly sure how - has anyone tried this? While a workaround would be to recreate the silverlight app each time, just raising an event in existing, loaded SL app would would be the perfect solution to my problem.
regards
ewart.
You can call a method in your Silverlight application from JavaScript.
See this blog post
You just need to create a class in your silverlight app that registers itself as callable from JS:
[ScriptableType]
public partial class SomeClass
{
private bool mouseHeldDown = false;
private Point moveMeOffset = new Point();
public SomeClass()
{
HtmlPage.RegisterScriptableObject("SilverlightObject", this);
}
[ScriptableMember]
public void DoThing(int x)
{
//do some stuff
}
}
Then you can call this from JS
document.getElementById("mySilverlightControl").content.SilverlightObject.DoThing(5);

Categories

Resources