Calabash-Android loop through ListView - calabash-android

I've written a feature:
Feature: Open List item
Scenario: As a valid user I can open list item
When I press list item number 0
Then I do something...
Then I go back
What I would need is to open every item of ListView (not only 0th), so how could I specify a loop that would in the end iterate through whole ListView, or some specified maximum index - ie. for parameter value 5 it should execute this scenario for 0th, 1th, 2nd, 3rd, 4th and 5th item.
So, two questions:
1) How to create a loop?
2) How to parametrize execution
Regards,
Milos

1. If you know the exact loop count, you can use scenario outline in cucumber.
Feature: Open List item
Scenario: As a valid user I can open list item
When I press list item number <count>
Then I do something...
Then I go back
Examples:
| count |
| 1 |
| 2. |
| .. |
| n |
More details about scenario outline: https://github.com/cucumber/cucumber/wiki/Scenario-Outlines
Or
2. You can get count using query() & iterate using for each loop in ruby
For getting count query("view").count
Get the count.
Store it in variable
Loop it in step definition

Related

Two-column list-box with input

I'm trying to create a control (for the first time) that pops up and shows the user two columns: The column on the left has labels and the column on the right has empty text boxes for user input.
For example:
---------------------
Ingredient | Quantity
---------------------
Carrots |
---------------------
Apples |
---------------------
Bananas |
And so on. It's important that they are able to scroll together.
I have no idea where to start :/ Should I be looking at tables? listboxes?
I know I can't use textboxes because the number of "ingredients" changes every time the control is called
There is a great deal we don't know about the use-case or (real) data and source. One way to display and edit a varying number of items is the DataGridView. If it is on a modal dialog, it 'pops up':
' form level collection of things
Private Recipe As List(Of RecipeItem)
...
' prepare the data and display:
Recipe = New List(Of RecipeItem)
Recipe.Add(New RecipeItem With {.Ingredient = "Carrot"})
Recipe.Add(New RecipeItem With {.Ingredient = "Apple"})
Recipe.Add(New RecipeItem With {.Ingredient = "Banana"})
Recipe.Add(New RecipeItem With {.Ingredient = "Hemlock"})
...
Dim UmCol As New DataGridViewComboBoxColumn
UmCol.DataPropertyName = "UnitMeasure"
UmCol.DataSource = [Enum].GetValues(GetType(UnitMeasure))
dgvDD.DataSource = Recipe
dgvDD.Columns.Remove("UnitMeasure")
dgvDD.Columns.Add(UmCol)
The DGV will save user edits back to the underlying datasource - the recipe list, in this case.
' elsewhere
For Each item In Recipe
Console.WriteLine(item.ToString)
Next
Result:
2 Each of Carrot
1 Tsp of Apple
1.5 Cup of Banana
3 Bushel of Hemlock
A UserControl with dynamically built TextBox controls will also work, but you likely still need a collection to store the data. If the data comes from a database, the DGV will still work fine, just use a DataTable as the source rather than the Recipe collection.

Sum data in a column based on another column Report Builder - Sharepoint

I have a project where I have to report stop times of different production lines.
I have to make a report file with Report Builder and my problem for the moment is that I have to sum all the stop times that where entered for the same line.
The stop times are entered on SharePoint (using a form from InfoPath) and stored in a SharePoint List.
My data list is presented like this:
LINES ---- TIME(min)
Line 1 ---- 4
Line 2 ---- 2
Line 1 ---- 3
Line 3 ---- 8
Line 4 ---- 9
Line 2 ---- 2
Line 3 ---- 4
Line 5 ---- 5
Line 5 ---- 8
I want to sum all the stop time for each line (In my report generated with Report Builder). So I'll have "Line1 -> 7", "Line 2 -> 4",...
Do you have any idea how I could do it?
Ask if you need more informations...
Thank you for your help!
This should be fairly easy; set up a table drawing the data in exactly that format, then right click the "Details" row in "Row Groups" at the bottom of Report Builder and click "Group Properties". Press Add, and select your "Lines" field, then press OK. Finally, change the expression populating the "Time" column in your table to =SUM(Fields!.Value).
What this will do is collapse the table to show one line per distinct value it finds in the "Lines" column, then tells it to simply add all the values it collapses together. The effect will be that it sums up the Time column for each distinct value it finds in the Lines column.

