I need to loop a string (split by ',') and get each element passed to the feature files automatically. I know there is excellent support for json array data-driven test, but does it support data-driven with normal strings or string array
As I know, I need to get it converted to a json array to support data-driven test at runtime, however, I want to know any existing support for normal array looping directly and automatically.
Here is my string(separated by ',') that needs to get passed as request parameter:
"PHE,TSH,17_a_OHP,G6PD,MSMS,THALASSEMIA,DGT"
Because my string is dynamically produced at runtime, I want to loop it automatically and pass to other feature files, not manually,
Note that converting arrays into other "shapes" is easy in Karate. And in 0.9.3 we introduced the karate.mapWithKey() API, so you can do this:
* def string = 'PHE,TSH,17_a_OHP,G6PD,MSMS,THALASSEMIA,DGT'
* def array = string.split(',')
* def list = karate.mapWithKey(array, 'name')
* print list
So you can see, list is ready to use for data-driven features. Also note that you can use this in dynamic scenario outlines !
Related
In our lucene .net based search (Lucene 4.8.0-beta00016) we save the generated query, the filter and the sorting in a custom text file.
e.g.:
"Query":"+name:*test*"
"Filter":"BooleanFilter(+type:project)"
"Sort":"<long: \"creationdate\">!"
We built a test tool, similiar to Luke and we want to execute this saved search there and run a programmatic search:
For the query I can use the QueryParser and get the corresponding query object, but there seems to be no parser for the filter and the sort.
var queryParsed = new QueryParser().Parse("+name:*test*");
var filter = ?
var sort = ?
indexSearcher.Search(queryParsed, filter?, 10000, sort?);
Is there any way I can parse the filter and sort strings to a Filter/Sort object ?
Have you ever thought to serialize your custom file in a different way?
I'm guessing your file is generated by calling the toString() method of each object type. Something like the follow
"Query:" + queryObject.toString()
"Filter:" + filterObject.toString()
"Sort:" + sortObject.toString()
If you serialize your original query, filter, and sort .NET objects as binary strings, in your test tool, you should be able to re-create the original .NET objects.
Look at https://learn.microsoft.com/en-us/dotnet/standard/serialization/
I need to loop a string (split by ',') and get each element passed to the feature files automatically. I know there is excellent support for json array data-driven test, but does it support data-driven with normal strings or string array
As I know, I need to get it converted to a json array to support data-driven test at runtime, however, I want to know any existing support for normal array looping directly and automatically.
Here is my string(separated by ',') that needs to get passed as request parameter:
"PHE,TSH,17_a_OHP,G6PD,MSMS,THALASSEMIA,DGT"
Because my string is dynamically produced at runtime, I want to loop it automatically and pass to other feature files, not manually,
Note that converting arrays into other "shapes" is easy in Karate. And in 0.9.3 we introduced the karate.mapWithKey() API, so you can do this:
* def string = 'PHE,TSH,17_a_OHP,G6PD,MSMS,THALASSEMIA,DGT'
* def array = string.split(',')
* def list = karate.mapWithKey(array, 'name')
* print list
So you can see, list is ready to use for data-driven features. Also note that you can use this in dynamic scenario outlines !
I'm using noflo and am trying to send an array as an initiallizer. There doesn't seem to be a supported (or at least documented) way to do this.
I'm currently using:
'["Kicker"]' -> IN Nodes(strings/ParseJson)
'{"in":"go!"}' -> IN Config(strings/ParseJson)
Nodes() OUT -> NODES MyComponent(noflotest/Universe)
Config OUT -> CONFIG MyComponent()
Is there a better way to do this?
Currently arrays and other complicated data structures are not supported in the .fbp syntax. There is a feature request about this.
Right now you have three options:
If FBP parser accepts your string (see the matching rules), you can first send it to the strings/ParseJson component to turn it to the appropriate data structure
Reading the value from a JSON or YAML file and passing it through the appropriate parser component
Converting your graph to the JSON graph format
I'm using Selenium client driver 2.4.0. When running tests using the WebDriverBackedSelenium object, e.g.
final FirefoxDriver driver = new FirefoxDriver();
selenium = new WebDriverBackedSelenium(driver, baseUrl);
how do I inject a Javascript array into my tests that can retain scope across different pages? That is, I want to create a JS var "myArray" that I can access (using selenium.getEval) when I open "http://mydomain.com/page1.html" but I can then reference when I open a different page ("http://mydomain.com/page2.html") within the same Selenium test.
Thanks, - Dave
I don't think it is possible out of box.
Workaround should work - add to the page some library that can deserialize from JSON (e.g. Dojo), use it to load an array definition to some JavaScript variable and before leaving page get it back, storing it out of scope request.
But I must say you have a kind of strange request - what are trying to do ?
You can do it with casting. Execute JavaScript to return an array. The JS array must contain only one type, which must be primitive.
For example, execute a script which returns an array of Strings:
ArrayList<String> strings = (ArrayList<String>) js.executeScript(returnArrayOfStrings);
If you need an array of any other type, you can build it from those strings. For example, if you need an array of WebElements, design your JS to return locators, and then iterate through, finding elements and building a new array:
ArrayList<String> xpaths = (ArrayList<String>) js.executeScript(getLocators);
ArrayList<WebElement> elements = new ArrayList<WebElement>();
for (String xpath: xpaths){
element = driver.findElement(By.xpath(xpath));
elements.add(element);
}
You have the Array in Java, so you can keep it in memory when your tests go to different pages and still reference the Java Array,
The only catch is, if your JS array is changing on the client side, your Java Array won't automatically update itself (the jsexecuter only returns once per execution), but that's not a big deal - instead of referencing the Java Array directly, you can access it via a getter which first executes the JS again to get a new Array, which you can use to replace the previous one, or merge them etc, before returning the new/updated array to your test code.
http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q=test&sl=en&tl=en&restrict=pr%2Cde&client=te
(replace test with your favorite keyword)
using this i want to write simple dictionary....
problem - api give json output how i get it using java?
Simple Parsing
Per default, JSON will just produce a nested graph of maps and lists. Here is an example of default parsing:
import org.svenson.JSONParser;
// assume json to be a JSON datasets as String
Object o = JSONParser.defaultJSONParser().parse(json);
o will now contain either a map or a list instance, depending on whether the first symbol in the JSON is '{' or '['.