I want to write script for a screen where there are two fields and I just want to test with different possibilities of values for those fields, whether it will navigate to further screen. But combinations of data to enter into these fields is too large. So can I import data from excel/any other file where my data is already stored?
Yes it is possible. You can acquire every data that you are able to acquire in a bash script. Write a script file that prints the desired information to the standard output. For example
#!/bin/bash
cat myfile
You can run this bash-script from UIAutomation and get the output of it with this command
var result = target.host().performTaskWithPathArgumentsTimeout(full_path_to_your_script, [""], 10);
Now your can use the output of your bash script:
element.setValue(result.stdout);
Refer fabe's answer here, https://stackoverflow.com/a/19016573/344798
Refer https://stackoverflow.com/a/20626488/344798
Related
I'm writing a mongo shell script that will delete some entries in an existing DB, and then reload entries with data from a CSV (which was originally a spreadsheet file).
I'm at the point where I need to read the CSV file to make the entries to be inserted into the collection, but I can't figure how to read the CSV file while only using the js script.
I know there are solutions (like this one) that shows how to use javascript with jquery to read the csv file, but I'm only using a js shell script file so those solutions aren't working for me.
This is what my mongo shell script looks like as of now:
printjson("Start");
// I will be deleting all entries, but for now only one.
printjson("Deleting Tag");
db.Tag.deleteOne({ name: "Tag Name" });
// Here is where I want to add entries from CSV into Mongo Colletion
// For now, I'm just inserting 1 with hard-coded data
printjson("Inserting Tag");
db.Tag.insertOne({
name: "Tag name",
description: "A tag used for testing",
});
// To verfiy the object was inserted
printjson("\nFinding Inserted Tag");
cursor = db.Tag.find({ name: "Tag name" });
while (cursor.hasNext()) {
printjson(cursor.next());
}
printjson("End.");
And I run it in my terminal with a command like this:
mongo mongodb://{{mycreds}}#{{address of existing mongo}}:27017/{{DB I want}}?authSource=admin script.js
How do I read a csv file in a js shell script?
What I really want is to insert the data in the csv file into my mongo collection. If there's a better way than reading the file, creating entries from data, and then inserting, I'd love to know.
Thank you for any assistance.
I started to write a scraper for the site to collect data on cars. As it turned out, the data structure can change, since the sellers do not fill all the fields, because of what there are fields that can change, and during the scraper as a result in the csv file, the values are in different fields.
page example:
https://www.olx.ua/obyavlenie/prodam-voikswagen-touran-2011-goda-IDBzxYq.html#87fcf09cbd
https://www.olx.ua/obyavlenie/fiat-500-1-4-IDBjdOc.html#87fcf09cbd
data example:
Data example
One approach was to check the field name with text () = "Category name", but I'm not sure how to correctly write the result to the correct cells.
Also I use the built-in Google developer tool, and with the help of the command document.getElementsByClassName('margintop5')[0].innerText
I brought out the whole contents of the table, but the results are not structured.
So, if the output can be in json format then it would solve my problem?
innerText result
In addition, when I studied the page code, I came across a javascript script in which all the necessary data is already structured, but I do not know how to get them.
<script type="text/javascript">
var GPT = GPT || {};
GPT.targeting = {"cat_l0":"transport","cat_l1":"legkovye-avtomobili","cat_l2":"volkswagen","cat_l0_id":"1532","cat_l1_id":"108","cat_l2_id":"1109","ad_title":"volkswagen-jetta","ad_img":"https:\/\/img01-olxua.akamaized.net\/img-olxua\/676103437_1_644x461_volkswagen-jetta-kiev.jpg","offer_seek":"offer","private_business":"private","region":"ko","subregion":"kiev","city":"kiev","model":["jetta"],"modification":[],"motor_year":[2006],"car_body":["sedan"],"color":["6"],"fuel_type":["543"],"motor_engine_size":["1751-2000"],"transmission_type":["546"],"motor_mileage":["175001-200000"],"condition":["first-owner"],"car_option":["air_con","climate-control","cruise-control","electric_windows","heated-seats","leather-interior","light-sensor","luke","on-board-computer","park_assist","power-steering","rain-sensor"],"multimedia":["acoustics","aux","cd"],"safety":["abs","airbag","central-locking","esp","immobilizer","servorul"],"other":["glass-tinting"],"cleared_customs":["no"],"price":["3001-5000"],"ad_price":"4500","currency":"USD","safedealads":"","premium_ad":"0","imported":"0","importer_code":"","ad_type_view":"normal","dfp_user_id":"e3db0bed-c3c9-98e5-2476-1492de8f5969-ver2","segment":[],"dfp_segment_test":"76","dfp_segment_test_v2":"46","dfp_segment_test_v3":"46","dfp_segment_test_v4":"32","adx":["bda2p24","bda1p24","bdl2p24","bdl1p24"],"comp":["o12"],"lister_lifecycle":"0","last_pv_imps":"2","user-ad-fq":"2","ses_pv_seq":"1","user-ad-dens":"2","listingview_test":"1","env":"production","url_action":"ad","lang":"ru","con_inf":"transportxxlegkovye-avtomobilixx46"};
data in json dict
How can I get the data from the pages using python and scrapy?
You can do it by extracting the JS code from the <script> block, using a regex to get only the JS object with the data and then loading it using the json module:
query = 'script:contains("GPT.targeting = ")::text'
js_code = response.css(query).re_first('targeting = ({.*});')
data = json.loads(js_code)
This way, data is a python dict containing the data from the JS object.
More about the re_first method here: https://doc.scrapy.org/en/latest/topics/selectors.html#using-selectors-with-regular-expressions
I have a csv file which has the input in the below format (It has no headers as first row):
India,QA,1200,
India,QA1,1201,
India,QA2,1202,
USA,Dev1,5580,
USA,Dev2,5580,
AUS,Dev3,3300,
AUS,Dev4,3301,
I have configured the CSV Data Set Config component and have given the respective path and variable name details. Snapshot below:
from the command line argument, i will be invoking the Jmeter jmeter.bat -t C:\Users\Dev\Desktop\JI\testscript.jmx -JCountry=Indiawhich also has a parameter called JCountry=India.
Now, I have to use this value (India) and then search the csv file's first column and if it matches, I need to send only those particular rows matching to the country name given from the cmd to the script.
I thought of using If Controller but how can I check the csv files first row and when there is a match, send those details to the script.
The easiest option would be dynamically generating a CSV file with only India lines
Add setUp Thread Group to your Test Plan
Add Test Action sampler to the setUp Thread Group (this way you won't have an extra result in .jtl file)
Add JSR223 PreProcessor as a child of the Test Action Sampler
Put the following code into "Script" area:
String country = props.get('Country')
def originalCsvFile = new File('C:/Users/Dev/Desktop/JI/JVMDetails/Details.txt')
def countryCsvFile = new File('C:/Users/Dev/Desktop/JI/JVMDetails/Country.txt')
countryCsvFile.delete()
originalCsvFile.eachLine {line ->
if (line.startsWith(country)) {
countryCsvFile << line
countryCsvFile << System.getProperty('line.separator')
}
}
Configure your CSV Data Set Config to use C:\Users\Dev\Desktop\JI\JVMDetails\Country.txt as this file will have only those lines which start with what you have defined as Country property
More information:
Apache Groovy - Why and How You Should Use It
Groovy Goodness: Working with Files
You need to loop through CSV, see example or other examples.
As the second example use in while condition the variable from CSV: ${Country} .
Inside loop you need to add If Controller with condition to compare country variable against country property:
${__jexl3("${__P{Country}" == "${Country}")}
Checking this and using __jexl3 or __groovy function in Condition is advised for performances
I'm working with sensor units outfield that spit out data in the form of native text files and have a database created with pre-defined tags. E.G mm, level, voltage. The text file I'm using is pretty unstructured with the data being on the right side of the header separated by semicolon delimiters.
I want to try and import the content into the database where each header matches the tag name and the values are inserted into that tag consecutively. I'm wondering if there's a possible solution or maybe even some tips on how i can achieve this?
Currently i have been working with PHP but haven't gotten to far, is it the best language to use for such a method? Or would javascript be preferred?
Text file is delimited by semicolons:
L;MINVi;Min voltage;V;PTi;Processor temperature;C;AVGVi;Average voltage;V;SDB;Network signal dB;dB;WL02;waterlevel 2m;cm;RSSI;Network signal indication;RSSI;OCi;Operating cycle;sec;SCNT;Satellites;;LAT;Latitude;deg;LON;Longitude;deg
S;170427000428;ERR;SERVER_LOGIN;+CME ERROR: Bad or no response from server
S;170427000428;ERR;FTP
S;170427000450;ALARM_SEND_OK
S;170427000510;WDT;GPS
D;170427000510;SCNT;0*T;LAT;0*T;LON;0*T
S;170427000518;ERR;SERVER_LOGIN;+CME ERROR: Bad or no response from server
S;170427000518;ERR;FTP
S;170427000647;ERR;SERVER_LOGIN;+CME ERROR: Bad or no response from server
S;170502171807;POWER_ON;ML-315;V2.7B1
S;170502171807;SYS_START;BHSDemo 5170991
D;170502171817;MINVi;3.66;PTi;25.8;AVGVi;3.71;WL02;2.86*A;OCi;9.95
S;170502171822;WDT;MODEM_INIT
D;170502171823;SDB;0*T;RSSI;0*T
S;170502171823;WDT;Network signal
database table Tag_data Structure
You can do like this
LOAD DATA INFILE '/yourtext.txt' INTO TABLE TABLENAME;
Your text will be pretty hard to explode every value with it's parameter because every single word end with ; so, first try to make your text file like parameter:value; or parameter=value; or parameter_value; then you can read the content of this file with this php function $content = file_get_contents("path/text_file_name.txt"); now the value of $content variable is equal to the entire text of your file hence, you can split this variable into an array with $splittedcontent = explode(";" , $content); every parameter:value is a parameter in this array like $splittedcontent[0] = parameter0:value0, $splittedcontent[1] = parameter1:value1 and so on, now you can use for loop throw this array and make what your need in you database..
I hope this will help you.
I need some help in understanding what to do next.
I need to write a web based search function to find medical records from an XML file.
The operator can enter either part or all of a patient name and Hit Search on the JSP web page.
The server is suppose to then return a list of possible patient names with the opportunity for the operator to go to next page until a possible patient is found. They can then select the person and view more details.
On the Server side
I have an XML file with about 100,000 records. There are five different types of records in the file. (This is roughly about 20,000 x 5 = 100,000).
I have a java class to source the xml file and create a DOM to traverse the data elements found on the file.
-- XML File Begin
100k - XML file outline
<hospital>
<infant key="infant/0002DC15" diagtype="general entry" mdate="2015-02-18">
<patient>James Holt</patient>
<physician>Michael Cheng</physician>
<physician>David Long</physician>
<diagnosisCode>IDC9</diagnosisCode>
..
</infant>
<injury key="injury/0002IC15" diagtype="general entry" mdate="2015-03-14">
<patient>Sara Lee</patient>
<physician>Michael Cheng</physician>
<diagnosisCode>IEC9</diagnosisCode>
..
</injury>
<terminal key="terminal/00X2IC15" diagtype="terminal entry" mdate="2015-05-14">
<patient>Jason Man</patient>
<physician>John Hoskin</physician>
<diagnosisCode>FEC9</diagnosisCode>
<diagnosisCode>FXC9</diagnosisCode>
..
</terminal>
<aged key= xxxx ... >
...
</aged>
<sickness key= xxxx ... >
...
</sickness>
</hospital>
approx 5 ( )x 20,000 = 100K records.
Key and patient are the only mandatory fields. The rest of the elements are Optional or multiple elements.
-- XML File End
Here is where I need help
Once I have the DOM how do I go forward in letting the client know what was found in the XML file?
Do I create a MAP to hold the element node links and then forward say 50 links at a time to the JSP and then wait to send some more links when the user hits next page?
Is there an automated way of displaying the links, either via a Java Script, Jquery, XSLT or do I just create a table in HTML and place patient links inside the rows? Is there some rendering specific thing I have to do in order to display the data depending on the browser used by client?
Any guidance, tutorials, examples or books I can refer to would be greatly appreciated.
Thank you.
I don't know an automatic way to match the type in jQuery, but you can test the attributes, something like verify if a non optional attribute in the object is present:
// Non optional Infant attribute
if(obj.nonOptionalAttribute) {
// handle Infant object
}
Or you may add an attribute to differentiate the types (something like a String or int attribute to test in your Javascript).
if(obj.type == 'infant') {
// handle Infant object
}
#John.west,
You can try to bind the XML to a list of objects (something like Injure implements MyXmlNodeMapping, Terminal implements MyXmlNodeMapping, Infant implements MyXmlNodeMapping and go on and have a List) to iterate and search by the value at the back end or you can pass this XML file to a Javascript (if you are using jQuery you can use a get or a post defining the result type as XML) and iterate over the objects to find what the user is trying to find...
Your choice may be based on the preference to use processor time in the server side or in the client side...