cucumber testing for checking parent of an element with certain class - cucumber

I have an element with id: #post and that element has parent <li>. Now I want to check whether the <li> has class .current or not.
The step might be like
Then the element "post" with parent "li" should have class "current"
If any body could help me with step_definitions, that'll be gr8!

With webrat you can search for an css selector. Maybe this solves your problem:
Then the element "([^"]*)" with parent "([^"]*)" should have class "([^"]*)" do |element_id,parent,css_class|
response.should have_selector "#{parent} .#{css_class}" do |matches|
matches.should have_selector element_id
end
end
I didn't try this code, but it should work for your purpose.

These suggestions should work for you, but you might also want to consider decoupling your selectors from your stories to make your test suite easier to maintain, and more expressive of business value. Eg: you might change the step to something like:
Then the post should be displayed as the current post
This becomes pretty easy to implement if you're using Pickle:
# /features/posts/viewing.feature
Given the following posts exist:
| post | title | slug |
| Lorem | Lorem Ipsum Dolor | lorem-ispum-dolor |
| Hello | Hello World | hello-world |
When I go to the post page for post "Hello"
Then post "Hello" should be displayed as the current post
# /features/step_definitions/post_steps.rb
Then /^#{capture_model} should be displayed as the current post$/ do |post_reference|
post = model!(post_reference)
page.should have_css("li.current ##{dom_id(post)}")
end

I used this, (which works):
Then /^"([^\"]*)" should have class "([^\"]*)"$/ do |id, parent_class|
assert page.has_xpath?('//a[#id="'+id+'"]/..[#class="'+parent_class+'"]')
end

Related

Generate hyperlink in Sharepoint

