get text with index number and then compare with the expected text - ruby

I need to write a method which will get text with the help of index number from popup and then i need to compare with the expected text
i.e i need to verify expected plan name is displayed at the bottom of the popup box

Setting the correct id for the query (which you can get by doing on calabash console the command query("*", :id)) on code below should do the trick. If you can't use id try to get another component property (like Android component by using query("*") ) and set the query inside theget_text calls.
def get_text(query)
query(plan_query, :text).first
end
def text_equals(text, expected_text)
unless text == expected_text
fail "#{text} not equal to #{expected_text}"
end
end
def verify_plan(index, expected_text)
plan_text = get_text("* id:'PLAN_TEXTS_ID' index:#{index}") # Can change 'id:...'' by Android class if plan does not have id
expected_text = get_text("* id:'BOTTOM_PLAN_ID'") # Same as above
text_equals(plan_text, expected_text)
end

Related

vars.put function not writing the desired value into the jmeter parameter

Below is the code which i have been trying to address the below UseCase in JMETER.Quick help is appreciated.
Usecase:
A particular text like "History" in a page response needs to be validated and the if the text counts is more than 50 a random selection of the options within the page needs to be made.And if the text counts is less than 50 1st option needs to be selected.
I am new to Jmeter and trying to solve this usingJSR223 POST processor but somehow stuck at vars.put function where i am unable to see the desired number being populated within the V paramter.
Using a boundary extractor where match no 1 should suffice the 1st selection and 0 should suffice the random selection.
def TotalInstanceAvailable = vars.get("sCount_matchNr").toInteger()
log.info("Total Instance Available = ${TotalInstanceAvailable}");
def boundary_analyzer =50;
def DesiredNumber,V
if (TotalInstanceAvailable < boundary_analyzer)
{
log.info("I am inside the loop")
DesiredNumber = 0;
log.info("DesiredNumber= ${DesiredNumber}");
vars.put("V", DesiredNumber)
log.info("v= ${V}");
}
else{
DesiredNumber=1;
log.info("DesiredNumber=${DesiredNumber}");
vars.put("V", "DesiredNumber")
log.info("v= ${V}");
}
def sCount = vars.get("sCount")
log.info("Text matching number is ${sCount_matchNr}")
You cannot store an integer in JMeter Variables using vars.put() function, you either need to cast it to String first, to wit change this line:
vars.put("V", DesiredNumber)
to this one
vars.put("V", DesiredNumber as String)
alternatively you can use vars.putObject() function which can store literally everything however you will be able to use the value only in JSR223 Elements by calling vars.getObject()
Whenever you face a problem with your JMeter script get used to look at jmeter.log file or toggle Log Viewer window - in absolute majority of cases you will find the root cause of your problem in the log file:

Putting Faker Gem Values to a Hash

I'm writing automated tests using Cucumber, Capybara, WebDriver, SitePrism, and Faker. I am new to this and need some help.
I have the following steps..
Given (/^I have created a new active product$/) do
#page = AdminProductCreationPage.new
#page.should be_displayed
#page.producttitle.set Faker::Name.title
#page.product_sku.set Faker::Number.number(8)
click #page.product_save
#page.should have_growl text: 'Save Successful.'
end
When (/^I navigate to that product detail page) do
pending
end
Then (/^All the data should match that which was initially entered$/) do
pending
end
In config/env_config.rb I have set up an empty hash...
Before do
# Empty container for easily sharing data between step definitions
#verify = {}
end
Now I want to hash the value generated by Faker in the Given step so I can validate it saved properly in the When step. I also want to enter the value generated by faker in the script below into a search field.
#page.producttitle.set Faker::Name.title
How do I push the values generated by faker to the #verify has?
How do I pull that value and insert it into a text field?
How do I pull that value to verify the save value equals the value generated by faker?
1. How do I push the values generated by faker to the #verify has?
A hash is simply a dictionary of key-value pairs, which you can set with hash[key] = value.
The key can be a string #verify['new_product_name'] = Faker::Name.title
The key can also be a symbol #verify[:new_product_name] = Faker::Name.title
Since the value you generate may be used multiple times within the step definition (once for storing it in the #verify hash, and once for setting the field value) I personally prefer to first store it in a local variable, and reference that where needed.
new_product_title = Faker::Name.title
#verify[:new_product_title] = new_product_title
2. How do I pull that value and insert it into a text field?
You can reference values by their key. So after you have stored the value in the hash, you could do this
#page.producttitle.set #verify[:new_product_name]
Or if you stored it in a local variable as suggested above, you would just do this
#page.producttitle.set new_product_name
3. How do I pull that value to verify the save value equals the value generated by faker?
Similarly, you can assert that a field value equals what you've stored in the hash. An example would be #page.producttitle.value.should == #verify[:new_product_name]
Putting this all together:
Given (/^I have created a new active product$/) do
#page = AdminProductCreationPage.new
#page.should be_displayed
# Create a new title
new_product_title = Faker::Name.title
# Store the title in the hash for verification
#verify[:new_product_title] = new_product_title
# Set the input value to our new title
#page.producttitle.set new_product_title
#page.product_sku.set Faker::Number.number(8)
click #page.product_save
#page.should have_growl text: 'Save Successful.'
end
When (/^I navigate to that product detail page) do
pending
end
Then (/^All the data should match that which was initially entered$/) do
#page.producttitle.value.should == #verify[:new_product_title]
end

Getting model value and generated ID from within simple_form custom input

I'm trying to make a custom input type with simple_form that will implement combobox-type functionality using jQuery-Autocomplete
. What I need to do is output a hidden field that will hold the ID of the value selected and a text field for the user to type in.
Here's what I have so far:
class ComboboxInput < SimpleForm::Inputs::Base
def input
html = #builder.hidden_field(attribute_name, input_html_options)
id = '' #what?
value = '' #what?
return "#{html}<input class='combobox-entry' data-id-input='#{id}' value='#{value}'".html_safe
end
end
I need to get the ID of the hidden field that simple_form is generating to place as an HTML attribute on the text entry to allow the JavaScript to "hook up" the two fields. I also need to get the value from the model to prepopulate the text input. How do I do this from within my custom input?
I'm looking for the id as well, but I did get the value:
def input
current_value = object.send("#{attribute_name}")
end
I just found a hokey id workaround:
html = #builder.hidden_field(attribute_name, input_html_options)
id = html.scan(/id="([^"]*)"/).first.first.to_s
I know it's a hack, but it does work. Since we don't have access directly to this type of resolution, it is likely to keep working even if the underlying id creation code changes.

