Protractor : How to select an item from list when right-clicked - select

I am trying to Right click on an element and then select an option "Rename" from the list. I have got "right clicking" working but can't select option from the list. Referred links 1, 2
Note 1:
1: On right click the menu options that are visible are native context menus. So, they don't appear in my DOM that I can see.
2: The App runs only in Chrome browser(not sure if it is a browser issue)
I have tried the following code:
browser.actions().mouseMove(elementVar).perform();
browser.actions().click(protractor.Button.RIGHT).click(protractor.Button.ARROW_DOWN).click(protractor.Button.ARROW_DOWN).click(protractor.Button.ARROW_DOWN).perform();
Consider, "Rename" to be the third option in the list.
Note 2:
If I am just running the app and enter 'R' from my keyboard, it selects the "Rename" option. But when I tried to run it in my test, it doesn't select the "Rename" option. See below code I tried:
browser.actions().mouseMove(elementVar).perform();
browser.actions().click(protractor.Button.ARROW_RIGHT).sendKeys('R',protractor.Key.ENTER).perform();
None of the above code works. Let me know if more information is required.
EDIT:
I am guessing the following to be happening:
once I mouse over, the script "right clicks" and after that the "tooltip" is displayed. Since the "tooltip" is displayed after "right click" I think the menu list goes to the background(the list is still visible along with the tool-tip), which is why the arrow down keys aren't working. Is this possible? If yes, how can I wait for the tooltip to be invisible and then right click?
Input: I tried to wait for tool-tip to be invisible and then right click, but still the "Arrow_down" doesn't work.
Is there a way to bring the menu list in the front once we have right clicked?
IMPORTANT:
I took a screenshot after I right clicked on the element, and the screenshot doesn't show the "menu list". Below is the code for screenshot:
browser.actions().click(protractor.Button.RIGHT).perform()
.then(function() {
browser.takeScreenshot().then(function(screenShot) {
writeScreenShot(screenShot, "image.png");
});
});
//writeScreenShot takes two variables actual screenshot data and the file name. And the screenshot is saved as "image.png"
What needs to be done?

