Coded UI: getcell not working for Wpftable having XamDataGridCustom in the hierarchy - coded-ui-tests

I am new to Coded UI coding so need some help for the below problem I am facing.
I have a WPftable which has the below hierarchy in the UI Map:
this.UICommissionEngineMainWindow.UIXamDataGridCustom.UIRecordsTable
I need to read the cell value from the above table and cells have the below hierarchy:
this.UICommissionEngineMainWindow
.UIXamDataGridCustom
.UIRecordsTable
.UIItemDataItem
.UIItem2443Cell
.UITextBlockText;
When I run the below line of code which has 'GetColumnName' and 'ColumnCount' method it works:
var myrecord = this.UICommissionEngineMainWindow
.UIXamDataGridCustom
.UIRecordsTable.GetColumnNames();
MessageBox.Show(this.UICommissionEngineMainWindow
.UIXamDataGridCustom
.UIRecordsTable
.ColumnCount.ToString());
But when I try to retrieve the cell data it fails. I tried several ways but everytime it fails with
Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException‌​: The playback failed to find the control with the given search properties.
Additional Details:
TechnologyName: 'UIA'
FrameworkId: 'Wpf'
ControlType: 'Cell'
RowIndex: '1'
ColumnIndex: '1'
Search may have failed at 'Records' Table as it may have virtualized children. If the control being searched is descendant of 'Records' Table then including it as the parent container may solve the problem.System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.
First Try
this.UICommissionEngineMainWindow
.UIXamDataGridCustom
.UIRecordsTable
.GetCell(1, 1)
.Value.ToString());
ALTERNATIVE:
//GetProgramTablehas the Wpftable object in it
var cell = new WpfCell(GetProgramTable());
int row = 1;
int column = 1;
foreach (var data in dataitem.FindMatchingControls())
{
var cell = new WpfCell(data);
cell.SearchProperties.Add(WpfCell.PropertyNames.RowIndex, row.ToString());
cell.SearchProperties.Add(WpfCell.PropertyNames.ColumnIndex, column.ToString());
MessageBox.Show(cell.FindMatchingControls().Count.ToString());
}
ALTERNATIVE:
cell.SearchProperties.Add(WpfCell.PropertyNames.ColumnHeader, "Name");
cell.SearchProperties.Add(WpfCell.PropertyNames.Value, "2143");
MessageBox.Show(cell.FindMatchingControls().Count.ToString())
I am wondering when GetcolumnNames and ColumnCount works why the GetCell doesnt work.

Related

Where is my error with my join in acumatica?

