Object Spy using Java - java

I am working on a project in Java where I should be able to launch a site and then recognize a browser Web Elements with a Mouse Over, like the Object Spy in QTP. The Elements that I hope to get are Name, Class Name, ID, Tagname, Linktext,Partial LinkText, CSS Xpath..etc..
I am kind of lost on how to bridge the Browser and the Application.Can anyone help?
Thank you in Advance.

Inject a javascript/Jquery code into the web page to capture element properties. You can pass the element back to Java class and catch it in a org.w3c.dom.HTMLElement object. Using the methods in the object, you can retrieve all the attributes corresponding to the Element.

Related

how to create or get xpath of input in javafx and webview

Is there a way to get the xpath of different input/href/div of a page loaded in a javafx webview?
For example:
I want to be able to load google.com
Click search box
return xpath of the search box in system.out.
Well I dont have an working example, but I can give you all the neccessary hinds you need. I also used this several times to communicate between Java and Javascript. What happens next is that you specify an Java class which will be injected into the Javascript part and which acts like a bridge between the two languages. First you need a callback class, which is called whenever you want to pass something from the JavaScript side to Java
import netscape.javascript.JSObject;
JSObject window = (JSObject) webView.getEngine().executeScript("window");
window.setMember("jsCallBack", new JSCallBack());
The callback class need at least one method which can be called from the Javascript side. in this case it is the callback() method
public final class JSCallBack {
public JSCallBack() {}
public void callback(final String response) {
System.out.println(response) ; // this is the String which you passed on the JS side
}
}
Now it is possible to invoke the callback() method from the Javascript side and it is also possible to pass arguments.
On the Javascript side you can call the callback function of the previously injected object by
function myCallback(value){
jsCallBack.callback(value);
}
The next thing you need to do is to specify a listener in Javascript, which listens for mouse events. There is already an existing post which copes with the problem of assembling the xpath for a clicked elements. After the assembly you only need to pass the result to the callback. On this blog you can also find an exmaple for communicating between JavaFx and Javascrit via callbacks.
So fa I only have experience in passing Strings from JS to Java, which works perfectly, I don't know if it works for differnt kinds of objects.

How to convert action method to POST type in Jenkins/Hudson

I have implemented Action to create customized method url.
getURL(){ "sampleURL"}
doBuildNow(){//Method implementation}
So Here URL : http://hostserver/job/jobName/sampleURL/buildNow
I would like to use this method as POST which doesn't work by default, I didn't find any clue from google search. Can any one please help me on this.
In order to force a Jenkins action method to only accept a post, add the '#RequirePOST' annotation to the method.
#RequirePOST
doBuildNow(){//Method implementation}
This has the added benefit of automatically providing a 'Try POSTing' button when someone does a get via the browswer.
This is the behavior seen in Jenkins when accessing the '/exit' url.

How do I declare a variable in play template and access it in controller?

I am trying to set a value to a variable in play template and access it in the controller.
For ex, in homepage.scala.html, I would like to set a pageName variable a value as "homepage.scala.html".
Once I set this value in the play template, I want to access it in my controller which is presently in Java.
How do I achive this?
I will then be migrating the controller to scala. How do access the pageName value in scala controller?
Why I am trying to do this?:
I am trying to apply Play Aloha editor to my application How to integrate the Aloha Wysiwyg Editor with Play! Framework. Here, when a static content on the page is edited, the page name is passed to central controller which then modifies the actual template page or even message resource to update the static content. If I can't or shouldn't pass the page name to the controller then how do I achieve this?
Many thanks.
At a general level, your templates should be acting like pure functions, without containing any state. But based on what you're asking, assuming your view is in scope as views.html.homepage, you could do something like views.html.homepage.getClass.getName

Passing info message to a Wicket page while using PageParameters

Does Wicket somehow allow passing both of the following kinds of params in a PageParameters object? Apparently not?
accountId which is shown in the URL (/account/<ID>)
infoMessage parameter which is not shown in the (bookmarkable) URL
I'm currently using IndexedHybridUrlCodingStrategy for the page in question, and simply trying parameters "0" and "infoMessage" gives this exception:
WicketMessage: Not all parameters were encoded. Make sure all
parameter names are integers in consecutive order starting with zero.
Current parameter names are: [0, infoMessage]
If I change "infoMessage" parameter name into "1", it works, but yields an ugly URL (in this case something like /account/42/Tosite%20108207%20tallennettiin.5) which is not what I want.
Now, the obvious answer perhaps is that infoMessage shouldn't be in PageParameters. But thing is, I tried adding it as normal constructor parameter instead, like so:
public AccountPage(PageParameters parameters, String infoMessage) {
// ...
}
But this approach fails in one important use case. After deleting a persistent "Record" object related to the Account, the following does not load the AccountPage properly (the deleted record is still visible). This code is executed in onClick() of an AjaxFallbackLink.
setResponsePage(new AccountPage(AccountPage.pageParameters(account), message));
On the other hand, my original approach...
setResponsePage(AccountPage.class, AccountPage.pageParameters(account));
... works fine, as it somehow loads the AccountPage "more thoroughly", but, again, I don't know how to pass the infoMessage parameter cleanly.
(AccountPage.pageParameters() above is a simple static utility for creating appropriate PageParameters with "0" = account id. The AccountPage constructor always loads the account from persistence using the ID.)
Any ideas? Perhaps using AjaxFallbackLink partially causes the problem?
Using Wicket 1.4.
From what I see in your question, you try to render both a bookmarkable page and show a feedback message to the user (most probably in a FeedbackPanel), but you don't want that message to be part of the URL.
What you want to do is tell the Session that you have an informational message, and let the feedback panel handle the message.
#Override void onSubmit() {
... save object ...
getSession().info("Object ... has been saved");
setResponsePage(ObjectPage.class, new PageParameters("id="+object.getId()));
}
In this case you tell Wicket to temporarily store a message in the session, until it gets rendered by a feedback panel. This idiom is also known as "flash messages".
You can't use both PageParameters and another parameter as constructor arguments, because Wicket can't create your page instance with such a constructor when the page is requested. Wicket only knows how to instantiate pages with default constructors or pages with a PageParameters parameter.

How do I make session/cache variables available to my main.html template?

I'm using Play Framework and setting a cache value as such:
String sessionId = Scope.Session.current().getId();
Cache.set(sessionId + "_user", "Doser");
and I want to ouput the value in my main.html without adding the value to every single controller in my application.
How do I achieve this in Play?
The other option you have for this, is to create an action in your controller that uses the #Before annotation, and then add the value using renderArgs().
I answered a previous question which I think is very similar to your requirements.
Does Play Framework support "snippets"?
You should also be aware that all session variables are available within your template, by default. You can see all the implicit objects that are available in the template in the Template Documentation here -- http://www.playframework.org/documentation/1.2.2/templates#implicits.
I need to stop answering my own questions.
I've created a tag as described in the link below, and it works perfectly:
http://www.playframework.org/documentation/1.2.2/templates#tags

Categories

Resources