Selenium command ordering for one-after-another JavaScript prompts - selenium

One script we have asks the user for a few values via successive JavaScript calls to window.prompt(). Selenium records this action, both the prompt texts and the values I typed in, but it doesn't seem to be able to play it back properly. It 'succeeds' in that no errors occur, but only the first prompt value actually makes it back to my script. Furthermore, the default ordering Selenium records makes the second value get returned in the first one's spot, and the rest still blank:
# [info] Executing: |answerOnNextPrompt | TEXT1 | |
# [info] Executing: |select | id | label=mychoice |
# [info] Executing: |answerOnNextPrompt | TEXT2 | |
# [info] Executing: |assertPrompt | Please enter a value for q1 | |
# [info] Executing: |answerOnNextPrompt | TEXT3 | |
# [info] Executing: |assertPrompt | Please enter a value for q2 | |
# [info] Executing: |answerOnNextPrompt | TEXT4 | |
# [info] Executing: |assertPrompt | Please enter a value for q3 | |
# [info] Executing: |assertPrompt | Please enter a value for q4 | |
I reordered it into what seems more sensible to me:
# [info] Executing: |answerOnNextPrompt | TEXT1 | |
# [info] Executing: |select | id | label=mychoice |
# [info] Executing: |assertPrompt | Please enter a value for q1 | |
# [info] Executing: |answerOnNextPrompt | TEXT2 | |
# [info] Executing: |assertPrompt | Please enter a value for q2 | |
# [info] Executing: |answerOnNextPrompt | TEXT3 | |
# [info] Executing: |assertPrompt | Please enter a value for q3 | |
# [info] Executing: |answerOnNextPrompt | TEXT4 | |
# [info] Executing: |assertPrompt | Please enter a value for q4 | |
After that I get TEXT1 as the first value, but the rest still blank.
I also tried waitForPrompt in place of each assertPrompt, but no dice.
My guess is that Selenium can't actually handle this situation because answerOnNextPrompt seems to need to come before the action that triggers the prompt, but it is the action that triggers the next prompt, so after the first one triggered by select there's no way to do it because they don't stack.
I'd like to be proven wrong, though...any ideas?
(If not, I might report it as a bug / something they need to change in the API, maybe by combining answerOnNextPrompt with assertPrompt: it could just take an optional argument with how the prompt ought to be answered.)
Platform is Selenium IDE 1.0.2 on Firefox 3.5.3 on win32.

This definately looks like a limitation in Selenium. The following is from the source of selenium-browserbot.js:
windowToModify.prompt = function(message) {
browserBot.recordedPrompts.push(message);
var result = !browserBot.nextConfirmResult ? null : browserBot.nextPromptResult;
browserBot.nextConfirmResult = true;
browserBot.nextPromptResult = '';
self.relayBotToRC.call(self, "browserbot.recordedPrompts");
return result;
};
It appears to process all prompts when the window is 'modified', and after each it sets the next answer to empty. I would raise a request for an improvement. Without giving it much thought I would suggest allowing stacking of the anwerOnNextPrompt command so that you can queue up the answers you want to give to each prompt in turn.
Update:
Something similar will also happen for consecutive JavaScript confirmations. The first will use the response set by choose*OnNextConfirmation, and all following confirmations will automatically select OK (true).
windowToModify.confirm = function(message) {
browserBot.recordedConfirmations.push(message);
var result = browserBot.nextConfirmResult;
browserBot.nextConfirmResult = true;
self.relayBotToRC.call(self, "browserbot.recordedConfirmations");
return result;
};

How about this one:
# [info] Executing: |select | id | label=mychoice |
# [info] Executing: |answerOnNextPrompt | TEXT1 | |
# [info] Executing: |assertPrompt | Please enter a value for q1 | |
# [info] Executing: |answerOnNextPrompt | TEXT2 | |
# [info] Executing: |assertPrompt | Please enter a value for q2 | |
# [info] Executing: |answerOnNextPrompt | TEXT3 | |
# [info] Executing: |assertPrompt | Please enter a value for q3 | |
# [info] Executing: |answerOnNextPrompt | TEXT4 | |
# [info] Executing: |assertPrompt | Please enter a value for q4 | |
BTW, why not using a regular HTML form instead so many of those annoying javascript prompts?

Related

How to add zlib with ExternalProject_Add to CMake project as a dependency