When you send ARROW keys to the browser, you have to send them as keys instead of passing them to click() function and the ARROW_DOWN key is part of Key object and not BUTTON. Here's how -
browser.actions().mouseMove(elementVar).perform();
browser.actions().click(protractor.Button.RIGHT).sendKeys(protractor.Key.ARROW_DOWN).sendKeys(protractor.Key.ARROW_DOWN).sendKeys(protractor.Key.ARROW_DOWN).perform();
For your second try, you should send RIGHT in the place of protractor.Button.ARROW_RIGHT to right click. When you send two actions/keys to sendKeys() function, you have to join them using chord object which combines the action of pressing two keys at a time(ex: CTRL+C for copy). But in your case i don't think its really necessary. Here's how to use it -
browser.actions().mouseMove(elementVar).perform();
browser.actions().click(protractor.Button.RIGHT).sendKeys(protractor.Key.chord("r", protractor.Key.ENTER).perform(); //Not necessary as you wont be pressing R+ENTER in your keyboard
OR
browser.actions().click(protractor.Button.RIGHT).sendKeys('R').sendKeys(protractor.Key.ENTER).perform();
Hope this helps.

use XPath to solve your problem
browser.actions().mouseMove(target).perform();
browser.actions().click(protractor.Button.RIGHT).perform();
element(by.xpath('//*[#id="context-menu"]/ul/li[1]')).click();
In your case it will be "//*[#id="context-menu"]/ul/li[3]" most probably.

Related

Testing keyboard input for blueprint select with react testing library

I have created a codesandbox to illustrate my issue here:
https://codesandbox.io/s/floral-resonance-z2h43?file=/src/SelectExample.spec.tsx
I am trying to test the keyboard navigation within a blueprint select. That is opening the select by clicking the button, then pressing key arrows untill the desired item is active and confirming with enter which closes the select.
The functionality works perfectly fine.
I however fail to get the unit test(s) to work. As you can see in the linked sandbox a unit test that select the new item via mouseclick works.
I however have run out of ideas how to trigger the onChange of the SelectExample with keyboard inputs.
userEvent.keyboard() doesn't work and fireEvent doesn't either (though I'm not sure what to target considering how blueprint implements the select and that I can only add data-testid to some elements, but going to any number of parentElements from the items which have testids didn't work either). Same issue with userevent.type(), unless the target for that is the desired item in which case the test pases but only because the implementation type() clicks on it before entering its text.
References for the keyboard input:
https://testing-library.com/docs/dom-testing-library/api-events/
https://testing-library.com/docs/ecosystem-user-event/
I'd appreciate any input.

DOM usage in QTP

During script execution a pop up won't go away, and it happens only through QTP(v12.02).
I am trying DOM to bypass the problem, the pop up event was on selection of a drop down value, so I used some code to find the correct index and use DOM to select the value
Browser().Page().WebList().Object.selectedIndex = itmindx
With this the pop up issue got resolved, but now to complete the process,I need to click the Save button which is disabled as the page didn't refreshed when the value was selected ( tried refreshing through QTP, tab out etc--didn't worked as it loads the previous value).So I used the fire event method
Browser().Page().WebList().Fireevent "onchange"
with this I ran in to the same issue of multiple pop ups. Used the following
Browser().Page().WebList().Object.onchange()
but then QTP won't executes the next line unless I hit enter externally on the pop up(multiple pop up is resovled but now QTP is stuck. I don't want to use RS.... Any solutions?
To enable the button
Browser().Page().WebButton().Object.disabled = false
Or
To hit enter for the popup
CreateObject("WScript.Shell").SendKeys("{ENTER}")
[ http://ss64.com/vb/sendkeys.html ]
Go for hitting the Enter button using SendKeys. It is not a good idea accessing DOM and change the state ourselves. There is a chance that you might miss potential defects!

Prevent users from typing and clicking in MS Word Add-in

I am writting a MS Word Add-in, I create a button to run a long time work with text. My work requires that during the time it is excuted, no change can be made by user ( typing, clicking, deleting ...) When this work is completed, user can type and click as usual.
I have used
this.Application.Options.AllowClickAndTypeMouse = false;
However, this doesn't work.
Who can help me!
First, your approach is wrong. The Click and Type is Word functionality and has nothing to do with disabling user Mouse clicks
(For more information about Click and Type refer to here).
Now for your question, here is one approach I would suggest:
If the user is not able to do any action, I would expect an appropriate message, so my idea is to create a modal form by using:
myForm.ShowDialog();
It should do the job and block the active document until it get closed.
I would also add a nice progress bar and "Close" button which you will enable when work has done.

mousedown event on options in select with jquery .on

I was reading the documentation of the .on event handler of jQuery and I started playing around with it.
I have a simple <select> element with the multiple attribute set to true.
However, I want the user to be able to select multiple items without having to press the ctrl or shift key(s)
According to the .on documentation, if you specify a selector it will automatically add those event handlers to any new items added inside that container that match the selector specified.
So in my case, I could for example decide to replace the <option> elements available in the listbox, but I still want to have the same functionality for those options without having to rebind those events etc.
One might think that the following snippet should do the trick (atleast, I did):
$('#dropdownlist').on('mousedown', 'option', function(e){
e.preventDefault();
$(this).prop('selected', $(this).prop('selected') ? false : true);
return false;
});
So when a users clicks on an option in that listbox, the default action will be cancelled and depending wether the item is already selected or not, it will invert that selection.
I have created a small fiddle demonstrating this behaviour: fiddle
In that fiddle, the first dropdownlist is behaving as expected, but the functionality is lost when replacing the items. This only works in FF & Chrome.
The second dropdownlist is how I thought it should've been (event handling wise), but that doesn't seem to work besides in Chrome -.-
The functionality is kept when replacing items, because the console will still log '2' when clicking on an item after replacing them.
Can someone explain me why this is happening? Am I doing something wrong?
Please point me in the right direction!
Thanks!
~ Dirk
IE doesn't respect the mousedown event on the option tag itself. You've got to use the OnChange event of the select tag, which is not what you (nor I) want. I was trying to do the exact same thing as you and was stopped at every attempt. I finally gave up and made it a list of checkboxes because I can get the same behavior out of mine that you are trying to do here.
You can see this question for some options, but I never did get it to work the way you are describing.

Is there a simple source code viewer plugin for eclipse?

for example
setMediamixDefaultTime(mediamixVO);
boolean booked = false;
Long campaignSeq = mediamixVO.getCampaignSeq();
when I want to know about how to declared setMediamixDefaultTime() method,
I have to jump to setMediamixDefaultTime() declaration line.
It's very annoying especiouly source code is long..
so I need that is,
if I move mouse to that method or keyboard shortcut, the method declaration popup in small window.
just crtl+click on the item you want to jump to.
There is also an outline view, which shows the program structure.
Control + mouse click on the method will take you to the method declartion and you can use the back button to come back to the previous code.
Again the shortcut for back button is Alt + left arrow
You can make use of the Declaration View if you don't want to lose your place, but the Navigate menu's "Last Edit Location", Back, and Forward actions may also work.