I want to get all the attributes from my "Actual Item Inventry" (From Stock Items Form) so i have:
PXResultset<CSAnswers> res = PXSelectJoin<CSAnswers,
InnerJoin<InventoryItem,
On<CSAnswers.refNoteID, Equal<Current<InventoryItem.noteID>>>
>
>.Select(new PXGraph());
But, this returns me 0 rows.
Where is my error?
UPDATED:
My loop is like this:
foreach (PXResult<CSAnswers> record in res)
{
CSAnswers answers = (CSAnswers)record;
string refnoteid = answers.RefNoteID.ToString();
string value = answers.Value;
}
... but i can not go inside foreach.
Sorry for the English.
You should use an initialized graph rather than just "new PXGraph()" for the select. This can be as simple as "this" or "Base" depending on where this code is located. There are times that it is ok to initialize a new graph instance, but also times that it is not ok. Not knowing the context of your code sample, let's assume that "this" and "Base" were insufficient, and you need to initialize a new graph. If you need to work within another graph instance, this is how your code would look.
InventoryItemMaint graph = PXGraph<InventoryItemMaint>.CreateInstance<InventoryItemMaint>();
PXResultset<CSAnswers> res = PXSelectJoin<CSAnswers,
InnerJoin<InventoryItem, On<CSAnswers.refNoteID, Equal<Current<InventoryItem.noteID>>>>>
.Select(graph);
foreach (PXResult<CSAnswers> record in res)
{
CSAnswers answers = (CSAnswers)record;
string refnoteid = answers.RefNoteID.ToString();
string value = answers.Value;
}
However, since you should be initializing graph within a graph or graph extension, you should be able to use:
.Select(this) // To use the current graph containing this logic
or
.Select(Base) // To use the base graph that is being extended if in a graph extension
Since you are referring to:
Current<InventoryItem.noteID>
...but are using "new PXGraph()" then there is no "InventoryItem" to be in the current data cache of the generic base object PXGraph. Hence the need to reference a fully defined graph.
Another syntax for specifying exactly what value you want to pass in is to use a parameter like this:
var myNoteIdVariable = ...
InventoryItemMaint graph = PXGraph<InventoryItemMaint>.CreateInstance<InventoryItemMaint>();
PXResultset<CSAnswers> res = PXSelectJoin<CSAnswers,
InnerJoin<InventoryItem, On<CSAnswers.refNoteID, Equal<Required<InventoryItem.noteID>>>>>
.Select(graph, myNoteIdVariable);
foreach (PXResult<CSAnswers> record in res)
{
CSAnswers answers = (CSAnswers)record;
string refnoteid = answers.RefNoteID.ToString();
string value = answers.Value;
}
Notice the "Required" and the extra value in the Select() section. A quick and easy way to check if you have a value for your parameter is to use PXTrace to write to the Trace that you can check after refreshing the screen and performing whatever action would execute your code:
PXTrace.WriteInformation(myNoteIdVariable.ToString());
...to see if there is a value in myNoteIdVariable to retrieve a result set. Place that outside of the foreach block or you will only get a value in the trace when you actually get records... which is not happening in your case.
If you want to get deep into what SQL statements are being generated and executed, look for Request Profiler in the menus and enable SQL logging while you run a test. Then come back to check the results. (Remember to disable the SQL logging when done or you can generate a lot of unnecessary data.)

how to add table within another table cell using only office api from the document editor plugin

We are trying to add table within another table cell using only office api from the document editor plugin. We tried to find out various methods like using Range, Run Command, ParagraphAddDrawing, AddElement etc. to do it , but are unable to find a way to achieve it.
Please advice us an proper way to achieve this using API as early as possible...
Regards
You need to get cell and use method Push() on it.
Example:
var oDocument = Api.GetDocument(); // getting document object
var oParagraph, oTable, oCell; // init variables
oTable = Api.CreateTable(3, 3); // creating new table object
oCell = oTable.GetRow(0).GetCell(0); //getting first cell in first row
oDocument.Push(oTable); // Push new table to document
oTable_two = Api.CreateTable(3, 3); // creating second table object
oParagraph = oCell.GetContent().Push(oTable_two); // pushing new table to first table

Grails, can't persist object in a while inside a for (object class with composite id)

I'm reading an Excel file with a 'for loop'. And I have no problem persisting 3 different instances of different classes that represents the firsts set of columns in the excel file.
But when I try to "while-loop" the next columns that represent a dynamic range of other objects I can't get them to persist in the DB. Nor with flush:true or anything.
for (int r = 6; r < sheet.rows; r++)
{
def fooInstance = new Foo()
def barInstance = new Bar()
def fooBarInstance = new FooBar()
//Set foo, bar and fooBar Instances properties based on the excel columns
def bazIndez = 11
while(bazIndex < sheet.columns){
def bazInstance = new Baz()
//set bazInstance properties
println bazInstance //Every property is ok
println bazInstance.getErrors() //0 errors
bazInstance.save() // .save(flush:true) didn't work either
bazIndez++
}
foo.save() //No problem here
bar.save() //No problem here
fooBar.save() //No problem here
}
fooInstance, barInstance and fooBarInstance get persisted, but bazInstance never is.
Note 1: All these object have no relationship with each other or with any other class.
Note 2: All these objects use composite id and "id generator: 'assigned'"
Grails 1.3.9
JDK 1.6
Thanks in advance.
I don't believe you can call getErrors() without first validating, as validation is what populates the list of errors.
Try running bazInstance.validate() before checking for errors. That should display any validation errors that are preventing the domain class from persisting.

