Protractor version 5.2.0 (Latest) - How to simulate keyboard key presses- TAB, ENTER? - protractor

Following NOT working:
browser.actions().sendKeys(protractor.Key.TAB);
browser.actions().sendKeys(protractor.Key.ENTER);
it('validate the upload portfolio feature', function() {
//loginPage.loginToPRA(); // not needed
element(by.custLoc(ObjRep.validateUploadPortfolio.portUpload)).click();
browser.actions().sendKeys(protractor.Key.TAB);
browser.actions().sendKeys(protractor.Key.ENTER);
browser.sleep(3000);
});
In Browse code button locator:
class="text-white background-teal cursor-pointer overflow-hidden padding-vertical-5 padding-horizontal-20 border-radius-4 border-shadow vertical-align-middle"

You're mixing two ways of Key-Inputs.
Selenium Way: browser.actions()
If you use browser.actions(). you use the Selenium-Way and you must end it with perform() to execute the action.
Find here in this Protractor API a short description plus a link to the detailed Selenium description with all possible key-actions.
Protractor Feature element.sendKeys():
Here you actually don't need browser.actions()., but element., because according to the Protractor API description here .sendKeys() is a property/function followed after an element.
So all described in Code (I'm only using element.sendKeys(), so I didn't test the Selenium-Way)
//SELENIUM-ACTION SEQUENCE IN PROTRACTOR
//Press first TAB, execute it, then Enter, execute it. The current cursor position doesn't matter
browser.actions().sendKeys(protractor.Key.TAB).perform();
browser.actions().sendKeys(protractor.Key.ENTER).perform();
//Press TAB then ENTER fast one after the other
browser.actions()
.sendKeys(protractor.Key.TAB)
.sendKeys(protractor.Key.ENTER)
.perform();
//PROTRACTOR
//focuses first the cursor to "element", then presses [TAB]
element.sendKeys(protractor.Key.TAB);
//focuses first the cursor to "element", then presses [ENTER]
element.sendKeys(protractor.Key.ENTER);

Related

Pressing Enter on a date input in Cypress

I have an app with some input fields that I'm trying to automate. The gist of these fields is that I should be able to double click a field, type in a new value, then press Enter to submit that value, which sends a PUT request and also closes the input field. This works for any input type except date.
So far I've tried:
Using cy.type('{enter}'). This gives Typing into a date input with cy.type() requires a valid date in the format 'yyyy-MM-dd'. You passed: {enter}
Using cy.trigger() to send out a keydown event for the enter key. This works, as in it closes the input field successfully but it somehow doesn't send the PUT request.
Pressing enter on the parent Element. Same as using cy.trigger()
Strangely enough, manually opening the input field myself, typing a date and pressing enter will send the request just fine. It seems to me like there's some issue with programmatically pressing enter to submit the field without Cypress interpreting this as my attempt to actually type an invalid character into the date field. The docs do specifically say that no special characters are allowed in a date field.
Can't post any code as this is corporate.
I have tried to let it work, but it simply can't be done at the moment. Something like this should work:
it.only('test', function () {
cy.visit('https://www.html5tutorial.info/html5-date.php')
cy.get('input')
.type('2009-12-12')
.type('{enter}')
})
But it doesn't so I started to dig into the pile of issues and found this one:
https://github.com/cypress-io/cypress/issues/3405 . It is about a different input type, but I believe it is related to your problem.
Unfortunately this problem is still present in Cypress 9.5. One possible work-around is to directly trigger the Javascript keyup or keydown event that you are listening for.
cy.get('input')
.type('2020-01-01T12:00')
.trigger('keydown', {
key: 'Enter',
});
This works for me, but as you pointed out might not in all situations. It depends entirely on how your app is listening for Enter in the first place and on which element.
Another possible option is to call .submit() on the form that wraps the input. If you're testing a component, you could create your own wrapper component that contains a form in order to trigger the submit.
You should remove 'date' attribute like below:
cy.get('input').invoke('removeAttr','type').type('2009-12-12{enter}');
I used something like that in my code, and it worked properly
cy.get('get-your-input').invoke('removeAttr', 'type')type('2022-12-01{enter}').trigger('change');
cy.get('get-your-input').invoke('attr', 'value', '2022-12-01').trigger('change');
cy.get('get-your-input').invoke('attr', 'type', 'date');
Please add date plus enter keystroke in the type: cy.get("#date").type("02-02-2022{enter}");

Creating Netbeans Code Template for tinylog

