sorting - Soritng Ascending and descending order after clicking on table header? -
i using selenium webdriver java. have table have click on header of each column , want validate whether sorting functionality working correctly or not. need check both asc
, desc
order.
so have take count of table first , header text click on each col 1-1 , need validate sorting.
how can achieve expected result. below html source code:
<div> <table cellspacing="0" rules="all" border="1" id="ctl00_contentplaceholder1_gvclinicaltrait" style="border-color:appworkspace;border-collapse:collapse;"> <tr class="gridtitlebar"> <th scope="col"><a href="javascript:__dopostback('ctl00$contentplaceholder1$gvclinicaltrait','sort$traitdate')">date collected</a></th><th scope="col"><a href="javascript:__dopostback('ctl00$contentplaceholder1$gvclinicaltrait','sort$traitdesc')">clinical trait data</a></th><th scope="col"><a href="javascript:__dopostback('ctl00$contentplaceholder1$gvclinicaltrait','sort$traitsourcedesc')">source</a></th><th scope="col"><a href="javascript:__dopostback('ctl00$contentplaceholder1$gvclinicaltrait','sort$traitvalue')">value</a></th> </tr><tr class="gridbody" align="left"> <td>11/6/2008</td><td style="width:200px;">a1c</td><td style="width:200px;">d</td><td>6.00</td> </tr><tr class="gridbody" align="left"> <td>9/17/2008</td><td style="width:200px;">bp</td><td style="width:200px;">e)</td><td>104/54</td> </tr><tr class="gridbody" align="left"> <td>7/12/2008</td><td style="width:200px;">bp</td><td style="width:200px;">g</td><td>124/56</td> </tr><tr class="gridbody" align="left"> <td>6/21/2008</td><td style="width:200px;">bp</td><td style="width:200px;">t</td><td>110/72</td> </tr><tr class="gridbody" align="left"> <td>6/14/2008</td><td style="width:200px;">bp</td><td style="width:200px;">n</td><td>120/70</td> </tr> </table> </div>
how can achieve expected result. below html source code:
- you need have list or array expected result.
you need create loop every test:
list<string> expectedvalues = new list<string>("12","13","14"); int expectednumber = expectedvalues.count; int tdnumber = 2; (int i=1; i< expectednumber; i++)
{ string result = driver.find(by.xpath("//div[@id ='ctl00_contentplaceholder1_gvclinicaltrait']/tr["+ +"]/td["+tdnumber+"]")).text;
if (result != expectedvalues[i]) assert.fail("wrong value!")
}
i didnt try code, if wrong it's pretty close code need.
Comments
Post a Comment