How to perform a 'mouse down' event using webdriver io? - selenium

Try to perform the following, with no luck:
Move to target element.
Perform a Left mouse click and hold against the target element.
My code (https://webdriver.io/docs/api/webdriver#performactions):
await $("#button1").moveTo();
await browser.performActions({ "actions": [mousedown] });

Related

Handle VueJS event only when key is pressed

I use VueJS component provided by 3rd-party library, which has its own events. I can handle such events as usual with "v-on" directive and specifying interesting event name, like that:
<TheComponent v-on:itemchanged="handler"/>
But is it possible to run handler only when 'itemchanged' occurs with CTRL key pressed? The handler should not run when CTRL key is not pressed.
I tried to play with click.crtl and keydown.ctrl but have no success.
Is it possible to run handler only when 'itemchanged' occurs with CTRL key pressed?
Assuming itemchanged is triggered by a change event: no, not without a workaround. Unlike keyboard and mouse events, change contains no keyboard info. You'll need to track the status of ctrl keypresses independently because JavaScript has no way of testing whether a key is down outside of those events.
Plugin
One encapsulated way to accomplish it is with a plugin:
const pluginKeypresses = function(Vue) {
const keyPresses = {
Control: false
}
window.onkeyup = function(e) { keyPresses[e.key] = false; }
window.onkeydown = function(e) { keyPresses[e.key] = true; }
Vue.prototype.$keyPresses = Vue.observable(keyPresses);
}
Vue.use(pluginKeypresses);
Note: The e.key detection here is the current standard as of 11/2020, but is not yet fully supported by IE and some other browsers. If IE matters to you, change the key detection implementation to your liking.
Usage
From anywhere in the app you can test this.$keyPresses.Control (boolean)
Demo
Don't you receive an event object with this event ? By adding a parameter to handler you should be able to catch the event, and check inside which key is pressed. Then just add a if statement at the beginning of you handler function.

UI5 - OPA5 tests - simulate "right click" or "long press" or "context menu"

I am beginning with OPA5 tests in UI5 and I created a context menu that is shown when a button, label or an image is right-clicked or if user holds it on touch screen.
Now I need to write an OPA5 test for this. I can perform left-click using new sap.ui.test.actions.Press() but I am not able to do right-click or long-press.
https://sapui5.hana.ondemand.com/#/api/sap.ui.test.actions/overview
Can someone help, please?
I believe I would be able to write it in jQuery. And as UI5 is based on jQuery there should be a way but I do not know how to combine jQuery and UI5.
If your Control has an event for RightClick, Hold etc. you should be able to call this Event in an Opa test somehow like:
iRightClickMyControl: function () {
return this.waitFor({
id: "myControlId",
viewName: "myView",
actions: function (oControl) {
oControl.RightClick();
}
errorMessage: "myControl was not found."
});
}
See "Writing Your Own Action" in
https://openui5.hana.ondemand.com/#/topic/8615a0b9088645ae936dbb8bbce5d01d

How to capture the event on clicking the arrow icon in tree grid

I am trying to call a function by clicking the arrow icon in treegrid.
I tried using onRowClick, but the function I use accepts rowData whereas rowClick return the event. How do i extract the information from event and pass it to rowData.
dojo.connect(grid, "onRowClick", formatIcon);
//Function Definiton
formatIcon(rowData){
//do something with rowData
}
with this i face issue rowData is undefined.
You should be able to catch the onClick event from your Dijit Tree Node.
onClick(item, node, evt)
More info can be found here:
http://dojotoolkit.org/api/#1_10dijit_Tree_onClick

Cancel WinJS.UI.Animation.pointerDown if not clicked

I'm using WinJS.UI.Animation.pointerDown and WinJS.UI.Animation.pointerUp within a WinJS repeater's item template.
The problem is if a user holds their finger or the mouse button down on an item and moves off it, the pointerUp animation doesn't seem to fire or it fires but has no effect because the element that the up event is on is not the same as the one before. The best example of this is in the animation sample in example 6 (tap and click). Hold down the mouse button on a tile and move it off. It will stay in it's animated state and won't fire the pointerup event. Here's the code I'm using.
How can I cancel the pointerdown animation if the user moves off the element?
target1.addEventListener("pointerdown", function () {
WinJS.UI.Animation.pointerDown(this);
}, false);
target1.addEventListener("pointerup", function () {
WinJS.UI.Animation.pointerUp(this);
}, false);
target1.addEventListener("click", function () {
//do something spectacular
}, false);
I'm using the click event to commit the click action so that the right click remains clear for launching the navigation at the top of the app.
Have you tried adding an event listener for pointerout? That's the event that's dispatched when a pointing device (e.g. mouse cursor or finger) is moved out of the hit test boundaries of an element.
See the docs on pointer events here:
http://msdn.microsoft.com/en-us/library/ie/hh772103(v=vs.85).aspx

program stuck using drag and drop selenium

I am trying to move slider using drag and drop. It identifies the element and clicked on it and after that nothing happens and my code stuck there itself(like waiting for user input). As soon as i moved my mouse little bit manually it executes rest of the code and works as expected. please help me what is this weird behavior.?. below is the code i used to build drag and drop.
Actions builder = new Actions(driver);
Action secondSlide = builder.dragAndDropBy(secondSlider, 50, 0).click().build();
System.out.println("waiting");
secondSlide.perform();
System.out.println("not waiting");
"Waiting" message is printing nicely but it doesn't print "not waiting" as it stuck in "secondSlide.perform()" line. But as soon as i moves my mouse little bit manually it prints "not waiting" and program ends gracefully.
Try to do it differently. Here is a number of approaches:
WebElement element = driver.findElement(By.name("element dom name"));
WebElement target = driver.findElement(By.name("target dom name"));
(new Actions(driver)).dragAndDrop(element, target).perform();
Or:
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(someElement)
.moveToElement(otherElement)
.release(otherElement)
.build();
dragAndDrop.perform();