I am attempting to add a code template to Netbeans so that typing lg followed by Tab will insert a tinylog statement. What I have so far is:
Logger.${logLevel type="org.pmw.tinylog.Logger.*" editable="true" default="info" }("${message}");
This works somewhat and produces a line that looks like:
Logger.info("message");
Pressing Tab moves the cursor between 'info' and 'message'. I can modify the 'message' field, press Tab and move back to the 'info' field. However, if I hit Control-Space and change 'info' to any of the other methods, the new method loads, but the code template wizard shuts down and then Tab just moves code to the right instead of switching between the method name and String parameter.
Have I made an error in my template, or am I asking too much from Netbeans to expect it is possible to keep the wizard alive when I change methods from info(String) to debug(String) for instance?

Issues with Drupal's autocomplete test with Behat

I'm trying to test a form generated by Drupal where there are some autocompletion to help people do the right choice.
In this form, there are 3 fields that let the user select 3 articles ('Actualités'), and once you start typing things, the auto-completes generates a list of Articles that have a similar title.
Here is an example:
The problem is that I realized while doing some tests that using $this->getSession()->getPage()->fillField() makes Behat loose focus on the field, like if it presses Tab once done filling the field.
So I tried a lot of tricks to gain focus of this field, like the following:
$field = $this->getSession()->getPage()->findField('field_mb_actualites[0][target_id]');
if($field) {
// Solution #1
// the dropdown menu is inside a `ul#ui-id-1` element
$this->getSession()->executeScript("jQuery('#ui-id-1').show();");
// Solution #2
$field->focus();
// Solution #3
// Consists of pressing "shift + tab" for a "reverse tab" and trying to get back to the field
$this->getSession()->getDriver()->keyDown($xpath, 16);
$this->getSession()->getDriver()->keyDown($xpath, 9);
$this->getSession()->getDriver()->keyUp($xpath, 9);
$this->getSession()->getDriver()->keyUp($xpath, 16);
// And I take a screenshot at the end to see if anything worked
file_put_contents('screenshot-focus.png', $this->getSession()->getDriver()->getScreenshot());
}
But I always get the same result, which is the following:
All I need to do once I have the focus is to press the "right" directional arrow to make the dropdown visible again, then the "down" directional arrow to select a suggestion, then "Enter" to confirm the choice.
However, I'm starting to run out of ideas, even though I found a couple questions on Behat's github about this problem, but I couldn't manage to make the answers work. How can I trigger the auto-complete?
Thank you in advance
You can use a JavaScript function to trigger the event like this:
public function triggerEventOn($css_selector){
$function = <<<JS
(function(){
var element = document.querySelector("$css_selector");
var event = document.createEvent('Event');
event.initEvent('change', true, true);
element.dispatchEvent(event);
})()
JS;
try{
$this->getSession()->getDriver()->executeScript($function);
}catch (Exception $e){
}
}
If you want you can also adapt this to fill the field and trigger the event after.
For checking the event that you need to trigger you need to inspect that element and check that ev in the inspector.

In Selenium IDE create node text title not found and give the error

Generate error Image screenshot :
I am also use command and run that i.e. type, typeAndWait, typeKeys, typeKeysAndWait , also give the error
Selenium IDE:
Command : Target
type : id=ctl00_Dialogproxy_deletenews_btnDelete
Reference box give the message text :
type(locator, value)
Arguments:
locator - an element locator
value - the value to type
Sets the value of an input field, as though you typed it in.
Can also be used to set the value of combo boxes, check boxes, etc. In these cases, value should be the value of the option selected, not the visible text.
I am send the image URL for all details
Edit: Image was hidden so make it visible.
This looks like it is again a duplicate of the issue you've noted in In Selenium IDE btnDelete (Button) not found
You follow up a "click" that loads a dynamic pop up with an action on a new element. It's possible that selenium is moving to fast for the pop up and the new elements are not in the DOM yet for selenium to access.
I suggest using a "waitFor" action, such as waitForElementPresent. You can also see if this is a case by inserting a pause (with 5 or 10 seconds). I do not recommend pause since it's a hard stop where as a waitFor command will take the minimum amount of time it needs.

Eclipse PDT: show every call of function

Is there an option in Eclipse PDT to show every call of chosen function.
I now if you select some kind of function and hit F3 key you will see a definition of selected function.
Open the Search Menu, Choose 'Search...', and navigate to the PHP tab, then
Enter the method name in the search string text box;
Select Method in the Search for group;
Select References in the Limit to group.
Find method usages http://img217.imageshack.us/img217/83/eclipsepdtfindmethodusa.png
We have a plugin for that... nWire for PHP. It's a comprehensive PHP code analyzer which represents all your code associations, invocations included in one quick and easy to use view. It can also represent the associations graphically.