PDA

View Full Version : How do I traverse grids



RameshM
18 May 2017, 11:19 PM
Hi,

I need some help while using ST in grids

What I've done in grid:
1. Double click a row in grid by mentioning the record index.
Sample code:
ST.play([ { type: "click", target: "#gridID => [data-recordindex="0"]", x: 192, y: 13, detail: 2 } ]); //code to double click 0th row of a grid
2. Validating text in a particular cell.
Sample code:
ST.grid('#gridID').rowAt(1).cellAt(1).text('text to be checked') // working! But waits for text to match. If text doesn't match the test will be terminated.

Facing issues in grid:
1. Couldn't check content in grid properly.
2. Couldn't check/uncheck a checkbox in a grid.
3. Getting number of rows and columns in a grid.
4. How to access components in a grid
5. How to check whether a particular text exists in any of the rows in a column

Request the experts to help me out with suitable code for tackling the above issues.

joel.watson
19 May 2017, 6:11 AM
Hi Ramesh--

I'll answer each question in red below.

1. Couldn't check content in grid properly.
Based on your description, it appears to be working as expected. The text() API method is designed as something of an implicit assertion...it will wait up to the timeout duration for the given state to be achieved. If the state changes and the condition is met, it will allow the event queue to proceed to the next event; otherwise, it will timeout. What is the alternative behavior you are expecting/desiring?

2. Couldn't check/uncheck a checkbox in a grid.
How are you trying to do this? You should conceivably be able to do this by retrieving the desired cell, and then selecting the correct element beneath it via the API, and which point you should be able to call click() on it.

3. Getting number of rows and columns in a grid.
There are currently no APIs on the Grid future to achieve this. However, you could always use the Ext JS grid APIs to retrieve that information.

