Named step blocks in SpecFlow - selenium

If someone knows, how to use repeating bunches of steps in Specflow, i.e. I need to check several pages, which contain some portion of same elements.
Something like this:
When I open page Page1
Then <do_something>
And I check button 3
When I open page Page2
Then <do_something>
And I check Textfield1
When I open page Page3
Then <do_something>
And I check button 4
<do_something>:
And I check button 1
And I check button 2
As if I have buttons 1 and 2 on each page, and something else in addition, but I dont want to write steps for buttons 1 and 2 for each page.

Maybe something like this?
Scenario Outline: Pages
Given I am on page <page>
When I click on "button 1"
And I click on "button 2"
Then something will happen
Examples:
| page |
| page1 |
| page2 |
| page3 |

Note that anything you place in the Examples table, in the same row as your example, will be used in the context of that example. So say, you want to do specific actions on every page, add this to the row of that page. (#marcel, sorry for copying your code, but I couldn't post this as a commend and format it a.f.a.i.k.)
Scenario Outline: Pages
Given I am on page <page>
When I click on "button 1"
And I do "<action1>"
And I do "<action2>"
Then something will happen
Examples:
| page | action1 | action 2 |
| page1 | action | action |
| page2 | action | action |
| page3 | action | action |

Related

Best practice to change component based on URL params in Vue

Just curious, for a route like /chart/:charttype
I want to load different type of chart components into that chart area, how to plan this in VueRouter(currently I only put /chart/:charttype there) and component( currently I put a container component there, inside which, there is a long list of v-if different type of chart components )? Any best practice?
/*
Say I have a long list of diff type of charts,
when charttype matches, it will load that component,
otherwise load 404 component there.
*/
_______________________
| _____________ |
| | | |
| | chart | |
| |___________| |
|_____________________|
I believe current long list of v-if way will be very hard for maintenance, also, in the future, that chart area will be a a group of charts which build a combo chart component(such as 4 charts as a combo chart component), so I guess there has to be a configurable way to do this.
Thanks,
You can check Dynamic Components in the docs
<component :is="componentName"></component>

react navigation: Navigate to screen from specific screen

My navigation structure looks something like this:
TabNavigator
|
|- StackNavigator
| |
| |- ListA
| |
| |- ShowA
|
|- StackNavigator
| |
| |- ListB
| |
| |- ShowB
ListA shows, as you might expect, a list of resources (type A). Pressing on one sets the state and navigates you to ShowA where you are viewing details about that specific resource.
ListB shows a list of resources (type B), and ShowB also shows a list of resources, however the resources are of type A. When pressing on one of these resources, you should be navigated to ShowA.
If on ListA I press and navigate to ShowA, that works perfectly.
If on ShowB I press and navigate to ShowA, that also works as expected.
However, if I first go to ListA, navigate to ShowA, then (without pressing 'Back' on ShowA) use the TabNavigator and go to ListB, then to ShowB, pressing on a resource opens ShowA but it's another instance of the screen placed on top of the stack. So when I press 'Back', instead of taking me to ListA as would be expected, it takes me to the previously opened ShowA.
I'm sorry if the formatting or explanation of this is inadequate. If anyone can help or if anyone needs more information please let me know and I'll do whatever I can.
You should register two screens using the same component under different screen names. The structure should look something like this:
Tab:
Stack
"Tab1List"
"Tab1Show"
Stack
"Tab2List"
"Tab2Show"

Scroll on DOM based generated PDF

Hi This is my first question to stackoverflow. In my project we have requirement to generate the PDF based on DOM. There were multiple requirement and we used Kendo for this. PDF was generated from Bootstrap pages and many UI issue was there as bootsrap3 is not officially support the print version. There were overlapping and table width issue, content was going off the screen due to Boostrap offset classes all of them are sorted now. One more task client ask that can we apply scroll to pdf were we have grid and lots of column. On browser everyone know we can manage it by applying horizontal scroll and user can see the rest of the data by scrolling it.
As per my experience I don't see this kind of example but still asking is there any possibility to implement the scroll for generated PDF where we have grid with lots of column?
PDF content layout is static and there are no scrollbars for items, such as tables within. So, no possibility.
When a grid is too wide you have to decide how to split up the layout of the grid for 'printout' pages. For example, suppose your grid needs six pages to fit in a pdf
The pages in the pdf could be from this row-wise layout
A wide grid
+---+---+---+
| 1 | 2 | 3 |
+---+---+---+
| 4 | 5 | 6 |
+---+---+---+
or this column-wise layout
A wide grid
+---+---+---+
| 1 | 3 | 5 |
+---+---+---+
| 2 | 4 | 6 |
+---+---+---+
Which ever you choose, the content in a pdf reader will look like
A wide grid (direction-wise)
+---+
| 1 |
+---+
... pages 2 to 5 ...
+---+
| 6 |
+---+
If the content is widely variant it might be easier to sell the client on receiving Excel content instead of PDF, versus trying to code your own grid to pdf layout engine.
If the web page is only the grid, you could also consider using the spreadsheet component, which has a pdf download feature which renders column-wise.

Selenium IDE get element using xpath and index

I am trying to assert that three elements are visible. I set up the following command to store the xpath count:
storeXpathCount | xpath=//input[contains(#class,"k-formatted-value") and contains(#class, "call-timer-editor")] | x
and x="3", which is correct. Now, I want to assert that all three of those inputs are visible. so I do:
verifyVisible | xpath=//input[contains(#class,"k-formatted-value") and contains(#class, "call-timer-editor")][1] |
verifyVisible | xpath=//input[contains(#class,"k-formatted-value") and contains(#class, "call-timer-editor")][2] |
verifyVisible | xpath=//input[contains(#class,"k-formatted-value") and contains(#class, "call-timer-editor")][3] |
The first line evaluates to true, but the other (which are for sure visible) evaluate to false. How should I correctly index to the three inputs?
Since you did not post code or link to the page you are automating I can only guess. Try this:
xpath=(//input[contains(#class,"k-formatted-value") and contains(#class, "call-timer-editor")])[2]

Clicking on several links part dynamically generated

I'm new in Selenium and testing matters.
I'm trying to capture the id of an hyperlink element that is dynamically part generated.
The click action is recorded like as below when i make click on in selenium, the part in bold are dynamically generated, there are many of them on my page and can differ from one site to another(I'm testing cms). I'd like to capture and click on any one.
This is what I've tried to do since:
storeAttribute | //button#class onclick="setLocation(javascript{baseUrlSelection()}['/checkout/cart/add/uenc/(a-zA-Z0-9)/product/(0-9)]'')" | myid
echo | ${myid} |
clickAndWait | ${myid[0]}
It doesn't work
My links looks like this when click action is recorded in selenium:
buton[#onclick="setLocation('http://localhost/mydomaine/index.php/checkout/cart/add/uenc/aHR0cDovL2xvY2FsaG9zdC9NYWdlbnRvSGls
YWlyZURlbW9WMi9tYWdlbnRvZGVtb0hpbGFpcmVWMi9pbmRleC5waHAvY2F0ZWdvcmllMS5odG1sP19fX1NJRD1V/product/1/')">
Please Help.
Are you using the Selenium IDE? It would probably be much easier to do something using the other development environments, however if you really want to do looping:
Get the looping user-extension from this page
and run a script like this.
store | 0 | myCurrent
storeEval | var pattern=new RegExp("\\w*http://localhost/mydomaine/index.php/checkout/cart/add\\w*");var i=0;var total=0;while(i<window.document.getElementsByTagName('input').length){if (window.document.getElementsByTagName('input')[i].id.match(pattern)){window.document.getElementsByTagName('input')[i].id = 'testID_' + total;total=total+1;}i=i+1;}total; | myTotal
while | storedVars.myCurrent < storedVars.myTotal
storeAttribute | //input[contains(#id,'testID_${myCurrent}')]#class | myid
echo | ${myid}
clickAndWait | //input[contains(#id,'testID_${myCurrent}')]
store | javascript{storedVars.myCurrent++}
endWhile
What does the click on these buttons do? Does it postback the page or anything like that? If so, you'll need to move the storeEval | var pattern.... inside the while loop. What the javascript does is rename all of the inputs on the page that match the RegEx pattern (which you'll probably need to change to match your button ID's) to a sequential ID so you can loop through them easily. If there is a different pattern you can exploit, feel free to do that.
Javascript adapted from here
You can use the xpath contains() function to locate the items:
storeAttribute | //input[contains(#onclick,"setLocation('http://localhost/mydomaine/index.php/checkout/cart/add/uenc/")]#class | myid
echo | ${myid}
clickAndWait | //input[contains(#onclick,"setLocation('http://localhost/mydomaine/index.php/checkout/cart/add/uenc/")]#class
It is also a good idea to reference the elements by something other than their onclick attribute. Id or name would be good choices.