UPDATE:
It's working but I don't know what happened so I will leave the question open.
I am trying to add zlib. For this purpose I have added the following configuration file that is included in my main CMakeLists.txt.
include(ExternalProject)
set(DEPS_BUILD ${CMAKE_BINARY_DIR}/deps/build)
set(DEPS_LOG ${CMAKE_BINARY_DIR}/deps/log)
set(DEPS_STAMP ${CMAKE_BINARY_DIR}/deps/stamp)
set(DEPS_TMP ${CMAKE_BINARY_DIR}/deps/tmp)
set(DEPS_SRC ${CMAKE_BINARY_DIR}/deps/src)
ExternalProject_Add(zlib
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/deps/zlib
INSTALL_DIR ${CMAKE_INSTALL_PREFIX}
DOWNLOAD_DIR ${DEPS_SRC}/zlib
TMP_DIR ${DEPS_TMP}/zlib
STAMP_DIR ${DEPS_STAMP}/zlib
LOG_DIR ${DEPS_LOG}/zlib
BINARY_DIR ${DEPS_BUILD}/zlib
SOURCE_DIR ${DEPS}/zlib
INSTALL_COMMAND cmake -E echo "Skipping install step for dependency zlib"
INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}
)
I am using CMake 2.21 (latest as of 9th of September 2021) and Visual Studio 2017. I have of course added zlib as a dependency like this:
add_dependencies(${MY_LIB} zlib)
where MY_LIB is the library. The ${DEPS} variable points at a subdirectory (inside the root directory of my project) where all git submodules are currently being initialized.
${CMAKE_SOURCE_DIR}
|
+ --- CMakeLists.txt
|
+ --- ${DEPS}
| |
| + --- dependencies.cmake
| |
| + --- zlib git submodule
| |
| + --- libpng git submodule
| |
| + --- libjpeg-turbo git submodule
...
Also the reason why I define all the variables below is mostly for structural purposes. The first time I added the ExternalProject stuff and ran my configuration it created a lot of directories all over the place inside my build directory. By defining specific locations I can ensure the structure I want and come in terms with:
${CMAKE_BINARY_DIR}
|
+ --- CMakeFiles
|
+ --- CMakeCache.txt
|
...
|
+ --- deps
| |
| + --- build
| | |
| | + --- jpeg
| | |
| | + --- png
| | |
| | + --- zlib
| |
| + --- src
| | |
| | + --- jpeg
| | |
| | + --- png
| | |
| | + --- zlib
| |
| |
| + --- stamp
| | |
| | ...
| |
| + --- tmp
| |
| ...
|
...
I am working on and which uses zlib's functionality internally. After generating the VS solution (with the ZERO_BUILD, ALL_BUILD etc. projects added to it) for VS 2017 64bit debug build I tried to build the zlib project just to see if it work properly but I am getting the following error:
Performing build step for 'zlib'
CUSTOMBUILD : error : could not load cache
I have successfully added turbojpeg to my project (with the same code) and it works without any issues. Given my previous experience with zlib when building 3rd party software (libs, executables) I am inclined to think that there is some configuration step missing. What that step might be is beyond me. I am also new to the ExternalProject module of CMake.

Pandoc Markdown to Latex PDF: table with alternating row colors?

