Capturing Copy Paste in Katalon - katalon-studio

How do you capture copy and paste functions in Katalon Studio?
I am writing a Katalon script which requires the user to copy and paste a randomly generated security number.

First, you will need to
import org.openqa.selenium.Keys as Keys
and then (let us say you will double click to select the number):
WebUI.doubleClick('id-of-the-number-field')
WebUI.sendKeys('id-of-the-number-field', Keys.chord(Keys.CONTROL, 'c'))
WebUI.click('id-of-the-paste-field')
WebUI.sendKeys('id-of-the-paste-field', Keys.chord(Keys.CONTROL, 'v'))

You can get the text from the object and store it in a variable:
String s = WebUI.getText("your-testobject")
WebUI.setText("your-testobject", s)
Then you could do whatever you want with the string.

Related

Is there a way to insert N times the same characters

I can't find if vscode has a such failure. Is there a way to construct a string with N characters?
I explain myselft:
I need to wrote an empty string like this:
foobar = "1111111111111111";
There is 16 times characters '1'. Is there a way, like in Vim, to construct the line like this:
i wrote 'foobar = "' then i'd make a command to repeat 16 times the character 'i'.
I hope it's clear for you.
Here is an easy way using HyperSnips - a snippet extension that can use javascript to produce the output. First the demo:
The HyperSnips snippet:
snippet `"(.+)\*(\d+)=` "expand" A
``
let origStr = m[1];
let howMany = parseInt(m[2]);
let newStr = origStr.repeat(howMany);
rv=`"${newStr}`
``
endsnippet
This code goes inside a <yourLanguage>.hsnips file to have it run only in that language or all.hsnips to run in all files.
I made it to run inside a "" using this key: (.+)\*(\d+)=
The = is really the trigger - it runs automatically - you could change that to be something else. [The key could be shorter if you didn't care about digits being repeated.]
For more on setting up HyperSnips (which is pretty easy) see VSCode Advanced Custom Snippets
There currently is no native way, outside of copy/pasting.
You can use Repeat Paste:
Copies selected text and pastes repeatedly based on user input. Functions like Vim yank, paste, and repeat. For example, in Vim you would select the characters you want to copy then type 30p to paste the selected text 30 times.
Select a char and activate your command palette with CTRL + SHIFT + P and type 'Repeat Paste' and it will prompt you for the quantity.
You can assign a shortcut to this command
You can use the extension Regex Text Generator. You write a Regular Expression that generates your needed text
Type the following in the Generate Box
foobar = "1{16}";

In VS Code is the an opposite command from join lines? Like, expand lines?

How to expand a line of code? For example join lines command will do this
before
{
a: 123,
b: 321
}
after
{ a: 123, b: 321 }
And I need to do the opposite,
from this
{ a: 123, b: 321 }
to this
{
a: 123,
b: 321
}
Is there a way to do it? Maybe a plugin? Thanks.
Using the example you provided you could use the splitline plugin
https://marketplace.visualstudio.com/items?itemName=chenzhe.split-line
I noticed the example you provided wasn't valid JSON (missing quotes). If it was, or was any other valid type of code you could use the built VS code code formatter:
Press Ctrl/Cmd + Shift + p
Select >Format Document
if you want to do that for JSON file it is doable
select the text and then hit ctrl-shift-F then VS code will format the json object automatically.
Very late but maybe useful to others.
There is also the option to format the selection based on the filetype's default formatter.
Select your code and then emit the command >Format Selection
If you want you can set a personal hotkey to Format Selection in the keyboard shortcuts.
Hint: To open the command prompt enter one of the following commands:
F1
Ctrl + Shift + p
Whether or not the formatter will output it in your desired format is questionable but maybe there's a way to customize that.
If you use a code editor that is setup to 'format on save' you can easily go between joining lines and expanding lines by formatting.
For instance vscode 'join lines' command that you can do by selecting text and then cmd+j will make all code to one line.
If you say have a formatter for whatever language you are writing you just format on save or call format from the command pallet.
My use case was JavaScript bookmarklets, which need to be one line, but I didn't want to write my code that way, so I just 'join lines' then format to edit or save outside the bookmarklet context.

Copying variable contents to clipboard while debugging in Visual Studio Code

I'm debugging in Visual Studio Code and I have a JSON object that I would like to copy as text to the clipboard.
Is this possible inside of Visual Studio Code?
I found two ways to do that, both of which are a bit hacky (in my eyes).
Use console.log
I think there will be a limit to the size of the string that this can output, but it was satisfactory for my requirements.
In the debug console, write console.log(JSON.stringify(yourJsonObject))
Copy the resulting output from the debug console. That can be a bit tedious for long strings, but a combination of mouse and keyboard (ctrl-shift-end) worked ok for me.
Use a watch (limited to 10'000 characters)
This method only works up to a limited size of the resulting json string (it looks like 10'000 characters).
Set a breakpoint in a reasonable location where your variable is in scope and start your app.
Go to the debug view, add a watch for a temporary variable, e.g. tmpJson
Get your breakpoint to hit.
In the debug console, write var tmpJson = JSON.stringify(yourJsonObject)
This will now have populated the watched variable tmpJson with the string representation of your json object
In the debug view, right click on the watched variable, click copy.
If the string is too long, it cuts it off with a message like the following:
...,"typeName":"rouParallel","toolAssembly":{"id":"ASKA800201","description":"CeonoglodaloD50R6z5","c... (length: 80365)"
But it would work for smaller objects. Maybe this helps some people.
It would be great to have this properly built-in with vscode.
There is an open issue regarding this: https://github.com/microsoft/vscode-java-debug/issues/624
Workaround :
Go to the VARIABLES panel and right click to show contextual menu on a variable
select Set Value
Ctrl+C
(tested on Java, not JavaScript)
I have an easy workaround to copy anything you want:
In the debug console, write JSON.stringify(yourJsonObject)
Copy the string without the double quotes " around the string
Open a browser, such as Chrome, open the inspecting tool, go on the console and write:
copy(JSON.parse("PASTE_THE_STRING_HERE"));
The object is now copy on your keyboard !
If you are debugging Python:
In the DEBUG CONSOLE type, for example:
import json
from pprint import pprint as pp
pp(json.dumps(outDetailsDict))
OUTPUT IS LIKE
{"": {"stn_ix": 43, "stn_name": "Historic Folsom Station (WB)", "name": "", },
...
The fastest way I found to do that on Visual Studio Code was
Adding a breakpoint where is located the object to copy
Right click on object and choose "Add to Watch"
From Watch sidebar, choose option "Copy Value" and it's all! 🎉
Note: this solution seems to work for longer values but not very long values. This answer suggests a 10,000 char limit and uses JSON.stringify(myvar) instead of just str(). On char limit, see also this comment below.
Tested in python debugger
Add the variable to Watch, but converted to string
str(myvar)
Right-click on the value of the watch, and select Copy Value
Now you should get the full value (but not for very long values. See note above).
(var name blurred out):
If you're in debug mode, you can copy any variable by writing copy() in the debug terminal.
This works with nested objects and also removes truncation and copies the complete value.
Tip: you can right click a variable, and click Copy as Expression and then paste that in the copy-function.
While the question presumably deals with JavaScript (JSON) based technologies, many people have posted Python-related posts in this thread. So I'll post a more specific answer for Python, although the reasoning can be extended with some tweaks to JavaScript-based technologies. 😊
Helper strategies for debugging with VSCode
Copying variable FULL VALUE (not truncated) to clipboard while debugging even for very long values and other additional strategies.
1 APPROACH: Access the "Run and Debug" screen and look for the "WATCH" area and double click inside it. Add something like str(<MY_VAR>) which should be the variable you want to find the value of during the debug process;
2 APPROACH: Access the "DEBUG CONSOLE" tab and in the footer (symbol ">") copy and paste the code below or another one of your choice...
def print_py_obj(py_obj, print_id="print_py_obj"):
"""Prints a Python object with its string, type, dir, dict, etc...
Args:
py_obj (Any): Any Python object;
print_id (Optional[str]): Some identifier.
"""
print(" " + str(print_id) + \
" DEBUG >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
print(" 0 STR >>>>>>>>>>>>>>>>>>>>>>>>")
print(str(py_obj))
print(" 0 <<<<<<<<<<<<<<<<<<<<<<<<")
print(" 1 TYPE >>>>>>>>>>>>>>>>>>>>>>>>")
print(type(py_obj))
print(" 1 <<<<<<<<<<<<<<<<<<<<<<<<")
print(" 2 DIR >>>>>>>>>>>>>>>>>>>>>>>>")
print(str(dir(py_obj)))
print(" 2 <<<<<<<<<<<<<<<<<<<<<<<<")
print(" 3 DICT >>>>>>>>>>>>>>>>>>>>>>>>")
try:
print(vars(py_obj))
except Exception:
pass
print(" 3 <<<<<<<<<<<<<<<<<<<<<<<<")
print(" " + str(print_id) + \
" DEBUG <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
print_py_obj(profit, "<MY_VAR_OPTIONAL_IDENTIFIER>")
NOTE: We may have a 10,000 character limitation for both approaches.
Thanks! 🤗🐧🐍
Yup ! That's very much possible
Select breakpoint near your json variable.Debug.
screnshot . Right click on json body and copy value.That's it.
On the selected breakpoint, go to the Debug Console and print(variable)

How to open a tab containing the provided string in Visual Studio Code

I'm working on an extension for Visual Studio Code, and I want to open a new tab containing some text I'll provide. I thought of using vscode.window.showTextDocument but it takes a TextDocument as input and I can't find how to create a TextDocument from a provided string. Any help?
I don't believe VSCode allows the creation of TextDocuments from strings. One way of obtaining a TextDocument is to create a temporary file from the provided string, possibly in your extensions directory so that the user isn't bothered by it, and then use the openTextDocument method on the file, which would return a TextDocument.

Is there a way to run an insert into statement with a valid "?" in it?

I am trying to build an insert into statement that will include a URL string which has a valid "?" in it. I am using Teradata SQL Assistant (Windows XP) and it is trying to translate this into a parameter.
Is there any way to override this and treat it as a character value?
Example URL:
https://www.location.com/livelink.exe?func=ll
Go to the Query tab on the Tools -> Options... page and uncheck the box labeled "Allow use of Named Parameters in queries". Here are the settings I use:
That will prevent question mark from being treated as prompts and process an insert statement like this:
insert into yourdb.yourtable
(url)
values ('https://www.location.com/livelink.exe?func=ll')