Shrink all columns

Feb 2, 2010 at 7:43 AM

Hi

 

I try the following, but it does not work as expected

 

/// <summary>
/// Shrinks all columns.
/// </summary>
/// <param name="view">The view.</param>
public static void ShrinkAllColumns(ListView view)
{
  ListViewColumns columns = view.Header.Columns;

  foreach( ListViewColumn column in columns )
  {
	Thumb rightGripper = column.Get<Thumb>( SearchCriteria.ByAutomationId( "PART_RightHeaderGripper" ) );
	Thread.Sleep(500);
	int size = (int)column.Bounds.Width / 2;
	rightGripper.SlideHorizontally( size );
	Thread.Sleep(500);
  }
}


Anyway only the first one will be shrinked all other not :(

so I try to shrink only one big column

/// <summary>
/// Shrinks all columns.
/// </summary>
/// <param name="view">The view.</param>
public static void ShrinkColumn(ListViewColumn column)
{
  
  Thumb rightGripper = column.Get<Thumb>(SearchCriteria.ByAutomationId("PART_RightHeaderGripper"));
  Thread.Sleep(500);
  int size = (int)column.Bounds.Width / 2;
  rightGripper.SlideHorizontally(size);
  Thread.Sleep(500);
  
}

and it seems that the test click on the column and not on the gripper

The used Grid is the WPF Grid from the WPF Toolkit each column contains the a left and a right gripper and a edit field which is mostly not visible



any Ideas?

Throndorin

Feb 2, 2010 at 7:59 AM
Edited Feb 2, 2010 at 8:21 AM

Now I use

 

 

 

/// <summary>
/// Shrinks all columns.
/// </summary>
/// <param name="column">The column.</param>
public static void ShrinkColumn(ListViewColumn column)
{
  
  Thumb rightGripper = column.Get<Thumb>(SearchCriteria.ByAutomationId("PART_RightHeaderGripper"));
  Thread.Sleep(500);
  int size = (int)column.Bounds.Width / 2;

  MouseActionHelper mouseHelper = new MouseActionHelper();
  mouseHelper.MousePosX = (int)rightGripper.ClickablePoint.X;
  mouseHelper.MousePosY = (int)rightGripper.ClickablePoint.Y;

  mouseHelper.DragItem((int)column.Bounds.TopRight.X - size, (int)column.Bounds.TopRight.Y);

  //rightGripper.SlideHorizontally(size);
  Thread.Sleep(500);
}

 

this shrinks the column to (column with)/2 as I want.

another problem is that if I get the ListView again, and also the columns the position of the columns are not correct. it seems that in the column informations are the old positions are stored

the test cycle:

  • shrink a column to have all needed columns in view
  • get TopLeft.Bounds.X from column to move and store it
  • move column to be the second column and move back to old position
  • check that the position is the same as before (Greater or equal)

Code:

ListView view = _catalogs.Get<ListView>(SearchCriteria.ByAutomationId("dataGridCatalogs"));
int shrinkSize = MyListViewHelper.ShrinkColumn( view.Header.Columns.Where( p=>p.Name=="Beschreibung").First() );
Thread.Sleep( 1000 );

view = _catalogs.Get<ListView>(SearchCriteria.ByAutomationId("dataGridCatalogs"));
ListViewColumn columnToMove = view.Header.Columns.Where(p => p.Name == "Applikationsprogramm").First();
ListViewColumn columnToEnter = view.Header.Columns.Where(p => p.Name == "Name").First();
AutomationElementHelper.ScrollAutomationElement( columnToMove.AutomationElement );

// Get the position and save it
int headerItemButtonXPositionBefore = (int)columnToMove.Bounds.TopLeft.X - shrinkSize;
//int headerItemButtonYPositionBefore = (int)columnToMove.Bounds.TopLeft.Y;
// Prepare the mouse move
MouseActionHelper mouseActionHelper = new MouseActionHelper();
// Point the mouse on the most right header button
mouseActionHelper.MousePosX = (int)columnToMove.ClickablePoint.X;
mouseActionHelper.MousePosY = (int)columnToMove.ClickablePoint.Y;
// Get target to drop the header button on
int targetX = (int)columnToEnter.Bounds.TopLeft.X;
int targetY = (int)columnToEnter.Bounds.TopLeft.Y;
mouseActionHelper.DragItem( targetX, targetY );
Thread.Sleep( 100 );
// Compare the new position and the position before moving
view = _catalogs.Get<ListView>(SearchCriteria.ByAutomationId("dataGridCatalogs"));

columnToMove = view.Header.Columns.Where(p => p.Name == "Applikationsprogramm").First();
columnToEnter = view.Header.Columns.Where(p => p.Name == "Bestellnummer").First();
Assert.AreNotEqual( columnToMove.Bounds.TopLeft.X, headerItemButtonXPositionBefore );

// Prepare the second mouse move
MouseActionHelper mouseActionHelper2 = new MouseActionHelper();
// Point the mouse on the right panel (Topology)
mouseActionHelper2.MousePosX = (int)columnToMove.ClickablePoint.X;
mouseActionHelper2.MousePosY = (int)columnToMove.ClickablePoint.Y;
// Get target to drop the header button on
targetX = (int)columnToEnter.Bounds.TopLeft.X;
targetY = (int)columnToEnter.Bounds.TopLeft.Y;

// Drag it the header button back to its original position
AutomationElementHelper.ScrollAutomationElement(columnToMove.AutomationElement);
mouseActionHelper2.DragItem( targetX, targetY );
Thread.Sleep( 1000 );
view = _catalogs.Get<ListView>(SearchCriteria.ByAutomationId("dataGridCatalogs"));

columnToMove = view.Header.Columns.Where(p => p.Name == "Applikationsprogramm").First();
// Compare the last position and the position before moving - must be the same
Assert.GreaterOrEqual(columnToMove.Bounds.TopLeft.X, headerItemButtonXPositionBefore);

if I don't substract the shrink size before moving the test fails

Feb 16, 2010 at 12:57 PM

it seems if only the

rightGripper.SlideHorizontally(size); don't work if the value is negative


Coordinator
Feb 19, 2010 at 5:16 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Apr 12, 2010 at 10:29 PM

Hi Throndorin,

Where do I find the AutomationElementHelper class? I see you have used this in code fragments in a few threads.

Thx

Rob Smyth

 

 

AutomationElementHelper
Apr 13, 2010 at 6:17 AM

Hi RopbSmyth,

 

this is a helper class we have defined to handle specific UIAutomation things

it's nothing official.

 

Throndorin

 

 

Apr 13, 2010 at 10:04 AM
Throndorin wrote:

Hi RopbSmyth,

 

this is a helper class we have defined to handle specific UIAutomation things

it's nothing official.

 

 

 

Thanks Throndorin,

Any chance of a copy? I'm new to the UIAutomation things so would love such a utility.

 

Rob Smyth

Apr 13, 2010 at 10:19 AM

please send me your email address over my codeplex profile

 

Nov 2, 2010 at 2:53 AM

Hello,  I am also interested in knowing where do I find the helper class and would love to use this class as well.  May I send you my email as well?   Thanks.

Nov 2, 2010 at 8:19 AM

@Nonna14 you should have mail