User Script replacing all instances of a string instead of specific instances - userscripts

I've been learning about user scripts and I've been messing around with Joe Simmon's Script when I came across a problem. Say for example that I have a webpage that says 'I want to go to a park.' If I want to replace 'a' with 'the', it would produce 'I wthent to go to the ptherk.' instead of 'I want to go to the park.' Is there any way to change to code so that it would replace the instances of 'a' where it is a word by itself instead of every instance of a in every string. And can you explain what you are doing so that I may learn. Thanks.

That code has an example: '/\\bD\\b/g' : '[D]', the symbol \\b denotes a word boundary.
You'll need '/\\ba\\b/g' : 'the' and '/\\bA\\b/g' : 'The'.

Related

LogicApp Split and Replace having problems with \n

I have been trying to split a string into an array of each line \n
As this doesn't work I tried replacing replace(outputs('Compose_6'),'\r\n','#') with a view to then splitting on #.
I have searched the internet and tried various things but nothing seems to work.
Can someone explain how to do this?
Thanks in advance
Using split(variables('string var'),'\n') expression, you can split string into array. By default logic app will add an extra black slash to original back slash. So suggesting you to change expression in code view as mentioned above.
I have created logic app as shown below,
In first initialize variable action, taken a string variable with text as shown below
Hello
Test split functionality
Using logic apps
Next initialize variable action, using a array variable and assigning value using expression as split(variables('string var'),'\n'). Make sure you dont have double back slash added in code view. Only one back slash should be there when you see it in code view.
Code view:
The output of logic app can be shown below,
Refer this SO thread.

Can't get Logic App Contains to work with array or comma separated string

I'm trying to look for specific keywords inside of text from a for each loop.
var text = "The lazy fox jumped over the brown dog."
var keywords = "fox,dog,sun";
If true, I want to do something with the text. If false, I want to ignore the text.
Does anyone know how to use an Array filter, Function, Select, Condition or inline code to check for this? If so, specific examples would be great.
By the way, I have a C# function that handles this extremely well in an ASP.net Core app.
UPDATE 1:
This doesn't work.
UPDATE 2:
The Condition is always false after the for each loop even after changing the settings and parallelism to 1.
Azure Logic App Condition does not work in loop if based on changing values
Thanks in advance!
There are so many ways to achieve what you need. Here are the 3 options that came to my mind within a minute.
The first one does use a For each loop, but I wouldn't recommend using it as it's not very efficient.
The For each parameter looks like this:
The Condition parameter looks like this:
The second option is much easier - no need for a loop, just filter the array straight away, then you can check whether it's empty or it has some items:
The Filter array parameters look as follows.
The split function is identical to the one used in option 1.
If you know JavaScript, you might decide to use regular expressions in inline code instead, e.g.:
Then you'd just need to check the output of the inline code. JavaScript code used in the example above:
var text = workflowContext.actions.Compose_text.outputs;
var keywords = workflowContext.actions.Compose_keywords.outputs;
return text.match(new RegExp("(" + keywords.split(",").join("|") + ")", "gi"));
My personal preference is option 2. However, please note that all 3 options above would find "sun" in text "The weather was sunny" even though there's no word "sun" in the text. If you do need "sun" to match only word "sun" - not "sunny", "asunder" or "unsung" - then go for option 3, just use a different, more complex regular expression.
One of the workaround would be use of Condition Connector. I have initialized the sentence in a string and then used Condition Connector which will be checking the conditions.
Finally, In the true section you can add the connectors accordingly.
Placing a Compose behind the for each loop and referencing the Output in the Condition is what finally worked for me. I used the toLower() function in my Compose. The Compose looks like this.
toLower(items('For_each_2')?['day']?['longPhrase'])

How to verify words one by one on a locator in Robot Framework?

I am still a bit new to the robot framework but please rest assured I am constantly reading its User Guide. I am a bit stuck now with one test case.
I do have a list of individual words, that I need to verify on a page, mostly German translations of field labels if they appear correctly or are found in an element at all.
I have created a list variable as follows:
#{GERMAN_WORDS} | Benutzer | Passwort | Sendung | Transaktionen | Notiz
I have the following locator that contains the text labels on the webpage, and the one I need to verify:
${GENERAL_GERMAN_BOARD} |
xpath=//*[#id="generalAndIncidents:generalAndIncidentsPanel"]
I would like to check every single word one by one from the list variable, whether they are present in the locator above.
I did create the following keyword for this purpose, however I might be missing something because it calls the entire content of my list variable, instead of checking the words from it one by one:
Block Text Verification
[Arguments] ${text_list_variable} ${locator_to_check}
Wait Until Element is Visible ${locator_to_check}
FOR ${label} IN ${text_list_variable}
${labelTostring} Convert to String ${label}
${isMatching} = Run Keyword and Return Status Element Should Contain ${locator_to_check} ${labelTostring}
Log ${label}
Log ${isMatching}
Exit For Loop If '${isMatching}' == 'False'
END
I am getting the following output for this:
Element
'xpath=//*[#id="generalAndIncidents:generalAndIncidentsPanel"]' should
have contained text '['Benutzer', 'Passwort', 'Sendung',
'Transaktionen', 'Notiz']' but its text was.... (and it lists all the
text from my locator)
So, it is basically not checking the words one by one.
Am I doing something wrong here? Is this a bad approach I am trying to do here?
I would be grateful if anyone could provide me some hint on what I should do here instead!
Thank you very much!
You've made one small but crucial mistake - the variable in this line here:
FOR ${label} IN ${text_list_variable}
, should be accessed with #:
FOR ${label} IN #{text_list_variable}
The for-in loops in RF expect 1 or more arguments of the looped over values, and the # expands a list variable to its members.

How would I check If a role has a certain word in it discord.js

I have this code so far which does not work.
if (member.roles.cache.some(role => role.name.includes === 'Gang‏‏‎ ‎'))
basically I have like 9 different roles that all have the word gang in them and instead of checking if a user has each role individually I want to check if they have any of the roles all at once. since it will save space and be less of a headache. is there any way to do this effectively? I'm open to all answers, thanks for the help.
The includes method is defined on the string prototype and takes the search string as argument (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes).
While your current code compares that method to the string literal 'Gang ' you instead want to provide the search string as an argument like this: role.name.includes('Gang‏‏‎ ‎')

Fitnesse Slim: How to concatenate symbol

How would one concatenate a symbol with text on either side?
For example:
Prefix: "GAR_"
Variable: $todayDate
Suffix: "_1"
GAR_$todayDate_1
Which would evaluate to:
GAR_07202012_1
When running the test in fitnesse, it seems as though the concatenation is working (GAR_$todayDate->[07202012]_1). However, I am passing this value as a parameter to visual studio and I instead end up with the following text: GAR_$todayDate_1.
When I remove the suffix or put a space between $todayDate and "_1", everything works as expected.
Any help would be appreciated.
Things I have tried:
GAR_!-$todayDate-!_1
GAR_$todayDate!-_1-!
GAR_$todayDate${SUFFIX} - static variable defined
Thanks,
Mike
I am stuck with the same problem currently.
The only way I found was to:
create a StringSupport class with a String concatenate(String s1, String s2) method
import the package of that class in your FitNesse test
put StringSupport in the available libraries in your FitNesse test with the Library table
in your Script, you can now do: |$result=|concatenate;|$s1|$s2|
To fit your exact use case, you just have to do the same concatenate() with 3 strings instead of just one.

Resources