Returning an Object[][] gives NullPointerException

I have an Access database which I need to retrieve all fields except the first and last and display it in a JTable. Everything works perfectly fine when I create my Object[][] but when i return it, i get a NullPointerException. I tried to find where there could be a null value in the database by printing the whole object out but that works fine and no values are null. Why would returning the Object[][] give me a NullPointerException and how can i fix it?
the stack trace is:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
public Object [] [] SetTrainingLogTable() throws SQLException
{
DatabaseConnection connection = new DatabaseConnection();
//Retrieves all the data from the TrainingLog table
ResultSet resultset = connection.SelectStatements("SELECT * FROM TrainingLog");
//Retrieves the number of entries
ResultSet numberofworkouts = connection.SelectStatements("SELECT COUNT(*) FROM TrainingLog");
int count = numberofworkouts.getInt(1);
number = count;
String[][] table = new String [count] [6];
//Number to incriment for while loops
int row = 0;
String date = "";
while(row<count)
{
date = resultset.getString(2);
table [row][0] = calculate.RefineDate(date);
table [row][1] = resultset.getString(3);
table [row][2] = resultset.getString(4);
table [row][3] = resultset.getString(5);
table [row][4] = resultset.getString(6);
table [row][5] = resultset.getString(7);
resultset.next();
row++;
}
Object[][] data = table;
connection.close();
return data;
}
I ran a debugger and it only gives the error when the return line is run.
It's best to post the stack trace and tell which line is raising the error. However, the typical way of writing such code is:
Connection con = ...;
Statement st = ...;
ResultSet rs = ...;
while (rs.next()) {
// ...
}
The result set starts out pointing before the first row. rs.next() returns whether there is a next row, and advances to it if it exists. Can you rewrite it in that style?
Other suggestions:
Can you create an actual object type instead of using Object[] to store the data from each row? Call it Workout.
Can you use a List<Workout> instead of your Object[][]?
Is the date stored in the database as a SQL DATE or TIMESTAMP? Then, don't convert it to a Java String: use java.sql.Date or java.util.Date. At work, I have a large old program that uses strings for dates, and it uses different formats to convert the values at different times. It's pretty miserable.
Don't use SELECT *. Give the names of the columns to return. Use the rs.getString("column_name") syntax.
There's no need to set one variable to the returned table and immediately set another variable to it.
Closing the connection or statement should be done in a finally block, or by try-with-resources.

Creating Data Table from object array

I am not sure if I am going about this the correct way but I have a c# method which loads an excel sheet into a 2 dimentional object array. In this array item 1,1 - 1,16 contain headers, then 2-1 - 2-16 contain data that match up with those headers as do x-1 - x-16 from there on in. I would like to turn this array into a data table so ultimately I can have it in a format I will then import into an access or SQL server db depending on a clients needs. I have tried using the following code to no avail, but I have a feeling I am way off. Any help on this would be very much appreciated.
private void ProcessObjects(object[,] valueArray)
{
DataTable holdingTable = new DataTable();
DataRow holdingRow;
holdingTable.BeginLoadData();
foreach(int row in valueArray)
{
holdingRow = holdingTable.LoadDataRow(valueArray[row], true);
}
}
Any chance you're using a repository pattern (like subsonic or EF) or using LinqToSql?
You could do this (LinqToSql for simplicity):
List<SomeType> myList = valueArray.ToList().Skip([your header rows]).ConvertAll(f => Property1 = f[0] [the rest of your convert statement])
DataContext dc = new DataContext();
dc.SomeType.InsertAllOnSubmit(myList);
dc.SubmitChanges();

Resources