Codeception pressKey ENTER does not work - webdriver

I am not familiar with codeception. I am trying to insert a text in an input field and press the ENTER button.
$I->fillField('#token-input-yw1', 'Some string');
$I->pressKey('#token-input-yw1', 13);
The text is entered but the enter key is not pressed. Any ideas?

If anyone still have problem with pressing Enter key, here is a solution: (if you are using Webdriver with Selenium)
$I->pressKey('#input',WebDriverKeys::ENTER);

Hopefully someone will find this useful.
See http://codeception.com/docs/modules/WebDriver#pressKey
pressKey
Presses the given key on the given element. To specify a character and modifier (e.g. ctrl, alt, shift, meta), pass an array for $char with the modifier as the first element and the character as the second. For special keys use key constants from WebDriverKeys class.
<?php
// <input id="page" value="old" />
$I->pressKey('#page','a'); // => olda
$I->pressKey('#page',array('ctrl','a'),'new'); //=> new
$I->pressKey('#page',array('shift','111'),'1','x'); //=> old!!!1x
$I->pressKey('descendant-or-self::*[ * `id='page']','u');` //=> oldu
$I->pressKey('#name', array('ctrl', 'a'), \Facebook\WebDriver\WebDriverKeys::DELETE); //=>''
?>
param $element
param $char Can be char or array with modifier. You can provide
several chars.
throws \Codeception\Exception\ElementNotFound
Please note, that you may need to add \ or \Facebook\WebDriver\ before WebDriverKeys:
\Facebook\WebDriver\WebDriverKeys::ENTER

I had the same problem. I pressed enter this way:
$I->executeJS('event.keyCode=13');
$I->fillField('input onkeypress=','13');
$I->pressKey('photo_link', '13');
But it didn't work.
I fixed it with the next code:
$I->executeJS("$('input#photo_link').trigger(jQuery.Event('keypress', {keyCode: 13}));");
It equals enter key, try it.

Related

window form goes not responding stage

I am new to progress 4GL. In my program, I tried to create a form using progress 4GL. The form has two fields one is DB name and another one is DB Description. The scope of this form is by default this should have one DB name and description and if a user-entered or keep blank in the field of DB name then an alert box should give a message. I have developed the form but when I run it the program keeps continuously running and window form goes not responding stage. I don't get a chance to enter or keep blank to the DB field name. Let me share my code and please help to find out what is the issue and why it's continuously running.
define variable cArcDB as character no-undo format "x(20)" INIT "qadb".
define variable cArcDBDesc as character no-undo format "x(25)" INIT "archive database".
define variable cTmp as character NO-UNDO.
form
cArcDB colon 25
cArcDBDesc colon 25
with frame frArchiveDB width 80 side-labels.
MAIN-LOOP:
REPEAT:
display
cArcDB
cArcDBDesc
with frame frArchiveDB.
set
cArcDB
with frame frArchiveDB editing:
if frame-field = "cArcDB" then do:
/* Find next/prev record from ttAppDB */
cTmp = cArcDB:input-value in frame frArchiveDB.
display
cArcDB
cArcDBDesc
with frame frArchiveDB.
end.
end. /* editing */
cArcDB = trim(cArcDB).
if cArcDB = "" then do:
/* Blank not allowed */
/* {us/bbi/pxmsg.i &MSGNUM=40 &ERRORLEVEL=3} */
next-prompt cArcDB with frame frArchiveDB.
undo MAIN-LOOP,retry MAIN-LOOP.
end.
END.
Please have look at the online reference of the "EDITING phrase". To me it looks like you're missing the READKEY after the beginning of the EDITING block and you also need to "APPLY LASTKEY" at some point. See the sample there:
/* Update Customer fields, monitoring each keystroke during the UPDATE */
UPDATE Customer.Name Customer.Address Customer.City Customer.State SKIP
Customer.SalesRep HELP "Use the space bar to select a SalesRep"
WITH 2 COLUMNS EDITING: /* Read a keystroke */
READKEY.
/* If the cursor is in any field except SalesRep, execute the last key
pressed and go on to the next iteration of this EDITING phrase to check
the next key */
IF FRAME-FIELD <> "SalesRep" THEN DO:
APPLY LASTKEY.
IF GO-PENDING THEN LEAVE.
ELSE NEXT.
END.
/* When in the SalesRep field, if the last key pressed was the space bar
then cycle through the sales reps */
IF LASTKEY = KEYCODE(" ") THEN DO:
FIND NEXT SalesRep NO-ERROR.
IF NOT AVAILABLE SalesRep THEN FIND FIRST SalesRep.
DISPLAY SalesRep.SalesRep # Customer.SalesRep.
NEXT.
END.
/* If the user presses any one of a set of keys while in the SalesRep field,
immediately execute that key */
IF LOOKUP(KEYFUNCTION(LASTKEY),
"TAB,BACK-TAB,GO,RETURN,END-ERROR") > 0 THEN APPLY LASTKEY.
ELSE BELL.
END.

Add ibanCode to exceptionMessage

I want to add iban code to my OpaCallException, so that I would know specifically which iban code is incorrect.
My code:
FIND FIRST tt_iban_crc_aaa WHERE tt_iban_crc_aaa.iban=tt_fee_request.debtorAccount AND tt_iban_crc_aaa.crc=g-crc NO-LOCK NO-ERROR.
IF NOT AVAILABLE tt_iban_crc_aaa THEN DO:
FIND FIRST aaa WHERE aaa.name=tt_fee_request.debtorAccount AND aaa.crc=g-crc NO-LOCK NO-ERROR.
IF AVAILABLE aaa THEN DO:
CREATE tt_iban_crc_aaa.
ASSIGN
tt_iban_crc_aaa.aaa = aaa.aaa
tt_iban_crc_aaa.crc = aaa.crc
tt_iban_crc_aaa.iban = aaa.name
.
END.
ELSE DO:
UNDO, THROW NEW OpaCallException("iban.invalid", "Iban incorrect", "Provided iban is invalid").
END.
END.
I am having difficult time with progress syntax. I could use some help or tips, thanks!
It looks like you need to use the SUBSTITUTE() function.
Replace "Provided iban is invalid" with SUBSTITUTE ("Provided iban (&1) is invalid", [Whatever field the iban code is in]).
You need to add a property in your OpaCallException class
DEFINE PUBLIC PROPERTY IbanCode AS CHARACTER NO-UNDO
GET.
PRIVATE SET .
Then add a constructor like this:
CONSTRUCTOR PUBLIC OpaCallException (pcIbanCode AS CHARACTER, /* add additional parameters */):
ASSIGN THIS-OBJECT:IbanCode = pcIbanCode.
SUPER (SUBSTITUTE ("Error with IBAN Code: &1", pcIbanCode), 0) .
END CONSTRUCTOR.

"Down arrow" moves cursor to end of line - how to turn it off

In IPython Notebook / Jupyter, arrow up/down keystrokes within a cell are handled by CodeMirror (as far as I can tell). I use these actions a lot (re-bound to control-p / control-n) to move between cells; but at the end of every cell, the cursor moves to end of line first before jumping to the next cell. This is counter-intuitive and, to me, rather distracting.
Is there any way to configure CodeMirror to make this move down to be just that - a move down?
Thanks!
The moving-to-next-cell behavior is defined by IPython wrapper code, which probably checks whether the cursor is at the end of the current cell, and overrides the default CodeMirror behavior in that case. You'll have to find that handler and somehow replace it with one that checks whether the cursor is on the last line. (I don't know much about IPython, only about CodeMirror, so I can't point you at the proper way to find and override the relevant code. They might have bound the Down key, or they might have overridden the goLineDown command.)
Knowing that I wasn't alone in wanting to skip the "going to end of line" behavior when going down from the last line of a code cell, I investigated that behavior and found out that:
it's CodeMirror that goes to the end of line when you type down in the last line of a code cell (file: codemirror.js ; "methods": findPosV and moveV)
and it's IPython that decides what to do with the "down" event after it has been handled by CodeMirror (file: cell.js ; class: Cell ; method: handle_codemirror_keyevent) ; looking at the code, I saw that IPython ignores the event when not at the last character of the last line.
This essentially confirms Marijin's answer.
The primary goal being to jump to the next cell, I think there's no need to prevent CodeMirror from going to the end of that line. The point is to force IPython to handle the event anyway.
My solution was to change the code from Cell.prototype.handle_codemirror_keyevent to this:
Cell.prototype.handle_codemirror_keyevent = function (editor, event) {
var shortcuts = this.keyboard_manager.edit_shortcuts;
var cur = editor.getCursor();
if((cur.line !== 0) && event.keyCode === 38){
// going up, but not from the first line
// don't do anything more with the event
event._ipkmIgnore = true;
}
var nLastLine = editor.lastLine();
if ((event.keyCode === 40) &&
((cur.line !== nLastLine))
) {
// going down, but not from the last line
// don't do anything more with the event
event._ipkmIgnore = true;
}
// if this is an edit_shortcuts shortcut, the global keyboard/shortcut
// manager will handle it
if (shortcuts.handles(event)) {
return true;
}
return false;
};
This code provides the desired behavior for the "down-arrow" key (almost: the cursor still goes to the end of the line, except that we don't see it, as we're already in another cell at that point), and also handles the "up-arrow" key similarly.
To modify the handle_codemirror_keyevent prototype, you have two possibilities:
You edit the cell.js file and change the code of the prototype to the code I gave above. The file is in <python>/Lib/site-packages/IPython/html/static/notebook/js or something similar depending on you distro
Much better, after the page is loaded, you change that prototype dynamically by doing this:
IPython.Cell.prototype.handle_codemirror_keyevent = function (editor, event) {
<same code as above>
};
You can do that in your custom.js for example, or create an extension to do it (that's what I did).

Problem with quotes in "onclick" function

I'm trying to concatenate PHP variables into an "onclick" function.
Here is the line I'm having trouble with (look for the "onclick" part):
$imagecontent = '<div class="imagensfw" id="image'.$id.'" style="width:'.round($wd).'px;height:'.round($ht).'px;" onclick="viewimage(image'.$id.','.round($wd).','.$url.');"><p>Image</div>';
I'm particularly having trouble with concatenating the $url variable. I'd want to put it between quotes, but if I do so, the "onclick" function becomes all messed up (when the code is displayed in the browser).
I think that putting the URL address ($url variable as a parameter in the onclick) between quotes will fix the error its shooting:
Error : missing ) after argument list
Here's my short Javascript function if you're interested:
function viewimage(id,width,url){
var image = document.getElementById(id);
image.innerHTML = '<img src="'+url+'" width="'+width+'" alt="Image" />';
}
Here's what I tried but didn't work (i.e. messed up the code):
onclick="viewimage(image'.$id.','.round($wd).', **"** '.$url.' **"** );"
(Noticed the double quotes added between the $url variable).
Thank you for your time.
Have you tried using variable parsing? From the link's example:
$beer = 'Heineken';
echo "He drank some ${beer}s";
This should simplify the construction of your string.
Silly me, I just noticed an error on my part. I thought we could use double quotes in an "onclick" function. Turns out not, we have to use single quotes ( ' ). It fixed my problem. Thanks!

Flex Rich Text Editor - Limiting the number of characters

Is there a way to restrict the number
of characters in the Flex Rich Text Editor?
I guess there should be, since it's possible
in a textarea. So, if I could get hold
of the textarea contained in the rich
text editor, I would be able to do it
I think this would be fairly easy in actionscript, although I'm not exactly sure how one would do it in mxml. It appears that there are two children that are contained in the RichTextEditor, one of them being TextArea. According to the documentation (http://livedocs.adobe.com/flex/3/langref/mx/controls/RichTextEditor.html#propertySummary), you can access the subcontrols like so:
myRTE.toolBar2.setStyle("backgroundColor", 0xCC6633);
With myRTE being the instance of your text editor. So my guess would be something like this would work:
myRTE.textArea.maxChars = 125;
With 125 being the number a characters you would want restricted to.
i just ran into this.
setting your maxChars on the textArea will provide a limit to the text area, but that won't be representative of the number of characters the user can type.
as the user is typing, markup is added behind the scenes, and that greatly increases the char count.
for example, if i type the letter 'a' into a RichTextEditor, i get a char count of 142 and this htmlText:
<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="10" COLOR="#0B333C" LETTERSPACING="0" KERNING="0">a</FONT></P></TEXTFORMAT>
i could not see a straightforward way to get a proper maxChar to work out of the box, so i extended RichTextEditor and gave it a maxChar. if maxChar > 0, i added a listener to "change" and did something like this in the event handler:
protected function handleTextChange(event:Event) : void
{
var htmlCount:int = htmlText.length;
// if we're within limits, ensure we reset
if (htmlCount < maxChars)
{
textArea.maxChars = 0;
this.errorString = null;
}
// otherwise, produce an error string and set the component so the user
// can't keep typing.
else
{
var textCount:int = textArea.text.length;
textArea.maxChars = textCount;
var msg:String = "Maximum character count exceeded. " +
"You are using " + htmlCount + " of " + maxChars + " characters.";
this.errorString = msg;
}
}
the idea is to apply a maxChars to the text area only when in the error state, so the user cannot type anything additional and will be prompted to erase some chars. once we leave the error state, we need to set the textArea.maxChars to zero so they can continue.

Resources