Select UI Element by filtering properties in coded ui - coded-ui-tests

I have a web application. And I am using coded ui to write automated tests to test the application.
I have a dropdown with a text box. Which on entering values in the textbox, the values in the dropdown gets filtered based on the text entered.
If I type inside textbox like 'Admin', I will get below options like this:
And I need to capture the two options displayed.
But using IE Developer tool (F12), I am not able to capture the filtered options, because the options that are displayed do not have any unique property (like this below). And the options that are NOT displayed have a class="hidden" property
Any way to capture the elements that are displayed by applying some kind of filter like 'Select ui elements whose class != hidden'
Thanks in advance!!

HI please try below code will it works for you or not.By traversing all those controls that have class ="hidden"
WpfWindow mainWindow = new WpfWindow();
mainWindow.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, "hidden");
UITestControlCollection collection = mainWindow.FindMatchingControls();
foreach (UITestControl links in collection)
{
HtmlHyperlink mylink = (HtmlHyperlink)links;
Console.WriteLine(mylink.InnerText);
}

I'm not sure there is a way to do it by search properties, but there are other approaches.
One way would be to brute force difference the collections. Find all the list items, then find the hidden ones and do a difference.
HtmlControl listControl = /* find the UL somehow */
HtmlControl listItemsSearch = new HtmlControl(listControl);
listItemsSearch.SearchProperties.Add(HtmlControl.PropertyNames.TagName, "li");
HtmlControl hiddenListItemsSearch = new HtmlControl(listControl);
hiddenListItemsSearch.SearchProperties.Add(HtmlControl.PropertyNames.TagName, "li");
hiddenListItemsSearch.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, "hidden");
var listItems = listItemsSearch.FindMatchingControls().Except(hiddenListItemsSearch.FindMatchingControls());
You will only be able to iterate this collection one time so if you need to iterate multiple times, create a function that returns this search.
var listItemsFunc = () => listItemsSearch.FindMatchingControls().Except(hiddenListItemsSearch.FindMatchingControls());
foreach(var listItem in listItemsFunc()){
// iterate 1
}
foreach(var listItem in listItemsFunc()){
// iterate 2
}
The other way I would consider doing it would be to filter based on the controls which have a clickable point and take up space on the screen (ie, not hidden).
listItemsSearch.FindMatchingControls().Where(x => {
try { x.GetClickablePoint(); return x.Width > 0 && x.Height > 0; } catch { return false; }
});

Related

Access List Options for a Field in a Custom Table in Kentico 10