I would like to have a table, in the (xe)latex PDF output of a Markdown document via pandoc, with alternating row colors - as noted here:
https://tex.stackexchange.com/questions/518097/booktabs-but-with-enclosing-border-around-the-table
... and xcolor with the table option to add alternating row colors
So, I'm trying this test.md:
---
title: "Testing"
author: Bob Alice
date: July 13, 2010
geometry: margin=2cm
documentclass: extarticle
fontsize: 12pt
header-includes: |
\usepackage[table]{xcolor}
\rowcolors{2}{white}{gray!25}
output: pdf_document
---
Here is a test of a table:
+----------+-------------------+-----------------+
| Box name | Another parameter | The IP address |
+==========+===================+=================+
| Test 1 | random-string-01 | 10.0.0.20 |
| Test 2 | random-string-02 | 10.0.0.30 |
+----------+-------------------+-----------------+
If I convert this via pandoc:
$ pandoc --version
pandoc.exe 2.10 ...
... with:
pandoc test.md --pdf-engine=xelatex -o test.pdf
... the result is:
Error producing PDF.
! LaTeX Error: Option clash for package xcolor.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.60 \rowcolors
So, apparently xcolor gets loaded in this setup, with other options, that clash with the [table] option.
Is it possible to coax pandoc into producing all tables in a Latex/PDF document with alternating row colors - without using custom templates?
Thanks to the link by #user1759789 in comments, it seems that it is enough to pass the Latex document class option table, which then gets passed when to xcolor when is loaded; note that the code will still generate this error, if you leave the \usepackage[table]{xcolor} line. So the working Markdown is this:
---
title: "Testing"
author: Bob Alice
date: July 13, 2010
geometry: margin=2cm
classoption: table
documentclass: extarticle
urlcolor: blue
fontsize: 12pt
header-includes: |
\rowcolors{2}{gray!10}{gray!25}
output: pdf_document
---
Here is a test of a table ( [buggy](https://stackoverflow.com/questions/62835496/) ):
+----------+-------------------+-----------------+
| Box name | Another parameter | The IP address |
+==========+===================+=================+
| Test 1 | random-string-01 | 10.0.0.20 |
| Test 2 | random-string-02 | 10.0.0.30 |
+----------+-------------------+-----------------+
and another grid table:
+----------+-------------------+-----------------+
| Box name | Another parameter | The IP address |
+==========+===================+================:+
| Test 1 | random-string-01 | 10.0.0.20 |
+----------+-------------------+-----------------+
| Test 2 | random-string-02 | 10.0.0.30 |
+----------+-------------------+-----------------+
and pipe table:
| Box name | Another parameter | The IP address |
|-----------------|-------------------------|-----------------|
| Test 1 | random-string-01 | 10.0.0.20 |
| Test 2 | random-string-02 | 10.0.0.30 |
... and the output is:

Test cases that run two different python scripts which are in different directories

I want to run a .robot file to test two different python scripts, which are in different directories. My .robot file is in /home/alperen/Desktop/scpTest and it is as follows:
*** Settings ***
| Library | Process
*** Test Cases ***
| Use Case 1 - Scp Test
| | [Documentation] | This .robot file tests the useCase1ScpTest.py by checking the stdout.
| | [Tags] | use case 1 | critical | scpTest
| | ${result}= | run process | python | /home/alperen/Desktop/scpTest/useCase1scpTest.py
| | Should be equal as integers | ${result.rc} | 0
| | Should be equal as strings | ${result.stdout} | Passed.
| Dummy test
| | [Documentation] | Dummy text
| | [Tags] | foo | bar | runScriptOnRemote
| | ${result}= | run process | python | /home/alperen/Desktop/runScriptOnRemote/masterScript.py
| | Should be equal as integers | ${result.rc} | 0
| | Should be equal as strings | ${result.stdout} | Passed.
If I run the code above, Dummy Test fails with a message "Failed. != Passed." because masterScript.py most probably prints "Failed." However, if I copy the masterScript.py to the same directory with my .robot file, Dummy Test results with a pass. Can anyone please help me understand why it happens? Is there a way to pass the Dummy Test without copying masterScript.py? Thanks in advance.
Edit: masterScript.py runs another script named hello.py (which prints "hello world") on a remote machine. If "hello world" is printed, then masterScript.py file prints "Passed." and "Failed." otherwise.
I have modified masterScript.py, which included something like
command = [ "python", "hello.py" ]
Changing "hello.py" to its full directory, something like "/home/alperen/Desktop/runScriptOnRemote/hello.py" worked, thanks to Psytho's suggestion.
Run robot with the --pythonpath switch directing it to the masterScript.py path. It's not the most elegant solution, but it works

Is there a way to split a string into an array in Selenium IDE

I'm trying to split the string "1 out of 20"
Is there a way to store 1 in a variable and 20 in another variable?
|store | 1 out of 20 | Text |
|storeEval | "${Text}".split(" ")[0] | firstsection |
|echo | ${firstsection} | |
[info] echo: 1
|storeEval | "${Text}".split(" ")[3] | lastsection |
|echo | ${lastsection} | |
[info] echo: 20
I'm not an expert in this field but probbaly this coudl help you
Selenium split date string working example?
It looks that splitting a string is possible via Selenium

Is it possible to view RabbitMQ message contents directly from the command line?

Is it possible to view RabbitMQ message contents directly from the command line?
sudo rabbitmqctl list_queues lists the queues.
Is there any command like sudo rabbitmqctl list_queue_messages <queue_name>?
You should enable the management plugin.
rabbitmq-plugins enable rabbitmq_management
See here:
http://www.rabbitmq.com/plugins.html
And here for the specifics of management.
http://www.rabbitmq.com/management.html
Finally once set up you will need to follow the instructions below to install and use the rabbitmqadmin tool. Which can be used to fully interact with the system.
http://www.rabbitmq.com/management-cli.html
For example:
rabbitmqadmin get queue=<QueueName> requeue=false
will give you the first message off the queue.
Here are the commands I use to get the contents of the queue:
RabbitMQ version 3.1.5 on Fedora linux using https://www.rabbitmq.com/management-cli.html
Here are my exchanges:
eric#dev ~ $ sudo python rabbitmqadmin list exchanges
+-------+--------------------+---------+-------------+---------+----------+
| vhost | name | type | auto_delete | durable | internal |
+-------+--------------------+---------+-------------+---------+----------+
| / | | direct | False | True | False |
| / | kowalski | topic | False | True | False |
+-------+--------------------+---------+-------------+---------+----------+
Here is my queue:
eric#dev ~ $ sudo python rabbitmqadmin list queues
+-------+----------+-------------+-----------+---------+------------------------+---------------------+--------+----------+----------------+-------------------------+---------------------+--------+---------+
| vhost | name | auto_delete | consumers | durable | exclusive_consumer_tag | idle_since | memory | messages | messages_ready | messages_unacknowledged | node | policy | status |
+-------+----------+-------------+-----------+---------+------------------------+---------------------+--------+----------+----------------+-------------------------+---------------------+--------+---------+
| / | myqueue | False | 0 | True | | 2014-09-10 13:32:18 | 13760 | 0 | 0 | 0 |rabbit#ip-11-1-52-125| | running |
+-------+----------+-------------+-----------+---------+------------------------+---------------------+--------+----------+----------------+-------------------------+---------------------+--------+---------+
Cram some items into myqueue:
curl -i -u guest:guest http://localhost:15672/api/exchanges/%2f/kowalski/publish -d '{"properties":{},"routing_key":"abcxyz","payload":"foobar","payload_encoding":"string"}'
HTTP/1.1 200 OK
Server: MochiWeb/1.1 WebMachine/1.10.0 (never breaks eye contact)
Date: Wed, 10 Sep 2014 17:46:59 GMT
content-type: application/json
Content-Length: 15
Cache-Control: no-cache
{"routed":true}
RabbitMQ see messages in queue:
eric#dev ~ $ sudo python rabbitmqadmin get queue=myqueue requeue=true count=10
+-------------+----------+---------------+---------------------------------------+---------------+------------------+------------+-------------+
| routing_key | exchange | message_count | payload | payload_bytes | payload_encoding | properties | redelivered |
+-------------+----------+---------------+---------------------------------------+---------------+------------------+------------+-------------+
| abcxyz | kowalski | 10 | foobar | 6 | string | | True |
| abcxyz | kowalski | 9 | {'testdata':'test'} | 19 | string | | True |
| abcxyz | kowalski | 8 | {'mykey':'myvalue'} | 19 | string | | True |
| abcxyz | kowalski | 7 | {'mykey':'myvalue'} | 19 | string | | True |
+-------------+----------+---------------+---------------------------------------+---------------+------------------+------------+-------------+
I wrote rabbitmq-dump-queue which allows dumping messages from a RabbitMQ queue to local files and requeuing the messages in their original order.
Example usage (to dump the first 50 messages of queue incoming_1):
rabbitmq-dump-queue -url="amqp://user:password#rabbitmq.example.com:5672/" -queue=incoming_1 -max-messages=50 -output-dir=/tmp
If you want multiple messages from a queue, say 10 messages, the command to use is:
rabbitmqadmin get queue=<QueueName> ackmode=ack_requeue_true count=10
This is how it looks on front interface avalable on http://localhost:15672 :
If you don't want the messages requeued, just change ackmode to ack_requeue_false.
you can use RabbitMQ API to get count or messages :
/api/queues/vhost/name/get
Get messages from a queue. (This is not an HTTP GET as it will alter the state of the queue.) You should post a body looking like:
{"count":5,"requeue":true,"encoding":"auto","truncate":50000}
count controls the maximum number of messages to get. You may get fewer messages than this if the queue cannot immediately provide them.
requeue determines whether the messages will be removed from the queue. If requeue is true they will be requeued - but their redelivered flag will be set.
encoding must be either "auto" (in which case the payload will be returned as a string if it is valid UTF-8, and base64 encoded otherwise), or "base64" (in which case the payload will always be base64 encoded).
If truncate is present it will truncate the message payload if it is larger than the size given (in bytes).
truncate is optional; all other keys are mandatory.
Please note that the publish / get paths in the HTTP API are intended for injecting test messages, diagnostics etc - they do not implement reliable delivery and so should be treated as a sysadmin's tool rather than a general API for messaging.
http://hg.rabbitmq.com/rabbitmq-management/raw-file/rabbitmq_v3_1_3/priv/www/api/index.html
a bit late to this, but yes rabbitmq has a build in tracer that allows you to see the incomming messages in a log. When enabled, you can just tail -f /var/tmp/rabbitmq-tracing/.log (on mac) to watch the messages.
the detailed discription is here http://www.mikeobrien.net/blog/tracing-rabbitmq-messages