I am trying to test my application with cucumber and capybara.
I have the following step definition:
Given(/^I fill in the create article form with the valid article data$/) do
#article_attributes = FactoryGirl.build(:article)
within("#new_article") do
fill_in('article_title', with: #article_attributes.title)
attach_file('article_image', #article_attributes.image)
fill_in('article_description', with: #article_attributes.description)
fill_in('article_key_words', with: #article_attributes.key_words)
fill_in('article_body', with: #article_attributes.body)
end
My article factory looks like this:
FactoryGirl.define do
factory :article do
sequence(:title) {|n| "Title #{n}"}
description 'Description'
key_words 'Key word'
image { File.open(File.join(Rails.root, '/spec/support/example.jpg')) }
body 'Lorem...'
association :admin, strategy: :build
end
end
And this is my uploader file:
# encoding: UTF-8
class ArticleImageUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
But each time i run this scenario i get ERROR message:
Given I fill in the create article form with the valid article data # features/step_definitions/blog_owner_creating_article.rb:1
cannot attach file, /uploads/article/image/1/example.jpg does not exist (Capybara::FileNotFound)
./features/step_definitions/blog_owner_creating_article.rb:5:in `block (2 levels) in <top (required)>'
./features/step_definitions/blog_owner_creating_article.rb:3:in `/^I fill in the create article form with the valid article data$/'
features/blog_owner_creating_article.feature:13:in `Given I fill in the create article form with the valid article data'
I also found that FactoryGirl returns image:nil when i run FactoryGirl.build(:article) in my rails test console.
Could anybody explain me what i am doing wrong,please?
You need to pass the path in directly:
attach_file('article_image', File.join(Rails.root, '/spec/support/example.jpg'))
What's happening here is that attach_file expects a string, not a CarrierWave uploader. When you pass it an uploader (#article_attributes.image), attach_file is calling Uploader#to_s, which calls Uploader#path. Since you haven't saved the article yet, the path at which the uploaded image will be located is invalid.
Note also that calling your variable #article_attributes is confusing, since it's actually a full article object, not just a hash. If that's what you want, you may want to try FactoryGirl.attributes_for(:article).
Related
I'm trying to update a plugin for Kodi 19 (and Python3).
But! Hell! Their documentation is a mess, and when you search the internet, a lot of code is outdated.
I cannot understand how correctly create a virtual folder with items using xbmcplugin.addDirectoryItems.
here's my (simplified) code:
this is my KODI menu function
def menu_live():
#this is were I get my datas (from internet)
datas = api.get_live_videos()
listing = datas_to_list(datas)
sortable_by = (xbmcplugin.SORT_METHOD_DATE,
xbmcplugin.SORT_METHOD_DURATION)
xbmcplugin.addDirectoryItems(common.plugin.handle, listing, len(listing))
xbmcplugin.addSortMethod(common.plugin.handle, xbmcplugin.SORT_METHOD_LABEL)
xbmcplugin.endOfDirectory(common.plugin.handle)
this builds a list of items for the virtual folder
def datas_to_list(datas):
list_items = []
if datas and len(datas):
for data in datas:
li = data_to_listitem(data)
url = li.getPath()
list_items.append((url, li, True))
return list_items
this create a xbmcgui.ListItem for our listing
def data_to_listitem(data):
#here I parse my data to build a xbmcgui.ListItem
label = ...
url = ...
...
list_item = xbmcgui.ListItem(label)
list_item.setPath(url)
return list_item
I don't understand well how to interact with the media url.
It seems that it can be defined within xbmcgui.ListItem using
list_item.setPath(url)
which seems ok to me (an url is set to the item itself)
but then, it seems that you also need to set the URL when adding the item to the list,
li = data_to_listitem(data)
list_items.append((url, li, True))
This looks weird since it means you have to know the URL outside the function that builds the item.
So currently, my workaround is
li = data_to_listitem(data)
url = li.getPath() #I retrieve the URL defined in the above function
list_items.append((url, li, True))
That code works. But the question is: if I can define an URL on the ListItem using setPath(), then why should I also fill that URL when appending the ListItem to my listing list_items.append((url, li, True)) ?
Thanks a lot !
I'm not exactly sure what your question is. But Video/audio add-on development is thoroughly explained in these guides: https://kodi.wiki/view/HOW-TO:Audio_addon, https://kodi.wiki/view/Audio-video_add-on_tutorial and https://kodi.wiki/view/HOW-TO:Video_addon. Have a look at them, especially the video-add-on guide (as pointed out by Roman), and try to adapt to your case.
Edit
But the question is: if I can define an URL on the ListItem using setPath(), then why should I also fill that URL when appending the
ListItem to my listing?
I'm far from an expert, but from my understanding and in the context of https://kodi.wiki/view/HOW-TO:Video_addon tutorial, the url in
list_items.append((url, li, is_folder))
is used to route your plugin to your playback function, as well as passing arguments to it (e.g. video url and possibly other useful stuff needed for playback). That is, the list item passed here doesn't need to have its path set.
ListItem.setPath(video_url)
on the other hand, is for resolving the video url and start the playback after you have selected an item.
I have a problem with Poltergeist. I can’t get the driver to locate a field on a page. What I want to do is to execute some js to make sure that the input field is empty before I start adding new text. I have a field with a label os "Skill list" and id of "user_skill_list". In order to make the step more generic I want to find the field by the label name and then get the id.
And(/^I delete the content of "([^"]*)"$/) do |label|
field_id = page.find_field(label).native.attributes['id'].value
page.execute_script("$('#{field_id}').val('');")
end
Here's the error message:
#javascript
Scenario: Update user by removing # features/godmin/skills.feature:36
Given "Thomas" skills are "rspec, testing" # features/step_definitions/godmin_steps.rb:63
And I click on "Edit" for "Thomas" # features/step_definitions/godmin_steps.rb:43
And I delete the content of "Skill list" # features/step_definitions/godmin_steps.rb:69
Unable to find field "Skill list" (Capybara::ElementNotFound)
./features/step_definitions/godmin_steps.rb:70:in `/^I delete the content of "([^"]*)"$/'
features/godmin/skills.feature:39:in `And I delete the content of "Skill list"'
```
My cucumber set up is pretty basic.
# features/support/env.rb
...
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
Capybara.default_max_wait_time = 5
...
Thank you. Please let me know if I should clarify my question.
Assuming your html is something like
<label for="user_skill_list">Skill list</label>
<input id="user_skill_list"/>
Then
page.find_field('Skill list').set('')
should find the field and clear it. If it's not finding the element there are a couple of possibilities.
The element isn't visible on the page
There is CSS being applied that is changing the case of "Skill list"
There are typos in your html so the label isn't actually associated with the field. You can test this by just doing page.find_field('user_skill_list').set('') so the label isn't involved
Note: you can get the id by just doing page.find_field('Skill list')[:id] rather than having to resort to .native.xxxx - although it's not really needed for this use case
I am new to Groovy Scripting. I am trying to access the value of a Response node
below is the script
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
def responseHolder = groovyUtils.getXmlHolder( testRunner.testCase.testSteps["request"].testRequest.response.responseContent );
responseHolder.namespaces["ns0"]="http://xmlns.int.com/orders/xsd/v1"
String mySection = responseHolder.getNodeValue["//ns0:MT_OrderCreateDTCFulfillmentResponse/ns0:StatusCode"] ;
log.info mySection
mySection is printed as []
Response XML:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:v1="http://xmlns.int.com/orders/xsd/v1"/>
<soapenv:Body xmlns:v1="http://xmlns.int.com/orders/xsd/v1">
<ns0:MT_OrderCreateDTCFulfillmentResponse xmlns:ns0="http://xmlns.int.com/orders/xsd/v1">
<StatusCode>000</StatusCode>
<ReferenceDocNbr>NA</ReferenceDocNbr>
<SchemaValidationStatus>Validated</SchemaValidationStatus>
<StatusTimestamp>2015-08-03T18:58:01.602</StatusTimestamp>
<FaultDetails>Request for customer order number NA received successfully and format validated.</FaultDetails>
</ns0:MT_OrderCreateDTCFulfillmentResponse>
</soapenv:Body>
</soapenv:Envelope>
SOAP UI Project Structure - I am running Test_Script. Suggest me what i am missing
You've to use:
responseHolder.getNodeValue("//ns0:MT_OrderCreateDTCFulfillmentResponse/StatusCode");
instead of responseHolder.getNodeValue["//ns0:MT_OrderCreateDTCFulfillmentResponse/ns0:StatusCode"];
Note that I change responseHolder.getNodeValue invocation to use () instead of [], and also change your xpath since in your response <StatusCode> it's not defined in xmlns:ns0="http://xmlns.int.com/orders/xsd/v1".
Another option is to use the * wildcard as a namespace to map anyone. So in this case you can use:
responseHolder.getNodeValue("//*:MT_OrderCreateDTCFulfillmentResponse/*:StatusCode");
Additionally, note that probably you XML is wrong, since I suppose that all sub elements of <MT_OrderCreateDTCFulfillmentResponse> must belongs to "http://xmlns.int.com/orders/xsd/v1" namespace... so you've to declare it as:
<ns0:MT_OrderCreateDTCFulfillmentResponse xmlns:ns0="http://xmlns.int.com/orders/xsd/v1">
<ns0:StatusCode>000</ns0:StatusCode>
<ns0:ReferenceDocNbr>NA</ns0:ReferenceDocNbr>
<ns0:SchemaValidationStatus>Validated</ns0:SchemaValidationStatus>
<ns0:StatusTimestamp>2015-08-03T18:58:01.602</ns0:StatusTimestamp>
<ns0:FaultDetails>Request for customer order number NA received successfully and format validated.</ns0:FaultDetails>
</ns0:MT_OrderCreateDTCFulfillmentResponse>
Or using as default for this tag:
<MT_OrderCreateDTCFulfillmentResponse xmlns="http://xmlns.int.com/orders/xsd/v1">
<StatusCode>000</StatusCode>
<ReferenceDocNbr>NA</ReferenceDocNbr>
<SchemaValidationStatus>Validated</SchemaValidationStatus>
<StatusTimestamp>2015-08-03T18:58:01.602</StatusTimestamp>
<FaultDetails>Request for customer order number NA received successfully and format validated.</FaultDetails>
</MT_OrderCreateDTCFulfillmentResponse>
Note that if you change you XML with my indication your first XPath it's correct since now StatusCode belongs to your namespace.
Hope it helps,
I'm using page-object gem with watir and RSpec to test my web application.
Here is my page object.
require 'page-object'
class UserEditPage
include PageObject
page_url "#{$context}/user/edit?id=#{#params[:id]}"
text_field :user_id, name: 'userName'
text_field :pw, name: 'password'
text_field :pw_retype, name: 'password2'
# snip uninteresting stuff
button :submit, index: 0
end
I would like to parameterize :id in page_url via PageObject::PageFactory like this:
visit UserEditPage, using_params: {id: 1000} do |page|
# operation on page
end
This document implies that above usage is possible, but I couldn't understand how exactly this is achieved.
Question: how can I pass parameter id from visit method to UserEditPage?
Running code results in
***/user/edit_page.rb:8:in `<class:UserEditPage>': undefined method `[]' for nil:NilClass (NoMethodError)
from ***/user/edit_page.rb:5:in `<top (required)>'
probably because #params is nil when evaluating page_url.
Changing using_params: {id: 1000} to id: 1000 with no luck.
The page_url needs to be:
page_url "#{$context}/user/edit?id=<%=params[:id]%>"
Note how the parameters need to be included differently - ie <%=params[:id]%> instead of #{params[:id]}.
The problem is that the page_url is evaluated when the page object class is evaluated. This means that when the class is evaluated, params[:id] must already exist. This is not going to be true when you want to include the parameters dynamically.
The page object gem uses ERB to allow you to create a template, which allows substitution of the params later - ie when calling visit.
In summary, when creating a page_url:
Use string interpolation if the value is known when the page object class is evaluated.
Use ERB if the value is to be dynamically specified on visit.
Working Example
Below is a working example of the dynamic parameters.
require 'watir-webdriver'
require 'page-object'
$context = 'http://testurl.com'
class UserEditPage
include PageObject
page_url "#{$context}/user/edit?id=<%=params[:id]%>"
end
include PageObject::PageFactory
#browser = Watir::Browser.new
visit UserEditPage, using_params: {id: 1000} do |page|
p page.current_url
#=> "http://testurl.com/user/edit?id=1000"
end
I want to parse url attribute from the XML and show image in image control (the one reffered to by the URL) in listbox from the following feed link: http://feeds.bbci.co.uk/news/rss.xml
My code is:
var ComingNewsFromUri = from rss in XElement.Parse(e.Result).Descendants("item")
select new NewsItems
{
Title = rss.Element("title").Value,
PubDate = rss.Element("pubDate").Value,
Description = rss.Element("description").Value
};
For RSS, I would recommend using SyndicationFeed and SyndicationItem....does all the parsing and converting to objects automatically and brilliantly for you.
http://ryanhayes.net/blog/how-to-build-an-rss-feed-reader-in-windows-phone-7part-i-retrieving-parsing-and-displaying-post-titles/
I have an RSS feed app on the store myself using SyndicationFeed and it is very reliable and convenient.
Here is another sample by Microsoft
http://code.msdn.microsoft.com/wpapps/RSS-Reader-Sample-1702775f