Search code examples
pythonswingcheckboxjtablemarathontesting

marathonITE script to tick a checkbox in a JTable cell


I'm using marathonITE testing tool to automate testing of a java swing application.

In one of the windows i have a JTable with 6 columns and N number of rows. Two columns of that table are checkbox type columns.

My requirement is to write the automation script to tick the check box when the row and column is given.

select('table', 'true', '[row=1][column=0]')

I tried this line but it directs the script to

class Fixture:


def teardown(self):
    '''Marathon executes this method at the end of test script.'''
    pass

which then stops the process.

Is there a way to tick the checkbox within a table when column and row is given?


Solution

  • I found a workaround for this problem. In the first part i traverse through the table and checks whether the test value is equal to each of those cell values. In the second part i use keystrokes to traverse to that particular row and column and use space and enter keystrokes to tick the check box.

    Note that this method works only for checking a single check box. For multiple check boxes will have to traverse back using key strokes and re do the keystroke traversing.

    #1st Part
    
                textValue = "Test Value"
                deplTable = get_component('table')
                no_of_columns = deplTable.getColumnCount()
                no_of_rows = deplTable.getRowCount()
    
                for col in range (no_of_columns):
                    if ( col == 1 or col == 4 ):
                        for row in range (no_of_rows):
    
                            if ( deplTable.getValueAt( row ,col) == textValue ):
                                print 'Found at row:',row,' col:',col
    #2nd Part
                                for x in range (row+1) :
                                    keystroke('table', 'Down')
                                keystroke('table', 'Left')
                                if ( col > 1 ):
                                    for  y in range (col-1) :
                                        keystroke('table', 'Right')
    
                                keystroke('table', 'Space')
                                keystroke('table', 'Enter')