I have a custom table with a few fields that have list options for the user to select from when adding the content. Is there something in the API that allows me to access the options for a particular field so I can use those same options in a filtering widget?
Something like the below but that works for fields in a custom table?
var guids = ParentDocument.GetValue("CustomFieldName").Split(';');
var referencedDocs = DocumentHelper.GetDocuments().WhereIn("DocumentGuid", guids);
UPDATE - The code in case the link in the answer changes:
protected string[] GetFormFieldOptions()
{
DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo("custom.MyPageTypeName");
if (dci != null)
{
//Get the data from the form field
FormInfo fi = new FormInfo(dci.ClassFormDefinition);
FormFieldInfo ffi = fi.GetFormField("Industry");
string[] industries = ffi.Settings["Options"].ToString().Split('\n');
return industries;
}
return null;
}
Use DataClassInfoProvider in order to get data you need. Check this blog post to see more details.
You can use the same code as you have in your question. The difference is you need to get 2 different things which are not available at the "Page" or "Document" level:
Custom table object
Custom table item based on #1
You use the API to get the custom table item:
var cti = CustomTableItemProvider.GetItem(<id or guid>, "yourcustom.tableclassname);
if (cti != null)
{
string[] s = ValidationHelper.GetString(cti.GetValue("YourField"), "").Split(";");
}
Update
To get a dynamic list of options in a field you can simply use a listing control like a dropdown list or a radio button list as your control (vs. a textbox). Then in the properties for the dropdownlist, you can set it to a query. In the query enter something like
-- if you wan to have a 'select one' add this
SELECT '', '-- select one --'
UNION
SELECT ItemID, FieldName
FROM CustomTable_Name
ORDER BY 2

Highlight Duplicate list item in SharePoint 2013

I have a SharePoint 2013 (The Cloud version) custom list where 1 column is a text field where contact numbers are keyed in.
How can I get SharePoint to highlight duplicate values in that column so that every time a new item is added to the list, I'll know if the contact number has been used previously?
Ideally, here's what I'd get if I were to enter 816's details for the 2nd time:
CNO....Name.......Issue
816.....Blink........Login Problem (highlighted in red)
907.....Sink.........Access Denied
204.....Mink.........Flickering Screen
816.....Blink........Blank Screen (highlighted in red)
I've been struggling with this for awhile and would be very grateful for any advice. Thanks!
Since SharePoint 2013 uses Client Side Rendering (CSR) as a default rendering mode I would recommend the following approach. Basically the idea is to customize List View on the client side as demonstrated below.
Assume the Requests list that contains RequestNo column.
The following JavaScript template is intended for highlighting the rows when list item with RequestNo column occurs more then once:
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
OnPostRender: function(ctx) {
var rows = ctx.ListData.Row;
var counts = getItemCount(rows,'RequestNo'); //get items count
for (var i=0;i<rows.length;i++)
{
var count = counts[rows[i]["RequestNo"]];
if (count > 1)
{
var rowElementId = GenerateIIDForListItem(ctx, rows[i]);
var tr = document.getElementById(rowElementId);
tr.style.backgroundColor = "#ada";
}
}
}
});
function getItemCount(items,propertyName)
{
var result = {};
for(var i = 0; i< items.length; i++) {
var groupKey = items[i][propertyName];
result[groupKey] = result[groupKey] ? result[groupKey] + 1 : 1;
}
return result;
}
How to apply the changes
Option 1:
Below is demonstrated probably one of easiest way how to apply those changes:
Open the page in Edit mode
Add Content Editor or Script Editor web part on the page
Insert the specified JavaScript template by enclosing it using
script tag into web part
Option 2:
Save the specified JavaScript template as a file (let's name it duplicatehighlight.js) and upload it into Site Assets library
Open the page in Edit mode and find JSLink property in List View web part
Specify the value: ~sitecollection/SiteAssets/duplicatehighlight.js and save the changes.
Result
SharePoint has some basic conditional formatting for Data View Web Parts and XSLT List Views, but the conditions you can use are rather limited. You can compare a field in the current item with a value that you specify. There are no formulas to count the number of items with the same name or similar, which would be the approach to use to identify duplicates.
If you need to identify duplicates, you may want to create a view that groups by the CNO number. Grouping will also include an item count, so you can run down the list and spot groups with more than one item.

How to find out if an XPages view(Panel) is sorted by a viewColumnHeader sort toggle switch?

I'm displaying a view using a viewPanel. The view contains some columns which are enabled to be sorted in both directions, which is working fine.
Now I'd need to find out if the view has been resorted by the user by being clicked on the "Sort Toggle" in the viewColumnHeader.
Is there a property or a method which I can access programmatically to find this out?
Or is there an event in the viewPanel I could intercept or listen to?
Update:
I found that the class UIViewColumnHeader (which is extended by XspViewColumnHeader) has some static properties describing the icons (see here) - could I check for them? And if yes, how?
The sort column should be defined on the dominoView datasource in the sortColumn property, whose Java class is com.ibm.xsp.model.domino.DominoViewData. That can be accessed by calling getData() on the ViewPanel
So you should be able to use getComponent("myViewPanel").getData().getSortColumn() in SSJS. By default I suspect it will be blank.
Ok, with the help of those both sites, I solved resp. worked around my problem:
First, there was Naveen's solution how to Getting ViewPanel Headers programmatically
Second, Mark Leusink's article about the order of events in XPages.
This led me to following code:
<xp:this.beforeRenderResponse><![CDATA[#{javascript:
var viewPnl:com.ibm.xsp.component.xp.XspViewPanel = getComponent("viewPanel1");
var list:java.util.List = viewPnl.getChildren();
var replaceRespCol = false;
for (var i = 0 ; i < list.size(); i++) {
var viewCol:com.ibm.xsp.component.xp.XspViewColumn = list.get(i);
var viewHdr:com.ibm.xsp.component.xp.XspViewColumnHeader = viewCol.getHeader();
if (#RightBack(viewHdr.getSortIcon(), "/") != "sort_none.gif") {
replaceRespCol = true;
}
}
if (getSearchKey() != "") {
getComponent("viewColumn1").setRendered(false);
getComponent("viewColumn1b").setRendered(true);
} else if (replaceRespCol == true) {
getComponent("viewColumn1").setRendered(false);
getComponent("viewColumn1b").setRendered(true);
} else {
getComponent("viewColumn1").setRendered(true);
getComponent("viewColumn1b").setRendered(false);
}}]]></xp:this.beforeRenderResponse>
which enables me now to dynamically show a categorized column (viewColumn1)
- if no filter/search key is entered and
- no re-sort via the headers is done.
Otherwise, a flat column (viewColumn1b) is shown. HTH

