Highlight selenium clicks using AOP - javascript

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.

Related

How do I exclude canvas element from Blazor Server page when modifying DOM from js?

I have a canvas tag which I update only using js logic. But after the first update, the canvas element is moved to the bottom of the html tree (guess it's a razor's fallback strategy when DOM is changed outside and it internal representation doesn't match). It would be nice to use something like:
#excludeFromRender { <canvas id="myCanvas"></canvas> }
What options do I have to update canvas element in the middle of page from js (meaning client-side) and keep it in right place of page? I should note that it's mandatory to use Blazor Server.
I don't know how to make it work.
I'm not sure why the element would be moved to the bottom of the tree.
Here's a simple wrapper component to do your excludeFromRender. It only renders once when the page loads:
public sealed class RenderOnce : IComponent
{
private RenderFragment _renderFragment;
private RenderHandle _renderHandle;
private bool _hasNeverRendered = true;
[Parameter] public RenderFragment? ChildContent { get; set; }
public RenderOnce()
{
_renderFragment = builder =>
{
_hasNeverRendered = false;
builder.AddContent(0, ChildContent);
};
}
public void Attach(RenderHandle renderHandle)
=> _renderHandle = renderHandle;
public Task SetParametersAsync(ParameterView parameters)
{
parameters.SetParameterProperties(this);
if (_hasNeverRendered)
_renderHandle.Render(_renderFragment);
return Task.CompletedTask;
}
}
Then use it like this:
<RenderOnce>
<canvas id="myCanvas"></canvas>
</RenderOnce>
So, I figured what was wrong in my case. I simply forgot to remove document.body.appendChild(canvas); at the end of canvas update logic. Sorry to bother.

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

How WebDriver Actions works

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.

Android Webview touch content

I want to get the content of that tag which I touch in webview in string.
Suppose I have 5 paragraph and I touch on one then I want content of that paragraph in string.
How can I achieve this?
Thanks
Well this is very easy, but you need to do it in parts, and you would need JavaScript.
1.- Enable JavaScript in your webview.
web.getSettings().setJavaScriptEnabled(true); //"web" is the object of type WebView
2.- Create a JavaScript Interface between the WebView and the Html.
public class JavaScriptInterface {
private Handler myHandler = new Handler();
public void getParagraph(final String paragraph){
myHandler.post(new Runnable() {
#Override
public void run() {
//Do something with the String
}
});
}
}
NOTE: Inside the method run, you will add whatever you need to process with the String retrieved from the Html. This class can be created inside the class where you create the WebView or as a separate class if you are going to use this same behavior from another activity.
3.- Send the Interface to the WebView.
web.addJavascriptInterface(new JavaScriptInterface(), "android");
/* In this case "android" is the name that you will use from the Html to call
your methods if is not too clear yet, please keep reading */
4.- You need to add the onClick event handler to each of your P tags.
<p onclick="android.getParagraph(this.innerText);">Text inside the paragraph</p>
/*android was the name we set for the interface in step 3, getParagraph is the name
of the method created on step2,"this.innerText" retrieves the text inside the paragraph*/
NOTE: All the names that you see on my example can be changed, BUT if you change the name on the java class remember to change all the calls in the html

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