Performing wildcard operations on table containing duplicate elements in karate? [duplicate] - ui-automation

This question already has an answer here:
Karate UI: How to click a specific checkbox with same class name
(1 answer)
Closed 1 year ago.
I am stuck with a case where the need is to click on an icon after asserting inputs from the user. In case there were some unique identifiers, the thing was pretty simple like the use of: rightOf('{}UniqueIdentifier').find('i').click() served the purpose.
Also working fine with: scroll('{}UniqueIdentifier').parent.children[4].click()
But in case the table contains repeated values nothing could be found unique to search for and click. For which the thought was to match entire row text where the last element is that icon which needs to be clicked OR any other method which suits this?
Table looks like this:-
Need to click on triple dot icon for- A2,P2,2,resolved. How can this be achieved using wildcard locators? I tried creating a list of elements and match it with user input list but failed doing so.
Any help would be appreciated. Thanks!

First you should get comfortable with locateAll(). It will return an array of Element objects. And after that there are many possible ways of looping over and finding what you want.
Also note that there is a "locateAll() with filter": https://github.com/intuit/karate/tree/master/karate-core#locateall-with-filter
Since you haven't provided any HTML I will have to guess. And note that x below is an Element and you can even call locate() on it.
* def filter = function(x){ x.text.contains('Unique Identifier') }
* def list = locateAll('.grand-parent-class', filter)
* list[0].parent.children[4].click()

Related

EPi find get all variants if search hit on product

A EPi find question coming up, We have WebProducts and WebVariants and when showing a simple product listing on the category page I'm showing the following result correctly
If a WebProduct doesn't have any variants - show the WebProduct on the result
If a WebProduct has variants - show the WebVariants and hide the WebProduct
But when I'm trying to use the same functionality for the site-search it gets complicated.
The WebProduct has a property named Brand while the WebVariants doesn't have that property. So when I search for "My brand" and I get a hit on a WebProduct that has WebVariants, it won't show the WebProduct because point 2 is true in that case.
I on the other hand don't want to show the product, but I want to get the variants for that product... It might sound confusing :grimacing:
I'll add a code snippet of the code that makes point 1 and 2 to work.
.SearchAndFilterFor(q)
.Filter(x =>
(x.MatchType(typeof(WebVariant))) |
(x.MatchType(typeof(WebProduct)) & ((WebProduct)x).HasVariants().Match(false)))```
I would say that you have a couple of options to choose from.
Either:
1: Change the way your variants are indexed so that they include some of the key info (in this case brand) that they currently lack and as such, appear in the search results.
OR
2: Just do the search for WebProduct and then loop through those results afterward to do the processing for ones that do/don't have variants.

Creating an array for multiple instances targeting IDs with non static members

I am trying to automate text boxes to fill with a certain value, however the text boxes names are not static so they will always change. I am looking to find a way to always populate them even though they do not have a static name and how to find the second, third, fourth etc instance of the boxes and be able to also fill them without overwriting the previous text boxes
i have tried using the _collect function in sahi pro but could not find how to target the class correctly
I expect to be able to populate any textbox using the same class name without overwriting the first instance of this class.
I am using Sahi pro.
The sahi documentation on _collect seems to be you exactly what you are looking for
// Collect all textboxes matching any identifier, in table "listing".
// Note the use of match all regular expression "/.*/"
var $textboxes = _collect("_textbox", "/.*/", _in(_table("listing"));
// Iterate and set values on all textboxes
for (var $i=0; $i<$textboxes.length; $i++) {
_setValue($textboxes[$i], "value");
}
If this does not solve your problem, please provide an example of the html and of your _collect code

yadcf autocomplete not working as in original examples

In the older examples of the AutoComplete filter, as soon as you typed in a letter the filtering was applied reducing the numbers of rows shown. For example, if I typed the letter "x", only rows with that column containing the letter "x" would be displayed.
{ column_number : 1, filter_type: "auto_complete" },
In the newer examples, the AutoComplete filter does not do this. I want the original functionality for my web page - how do I achieve this? Is there an option I need to pass to the AutoComplete plugin via the filter_plugin_options parameter? Or is there a different filter I should be using?
I can't recall that aytocomplete ever worked this way, you need to use the filter_type: 'text' instead, see the fourth column in the following showcase page
IMO triggering the filter on each keyboard type fits better the text filter rather then autocomplete

How to use Parameter field in a record selection "like" statement?

I have designed a report to pull data fields based on a record selection formula that uses a "like" operator that looks for a substring match in a particular field's data, as so:
{rct.serno} like "*9842*"
(due to the free-format way data is stored in the given field, I have to do a substring match to find the relevant rows in the DB.)
This works fine. Instead of manually editing the record selection formula every time, though, I thought to use a Parameter field ("{?TagNum}") to prompt the user for the desired string, and then use that in the record selection formula like:
{rct.serno} like "*{?TagNum}*"
Crystal does not throw an error when I save this record selection formula, but it does not return any records after the report is refreshed, and a parameter value is entered. How can I properly use the parameter value in a record selection substring match?
You're really close to the solution. You can modify the formula in the Select Expert. Just click the Select Expert icon (or from the Report menu). Then click the Formula Editor button. Concatenate or add an asterisk onto the beginning and end of the parameter using the + operator, like this:
{Customers.LastName} like "*" + {?pLastName} + "*"
Let me know if that helps.
~ Nathan

cakephp empty option for select fields

I am stumped beyond belief.
I have a select box being generated by the cakephp form helper. I am feeding it an array of options, and passing an empty value... pretty standard stuff.
However, my "empty" field is showing up at the very bottom of the list.. not the top. So when the field loads, it just defaults to the first option... which is not the "empty" option.
Not a whole lot of room for error on the code here..
echo $this->Form->input('whatever',array('empty'=>'Choose One','options'=>$categories));
The only small item that might be important, is that $categories is a multi-array, so the select box has optgroups & options.
Is there some quirk/bug out there that I do not know of that is trying to force me to sneak into my scotch supply a few hours ahead of schedule?
edit: using the latest release of cakephp 1.3.x
I think that I once had the same problem.
It turned out to be the data (options array).
Is there an option with an empty key? probably the last one then.
this lead to the scenario I remember and seems to be the exact same thing.
the form helper will override this empty key value pair then and not create a second one.
without more infos from your end this will be difficult to solve.