Why does ::TableView.model return nilClass when Nokogiri is used?

EDIT
The problem was with something else so the trouble wasn't really Qt, still I don't know why this happened.
The thing was that in the method display_filesize #yt.get_filesize(row_id, format) I used Nokogiri to parse the XML. I don't know if the XML was corrupted (it was loaded from quvi), but it was definitely the culprit. After switching to XMLSimple everything works fine.
The code I used:
def get_filesize(video_id, format)
video = #videos[video_id]
if video.formats[format].empty?
to_parse = `quvi --xml --format #{format} #{video.player_url}`
parsed = Nokogiri.parse(to_parse)
video.formats[format] = { :size => parsed.at('length_bytes').text,
:url => parsed.at('link').at('url').text }
end
video.formats[format][:size]
end
Now I use something like this:
def get_filesize(video_id, format)
video = #videos[video_id]
if video.formats[format].empty?
to_parse = `quvi --xml --format #{format} #{video.player_url}`
parsed = XmlSimple.xml_in(to_parse, {'KeyAttr' => 'name'})
video.formats[format] = { :size => parsed['link'][0]['length_bytes'][0],
:url => URI.decode(parsed['link'][0]['url'][0]) }
end
video.formats[format][:size]
end
It works beautifully. Still, I don't know why it crashed. This is the real question.
OLD QUESTION
I have a Qt::TableView that contains Qt::StandardItemModel. A row in the model consists of text, Qt::PushButton, checkbox and Qt::ComboBox. It works like this:
The user is presented with text values and can explore further if they want to.
The user clicks Qt::PushButton and the next cell is populated with a Qt::ComboBox containing other possible values to choose from.
If the user chooses an option from Qt::ComboBox, magic happens, objects get created, hashes populated and the cell on the right gets populated with appropriate text (through a Qt::StandardItem)
Then the checkbox can be checked.
After selecting the rows the user wants, a Qt::PushButton located outside of the Qt::TableView can be clicked. It then iterates through the model, tests if the checkbox is selected and should it be, tries to access the value in the appropriate ComboBox.
The problem is, when I insert code that tries to access the Qt::ComboBox, I can't insert the Qt::StandardItem, because I can't get the model, because Qt::TableView.model returns NilClass (at some point).
I don't know why and how this happens. It's a random thing, sometimes the value of Qt::ComboBox can be changed a couple times, sometimes the first try ends with an error.
Here is how I create the Qt::StandardItem:
def display_filesize
row_id = row_id_from_object_name(sender.objectName)
format = sender.currentText
filesize = #yt.get_filesize(row_id, format) # get the text
filesize_item = Qt::StandardItem.new("#{(filesize.to_i/1024/1024)} MB ")
# #tc simply stores the indexes of columns so I can access them easily
#ui.tableView.model.setItem(row_id, #tc[:filesize], filesize_item)
end
And here is how I try to access the Qt::ComboBox value:
model = #ui.tableView.model
checked = model.rowCount.times.map do |i|
if model.item(i, #tc[:check]).checkState == Qt::Checked
# if I remove the following two lines it works...
index = model.index(i, #tc[:formats])
format = #ui.tableView.indexWidget(index).currentText
#yt.videos[i][format]
end
end
And this is the error I am trying to get rid of:
searcher.rb:86:in `display_filesize': undefined method `index' for nil:NilClass (NoMethodError)
from /var/lib/gems/1.9.1/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:469:in `qt_metacall'
from /var/lib/gems/1.9.1/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:469:in `method_missing'
from /var/lib/gems/1.9.1/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:469:in `exec'
from qutub-player.rb:17:in `<main>'

Using a user defined variable within a function? (Ruby, Watir)

I'm creating drag and drop feature that depends on upon ID for placement, it works perfectly fine, but I need the status of task to be user defined so the user will have control of where something will be dragged as each section is uniquely named.
getID refers to getting the reference id of a Div.
I'd then concatenating with a "_" as well as adding the user set word
Class:
def addtask
dropTask = #browser.div(:id => getID+"_"+"##{statusOfTask}")
dragTask = #browser.div(:id, "footer").span(:class, "headerDrag")
dragTask.drag_and_drop_on dropTask
end
User Script:
statusOfTask = ["Ready"]
addtask()
Any ideas?
You just need to pass the desired status text to the addTask() method.
Class (add statusOfTask as a parameter):
def addtask(statusOfTask)
dropTask = #browser.div(:id => getID+"_"+"##{statusOfTask}")
dragTask = #browser.div(:id, "footer").span(:class, "headerDrag")
dragTask.drag_and_drop_on dropTask
end
User Script (pass in the first (or desired) value of statusOfTask):
statusOfTask = ["Ready"]
addtask(statusOfTask[0])

Resources