Extract substring of list based on another list

Using two lists, one consisting of names with added information in various forms (see below for example - list 1) and one consisting of the clear formatted names, i.e. with no added information (list 2)
List 1
--------
Netto City | Value
Imerco City | value
Bilka Suburb | value
Bauhaus, City | Value
City FDB Superb | Value
List 2
------
Netto
Imerco
Bilka
Bauhaus
FDB Super
What I am trying to do is create a filter, so that no matter what the first column of my source data(list 1) looks like, i will be able to sum the values based on (list 2).
Something similar to this: Excel - extracting data based on another list
I tried using vlookup, but that does not search for substrings, then i tried using
=IF(COUNTIF(A$4:A$9;"*"&D5&"*")>0;
INDIRECT(ADDRESS(MATCH("*"&D5&"*";A$4:A$9;0);4));"not found")
But that appears to do the opposite, search list 1 for a single cell value from list 2.
I can't quite get my head around if this works just as well, I havent been able to get it to work anyway, thus my search for the other way. Search List 2, for each item from List 1.
But, ultimately, what I am trying to accomplish is to create a list from the source data, which I can use to categorize each item in list 1 from, based on list 3
List 3
Bilka | Cat1
Imerco | Cat2
FDB Super | Cat1
etc.
For that to work, i need a clean list of the source data, without all the extra information which comes with it.
I use the following sumif
=SUMIFS($F$3:$F$703;$B$3:$B$703;
"="&$H4;$D$3:$D$703;">="&I$2;$D$3:$D$703;"<="&I$3)
to sum all sums belonging to a particular item in List 3 (where i've manually created List 3), between to dates.
The purpose of this is to create a sheet that contains all expenditures to a particular store or category of ones own choosing, for instance the ones listed in List 1, are primarily food stores.
Edit - Clarification.
What I am proposing to do is a multistage process.
Stage 1:
Insert original source data (done)
Stage 2:
Filter source data for unique values (done)
Stage 3:
Create list of approve names for each item in source data
- Ie, Bilka Suburb into Bilka, Netto City into Netto
Here 'Netto' and 'Bilka' are approved names which is manually created to allow for grouping in stage 4. I am looking to automatize this step.
Stage 4:
Group each item from the list of Stage 3, based on name and date-interval, weekly monthly whatever (done) if i could only get Stage 3 to work, as it works on my manually corrected data.
Stage 5:
Select appropriate category, and type for each item in resulting list from Stage 3:
Bilka, is a food place, so it would get the category 'food', same as netto, where Bauhaus would get the category 'Building Supplies', each of these items would get the type 'expense' where say wage would get the type 'income' (done)
the solution to stage 5, is just a vlookup, based on the category into a table that lists each category with a type, so that is simple enough.
Final Solution: Requires that the list to iterate over is in column G, and outputs the list of approved names in column H. There is the error of if not being able to know the difference between an item such as "Super" and "SU", I don't know how to fix that. If anyone has any suggestions on that I am all ears.
Sub LoopCells()
Sheets("RawData").Select
Sheets("RawData").Activate
LRApproved = Cells(Rows.Count, "H").End(xlUp).Row
LRsource = Cells(Rows.Count, "G").End(xlUp).Row
For Each approvedcell In Worksheets("RawData").Range("H2:H" & LRApproved).Cells 'Approved stores entered by users
For Each sourcecell In Worksheets("RawData").Range("G2:G" & LRsource).Cells 'items found from bank statement export
If InStr(UCase(sourcecell.Value), UCase(approvedcell.Value)) <> 0 Then
sourcecell.Offset(0, 2).Value = approvedcell.Value
End If
Next sourcecell
Next approvedcell
End Sub
Thanks for all the help.
Edit: Added final solution and VBA tag.
This works for me:
=SUM(B$3:B$7*NOT(ISERROR(SEARCH(A11,A$3:A$7))))
This assumes that your example list 1 is in range A3:B7 and your list 2 in A11:B15. Paste the above formula in cell B11 and press CtrlShift-Enter to enter it as an array formula. Then you can drag-copy it all the way down to B15.
Explanation: SEARCH for e.g. "Netto" in the cells of List 1. For cells that do not contain that string, SEARCH returns an error. So we're looking for cells that do not return an error. We now have an array of booleans indicating this. Multiply it element-by-element by the array of values. In this multiplication, TRUE is interpreted as 1 and FALSE as zero, so you're screening out the values that don't correspond to "Netto".
Here's a secreenshot of my setup:
Perhaps I've misunderstood but can't you use SUMIF?
=SUMIF(A$4:A$9;"*"&D5&"*";B$4:B$9)
instead of going with VBA, you can extract this with simple small formula. =Index(List2!A2:A10,Match(1,Countif(List1A2,""&List2!A2:A10&""),0)) (Press Ctrl+Shift+Enter). Assume you want to extract the list 2 in to list 1.

trying to do a match by relavence using excel

I have this really poorly formatted data that I have to work with every week. Here's a sample:
Code: To: Total: Description:
-------------------------------------------------------------
FD987 00001 5 Food/Snack/M&M
FD987 00001 5 Food/Snack/Pretzels
NA654 00001 5 Non-Alc/Soda/Sprite
NA654 00002 2 Non-Alc/Soda/Sprite
NA987 00002 2 Non-Alc/Soda/Lemonde
I want the data to end up sorted by the "To" code, with the various data summed for subtotals in each category and subtotals for the whole "To" entry. Like this:
To: Total: Description:
---------------------------------------------------
00001 10 Food Subtotal
00001 5 Non-Alc Subtotal
00001 15 Grand total
00002 0 Food Subtotal
00002 4 Non-Alc Subtotal
00002 4 Grand total
I have written code that gets "00001" and "00002". But I don't know what to do from there. Should I loop through using a combination of if and for?
example:
pseudo code:
for all i in UniqueToCodes
if (cell.value = i) then
Descriptions = {"Food", "Non-Alc"}
tempsum = 0
for all j in Descriptions
q = total for item j belonging to Descriptions belonging to UniqueToCodes
tempSum = tempSum + q
next j
end if
next i
or would looping backwards be more efficient?
for example as this:
pseudo-code:
for i = lastOccurenceOf(ToCode) to firstOccurenceOf(ToCode) -1
Descriptions = {"Food", "Non-Alc"}
for all j in Descriptions
q = total for item j belonging to Descriptions belonging to UniqueToCodes
tempSum = tempSum + q
next j
next i
(I know that the "To" codes appear always as blocks and never with interjections by other codes i.e.
always as this:
00001
00001
00002
never as this:
00001
00001
00003
00001)
also how i store all these temp sums? i.e. tempSum of "Food" and tempSum of "Non-Alc" for "To" code "00001"? I know dictionary objects map only one property to a key. But I need to match the subtotal to the Description and the Grand Total to the "To" Code. What would you say is the best approach to this problem? Any help would be greatly appreciated! Thanks!
Like the people said in the comments, a Pivot Table would probably be the easiest way to sum up your data. However, in order to subtotal the way you want, you need to break apart the Description column.
In Excel 2007 you can use Text to Columns as follows:
Select your Description column.
Click Data -> Text to Columns.
On the Convert Text to Columns Wizard make sure Original data type is set to Delimited and click Next.
Select Delimiters to Other with a / and then click Finish.
Rename the new columns whatever you want.
If Text to Columns isn't available, just create a formula to pull the first food type out of the Description. For example, using the first picture above, put this formula in cell E2. =LEFT(D2,FIND("/",D2)-1)
Now you can create a Pivot Table.
Make sure the active cell is within the table of data and click Insert -> PivotTable. When the Create PivotTable dialog box displays, click OK.
Drag To and Type to Row Lables area and Total to Values area.
Done. There is your basic pivot table. You can change the basic format thru Pivot Table Options and Field Settings.

Determine section for selected row from NSOutlineView

OK so I've got a sidebar built using an NSOutlineView. I currently have two sections in the sidebar which can be expanded/contracted. I would like to be able to determine which section the selected row belongs to.
- Section 1
-- Item 1
-- Item 2
-- Item 3
- Section 2
-- Item 4
-- Item 5
The problem is that the selectedRow value changes depending on whether sections are expanded or not. Is there no easy way to determine which section the row belongs to without manually keeping track of expansion/contraction and the number of items in each section?
Try this:
//returns id of section, where currentRow is a selectedRow
id section = [yourNSOutlineView parentForItem:[yourNSOutlineView itemAtRow:selectedRow]];
You could call [NSOutlineView itemAtRow:] with the index of the selected row.