I have to generate an hyperlink in sharepoint based on sql table like this:
+----+----------------------------+
| ID | path |
+----+----------------------------+
| 1 | file://test/9932323.pdf |
+----+----------------------------+
| 2 | file://test/1653156423.pdf |
+----+----------------------------+
Actually there is this code to generate html link:
<asp:Label runat="server" id="ff1{$ID}" text="{$thisNode/#PATH}" />
I cannot modify SQL table (dinamically generated) but I have to substitute:
/test/ with /test.abc.local/
and
displayed text with filename only ("path" field substring after last '/')
How can I to that without creating new view or calculated fields?
I tried with:
<a href="{REPLACE($thisNode/#PATH),12,1,'.abc.local/')}"><asp:L ...
but with no success. (I'm really newbie in Sharepoint)
thanks
I'm not going to remove the previous answer because it still valid and it is pretty handy if somebody comes across the same issue, so the RegEx() expression you will have something like this:
/(file\:\/\/)/g
Using the expression above you can find the string you want, so the example below gives you all the LABELS on a page, and from there you can use the following:
.replace( new RegExp("/(file\:\/\/test)","gm"),"/test.abc.local")
Using the expression above you can find the string you want, so the example below gives you all the LABELS on a page, and from there you can use the following:
$('input[type=text]').each(
function(index)
{
console.log(' text: ' + $(this).val() + ' replace: ' + $(this).val().replace( new RegExp("(file\:\/\/test)","gm"),"/test.abc.local") );
}
);
If I understood your question correctly, I would strongly suggest you to use RegEx(), it is possibly the most handy thing ever created to handle string find/replacement.
You can put a JavaScript function to perform the RegEx() substitution on the page inside of a <script language="javascript"></script> , then on your <asp:label> you will replace the output for calling this function by passing the string #thisNode/#PATH to the JavaScript function you wrote, which will find and replace the substring for the desired output

Asciidoctor parametetrized template

I am using asciidoctor using asciidoctor-maven-plugin. In my document (actually documentation), I have one block repeated many times. Is there any way to do include with parameters.
What I want in pseudocode, I can't find how to write it:
template:
=== HTTP request
include::{snippets}/{variable}/http-request.adoc[]
=== HTTP response
include::{snippets}/{variable}/http-response.adoc[]
Usage
include template[variable=customer]
Thanks.
I think you can redefine attributes. With this tree:
Folder
| main.adoc
| template.adoc
|
\---code
+---first
| http-request.adoc
| http-response.adoc
|
\---second
http-request.adoc
http-response.adoc
My main.adoc file looks like this:
:snippets: code
== First Chapter
:variable: first
include::template.adoc[]
== Second Chapter
:variable: second
include::template.adoc[]
== End
This is the end.
The previous example works, but I have the feeling that this is not exactly what you want.
If you are looking for a Macro example, have a look at this maven & java example: java-extension-example.

How do you add an examples table to a background in a cucumber feature file?

I'm wanting to add an examples table to a background step in a cucumber feature file. How do I go about doing this?
I want to do something like this:
Background:
Given <username> has logged in
Examples:
|username|
|User 1 |
|User 2 |
Scenario: .....
Unfortunately, this is not possible.
The Cucumber docs
Does this help you..
Feature: Passing background with multiline args
Background:
Given table |a|b|
|c|d|
And multiline string """ I'm a cucumber
and I'm okay. I sleep all night and I test all day """
Scenario: passing background
Then the table should be
|a|b|
|c|d|
Then the multiline string should be """ I'm a cucumber and I'm okay. I sleep all night and I test all day
""" Scenario: another passing background
Then the table should be |a|b| |c|d|
Then the multiline string should be """ I'm a cucumber and I'm okay. I sleep all night and I test all day
Refer this link for more scenarios..
https://www.relishapp.com/cucumber/cucumber/docs/gherkin/background
May be this could help you:
Background:
Given Login with email myemail#mail.com and pass myPass
Scenario Outline:Scenario 1
Examples:
| thing1| thing2 | thing3 |
| fdlsk | fadsff | faskld |
And in your stepdef use this:
#Then("^Login Login with email ([^\"]*) and pass ([^\"]*)$")
public void login_general(String email, String pass) {
login.fillEmail(email);
login.fillPass(pass);
login.clickLogin();
}

Why does this jade template not work with commenting?

When I use the word works, I mean by all the content showing inside the well.
For some reason this jade template doesn't work if I leave the commented line in but works if I delete the commented line. Why is this happening?
extends layout
block content
h1= title
// div.well
p Fill out your info
form(method="post", action="/add")
div.control-group.input-append
input#name(type="text", name="name", data-required)
label.add-on(for="name")
| Name
div.control-group.input-append
input#country(type="text", name="city", data-required)
label.add-on(for="city")
| City
div.control-group.input-append
input#country(type="text", name="country")
label.add-on(for="country")
| Country
div.control-group.input-append
input#birthday(type="text", name="birthday")
label.add-on(for="birthday")
| Birthday
div.control-group.input-append
input#email(type="text", name="email")
label.add-on(for="email")
| Email
button(type="submit") Submit
Jade interprets your comment in that line as a comment for the whole block. So the div.well and its inner tags appear in the dom, but there commented out.
See here: http://jade-lang.com/reference/#blockcomments

Jade: Links inside a paragraph

I'm trying to author a few paragraphs with Jade, but finding it difficult when there are links inside a paragraph.
The best I can come up with, and I'm wondering if there's a way to do it with less markup:
p
span.
this is the start
of the para.
a(href="http://example.com") a link
span.
and this is the rest of
the paragraph.
As of jade 1.0 there's an easier way to deal with this, unfortunately I can't find it anywhere in the official documentation.
You can add inline elements with the following syntax:
#[a.someClass A Link!]
So, an example without going into multiple lines in a p, would be something like:
p: #[span this is the start of the para] #[a(href="http://example.com") a link] #[span and this is the rest of the paragraph]
You can also do nested inline elements:
p: This is a #[a(href="#") link with a nested #[span element]]
You can use a markdown filter and use markdown (and allowed HTML) to write your paragraph.
:markdown
this is the start of the para.
[a link](http://example.com)
and this is the rest of the paragraph.
Alternatively it seems like you can simply ouput HTML without any problems:
p
| this is the start of the para.
| a link
| and this is he rest of the paragraph
I wasn't aware of this myself and just tested it using the jade command line tool. It seems to work just fine.
EDIT:
It seems it can actually be done entirely in Jade as follows:
p
| this is the start of the para
a(href='http://example.com;) a link
| and this is the rest of the paragraph
Don't forget an extra space at the end of para (although you can't see it. and between | and. Otherwise it will look like this para.a linkand not para a link and
Another way to do it:
p
| this is the start of the para
a(href="http://example.com") a link
|
| this is the rest of the paragraph.
Another completely different approach, would be to create a filter, which has first stab at replacing links, and then renders with jade second
h1 happy days
:inline
p this can have [a link](http://going-nowhere.com/) in it
Renders:
<h1>happy days</h1><p>this can have <a href='http://going-nowhere.com/'>a link</a> in it</p>
Full working example: index.js (run with nodejs)
var f, jade;
jade = require('jade');
jade.filters.inline = function(txt) {
// simple regex to match links, might be better as parser, but seems overkill
txt = txt.replace(/\[(.+?)\]\((.+?)\)/, "<a href='$2'>$1</a>");
return jade.compile(txt)();
};
jadestring = ""+ // p.s. I hate javascript's non-handling of multiline strings
"h1 happy days\n"+
":inline\n"+
" p this can have [a link](http://going-nowhere.com/) in it"
f = jade.compile(jadestring);
console.log(f());
A more general solution would render mini sub-blocks of jade in a unique block (maybe identified by something like ${jade goes here}), so...
p some paragraph text where ${a(href="wherever.htm") the link} is embedded
This could be implemented in exactly the same way as above.
Working example of general solution:
var f, jade;
jade = require('jade');
jade.filters.inline = function(txt) {
txt = txt.replace(/\${(.+?)}/, function(a,b){
return jade.compile(b)();
});
return jade.compile(txt)();
};
jadestring = ""+ // p.s. I hate javascript's non-handling of multiline strings
"h1 happy days\n"+
":inline\n"+
" p this can have ${a(href='http://going-nowhere.com/') a link} in it"
f = jade.compile(jadestring);
console.log(f());
If your links come from a data source you can use:
ul
each val in results
p
| blah blah
a(href="#{val.url}") #{val.name}
| more blah
See interpolation
Edit: This feature was implemented and issue closed, see answer above.
I've posted an issue to get this feature added into Jade
https://github.com/visionmedia/jade/issues/936
Haven't had time to implement it though, more +1s may help !
This is the best I can come up with
-var a = function(href,text){ return "<a href='"+href+"'>"+text+"</a>" }
p this is an !{a("http://example.com/","embedded link")} in the paragraph
Renders...
<p>this is an <a href='http://example.com/'>embedded link</a> in the paragraph</p>
Works ok, but feels like a bit of a hack - there really should be a syntax for this!
I did not realize that jade requires a line per tag. I thought we can save space. Much better if this can be understood ul>li>a[class="emmet"]{text}
I had to add a period directly behind a link, like this:
This is your test [link].
I solved it like this:
label(for="eula").lbl.lbl-checkbox.lbl-eula #{i18n.signup.text.accept_eula}
| #{i18n.signup.links.eula}.
As suggested by Daniel Baulig, used below with dynamic params
| <a href=!{aData.link}>link</a>
Turns out there is (now at least) a perfectly simple option
p Convert a .fit file using Garmin Connect's export functionality.
p
| At Times Like These We Suggest Just Going:
a(ui-sref="app") HOME
|
Most simplest thing ever ;) but I was struggling with this myself for a few seconds. Anywho, you need to use an HTML entity for the "#" sign -> #
If you want to in include a link, let's say your/some email address use this:
p
a(href="mailto:me#myemail.com" target="_top") me#myemail.com

Resources