4. How to access components in a grid
By "components", are you talking about docked items like toolbars? If so, you could use the gotoComponent() (http://docs.sencha.com/sencha_test/2.1.0/api/ST.future.Component.html#method-gotoComponent) method to traverse the hierarchy.

5. How to check whether a particular text exists in any of the rows in a column
You can use the rowWith() (http://docs.sencha.com/sencha_test/2.1.0/api/ST.future.Grid.html#method-rowWith) method with the following syntax:


rowWith('propertyName', 'propertyValue') => rowWith('salary', '50000');

Jagath
22 May 2017, 9:01 PM
There are currently no APIs on the Grid future to achieve this. However, you could always use the Ext JS grid APIs to retrieve that information.

Could you please tell me how can I use ExtJS grid API in Sencha Test?

Thanks in advance.

Jagath

RameshM
22 May 2017, 9:18 PM
Hi Joel,

Thanks a lot for your detailed reply.
Needed some inputs:

1. Couldn't check content in grid properly.
Based on your description, it appears to be working as expected. The text() API method is designed as something of an implicit assertion...it will wait up to the timeout duration for the given state to be achieved. If the state changes and the condition is met, it will allow the event queue to proceed to the next event; otherwise, it will timeout. What is the alternative behavior you are expecting/desiring?
RM - Is there some command which does not timeout and exit the code when it fails. Desired behavior is that it logs an error and continues to the next line in the script


3. Getting number of rows and columns in a grid.
There are currently no APIs on the Grid future to achieve this. However, you could always use the Ext JS grid APIs to retrieve that information
RM - Could you please explain with an example code as to how this can be done?

Need help on another thing:
How to check whether the values in a particular column in a grid are sorted Ascending or descending order?

Awaiting your response
Ramesh

joel.watson
23 May 2017, 4:00 AM
1. Couldn't check content in grid properly.
RM - Is there some command which does not timeout and exit the code when it fails. Desired behavior is that it logs an error and continues to the next line in the script

I can log a feature request for this.


3. Getting number of rows and columns in a grid.
RM - Could you please explain with an example code as to how this can be done?

Without knowing your application in more detail, a precise solution is not possible. However, to retrieve the number of visible columns, you could call getVisibleColumns() on the instance of the Ext JS grid. This will return an array whose length should represent the columns that are currently visible.

The row count is a bit trickier, depending on whether the grid is buffered or not. If not, you could simply get the count of records from the grid's store. Otherwise, you'd need to interrogate the grid's view to determine the number of currently rendered rows.

Need help on another thing:
How to check whether the values in a particular column in a grid are sorted Ascending or descending order?

You should be able to retrieve the desired column, call getSorter(), and then call getDirection() on the sorter object.

Jagath
23 May 2017, 7:02 AM
Joel,

Could you please give an example for #3. You can use http://examples.sencha.com/extjs/5.1.0/examples/kitchensink/#array-grid

I tried ST.grid('#myGrid').get('store') and Ext.ComponentQuery.query('#myGrid').getStore() to retrieve store but both are not working. When I debug the script Ext is defined but nothing in it.


You should be able to retrieve the desired column, call getSorter(), and then call getDirection() on the sorter object.
Using getSorter() method we can get the direction and column, but it does not mean the content is sorted right?. Do you have any idea how to validate the content?

Thanks in advance,
Jagath

joel.watson
23 May 2017, 7:07 AM
Joel,

Could you please give an example for #3. You can use http://examples.sencha.com/extjs/5.1.0/examples/kitchensink/#array-grid

I tried ST.grid('#myGrid').get('store') and Ext.ComponentQuery.query('#myGrid').getStore() to retrieve store but both are not working. When I debug the script Ext is defined but nothing in it.


Using getSorter() method we can get the direction and column, but it does not mean the content is sorted right?. Do you have any idea how to validate the content?

Thanks in advance,
Jagath

What kind of scenario are you running? In-browser, or web-driver based? Thanks
Joel

Jagath
23 May 2017, 8:42 PM
Joel,

I am doing this in browser scenario currently, but it would really help if you could explain it for both scenarios.

Could you please explain why we need separate script for both In-browser and web-driver?

Thanks,
Jagath

joel.watson
24 May 2017, 10:25 AM
Joel,

I am doing this in browser scenario currently, but it would really help if you could explain it for both scenarios.

Could you please explain why we need separate script for both In-browser and web-driver?

Thanks,
Jagath

For WebDriver-based scenarios, the context in which the spec itself is executed does not have access to the scripts which are running in the target browser which is being communicated to via WebDriver, while for in-browser scenarios, the spec shares an execution context with the target browser.

So for in-browser scenarios, you can directly interact with Ext JS components (and anything else in the DOM, for that matter). WebDriver scenarios, on the other hand, need to use the execute() (http://docs.sencha.com/sencha_test/2.1.0/api/ST.html#method-execute) method to specifically execute code within the context of the target browser.

Thanks!
Joel

Jagath
24 May 2017, 10:59 PM
Joel,

Thanks for your response. I wrote function to get the count.



function getRowCount(selector,callback){
it("Get rows count",function(){
ST.element(selector).execute(function () {
var grid = Ext.ComponentQuery.query(this.future.locatorChain[0].locator)[0],
store = grid.getStore(),
itemCount = store.getCount();
return itemCount;
}).and(function (future) {
if(callback) callback(future.data.executeResult);
});
});
}


Is there any function to check whether the test case runs in Web-driver or In-browser?

Thanks in advance,
Jagath

joel.watson
25 May 2017, 8:45 AM
Hi Jagath--

This isn't currently documented, but you could check ST.isSandbox property (where "true" is WebDriver-based scenario).

Thanks!
Joel

marcelofarias
30 May 2017, 2:18 PM
You can try this:


ST.defaultContext.isWebDriverContext

Be careful, however:

It is not part of the public API. Although unlikely, it might be deprecated in the future.
Trying to share context-sensitive code between in-browser and WebDriver scenarios is very likely to lead to headaches in terms of maintainability of your tests in the future.


Regards