Sharepoint webpart combobox of lists

I have a webpart that works off of a list but what I'm trying to do create a dropdown that contains a list of sharepoint lists so that when the user edits the page and selects 'modify shared webpart' they are able to choose a list item and that gets parsed back to the webpart.
Any examples or links to examples appreciated!
Thanks
Dan
What you are looking for is called a Toolpart. Take a look at this example for a tutorial on how to create one.
Overall, your general steps will be:
Create your custom Toolpart class inheriting from Microsoft.SharePoint.WebPartPages.ToolPart
In your custom Toolpart, override CreateChildControls, write the code to iterate over the lists in your SPWeb, and add those to a DropDownList
In your webpart, override GetToolParts and add your custom ToolPart so that it shows up in the right hand side
It sounds like you want to create a custom editor part. In the part you would have one dropdown that shows the names of the lists (you probably want to filter hidden and empty lists) and, when an item is selected from the list, a second dropdown shows the Title column of the items from the selected list.
Here's some code (edited here, so it will need to be cleaned up) to help you get started:
protected Page_Load(...)
{
if (IsPostBack) return;
var web = SPContext.Current.Web;
var query = from list in web.Lists
where list.Hidden == false && list.ItemCount == 0
select list;
DropDownList1.DataSource = query;
DropDownList1.DataTextField = "Title";
DropDownList1.DataBind();
}
protected DropDownList1_SelectedIndexChanged(...)
{
var web = SPContext.Current.Web;
var listName = DropDownList1.Text;
var list = web.Lists[listName];
var table = list.Items.GetDataTable();
DropDownList2.DataSource = table;
DropDownList2.DataTextField = "Title";
DropDownList2.DataValueField = "ID";
DropDownList2.DataBind();
}

How can I customize SharePoint list column aggregation (total) calculations?

I have a SharePoint list column of type 'Single line of text'. Out of the box SharePoint only provides the ability to display a 'Count' total for this column type. I would like to be able to perform a custom aggregation on the data (specifically to sum numeric data held as text to overcome this deficiency).
I have found examples for doing something similar for calculated columns using XSLT and Javascript but I believe that both of these approaches fail where the data is paginated (only aggregating the subset of the list content displayed on screen).
I want to retain the functionality of the ListViewWebPart (rendering, sorting, filtering, view definition, action menus etc.) but add this functionality. How can I do this?
The only things you can do with totals are:
Average; Count; Max; Min; Sum; Standard Deviation; Variance
Not sure how to calculate anything else.
I've not had a chance to fully test it but this is the best I could come up with:
Create a WebPart which contains two controls:
A ViewToolBar with the context of the list/view to be displayed
A Literal containing the rendered HTML of the view to be displayed
This will then render as the original list/view.
On rendering the WebPart, get the items from the view, specifying the RowLimit as the maximum value so that all items in are retrieved (not just the first page).
Iterate over the items, calculating the total in a suitable data type to retain precision.
Render the total as a hidden value in the HTML and overwrite the rendered Count total with Javascript such as by the method described here.
A rough sketch of the code:
public sealed class TextAggregatingWebPart : WebPart {
protected override void CreateChildControls() {
base.CreateChildControls();
var web = SPContext.Current.Web;
var list = web.Lists[SourceList];
var view = list.Views[ViewOfSourceList];
var toolbar = new ViewToolBar();
var context = SPContext.GetContext(
Context, view.ID, list.ID, SPContext.Current.Web);
toolbar.RenderContext = context;
Controls.Add(toolbar);
var viewHtml = new Literal {Text = view.RenderAsHtml()};
Controls.Add(viewHtml);
}
protected override void Render(HtmlTextWriter writer) {
EnsureChildControls();
base.Render(writer);
var web = SPContext.Current.Web;
var list = web.Lists[SourceList];
var view = list.Views[ViewOfSourceList];
var items = list.GetItems(new SPQuery(view) {RowLimit = uint.MaxValue});
foreach (SPItem item in items) {
// Calculate total
}
// Render total and Javascript to replace Count
}
}
Note that this doesn't solve the problem with the Modify View screen only showing Count as a total for text columns. Also there is a possibility that changes to the list between the initial rendering by the view and the retrieval of the items for aggregation could produce discrepancies between the total and the displayed items.

Resources