Friday, September 20, 2013

FINDING LOCATORS FOR SELENIUM

 USING XPATH:

Some examples:
//li[@id='partner360__adnpayment']
//input[@id='']/following-sibling::img
//input[@name='orgstatus_active_type']/following-sibling::label[text()='$Value']/preceding-sibling::img
//table[@class = 'x-btn-wrap x-btn op-btn-standard']//following::button[text() ='Apply']
//table[@class='']//folowing::button[text()='Apply']
//a[contains(text()='')]
//label[contains(text()='']
//div[@id='dynamicAcctFormDetails']//input[@name= 'creditStatus']/following-sibling::img
//*[@id='acct-save-id']
"//*[@class='x-btn-menu-arrow-el' and @type ='button']
//a[contains(text(),'Save and Close')]"
//table[@id='user-save-id']/tbody/tr/td[2]/em/button
//div[text()='Users' and contains (@class,'op-listitem')]
//div[text()='xyz' and contains(@class,'something')]
//div[text()='xys' and contains(@class,'something')]
//input[@id='']/following-sibling::img
//div[contains(@class,'auto_payments_summary_grid')]//div[contains(text(),'Sales Order: ') ]

QUICK HELP FOR FINDING  LOCATORS IN EXT JS-3

BUTTON        //table[@id='adnetwork-partner-active-id']/tbody/tr/td[2]/em/button
BUTTON        //button[text()='Submit']
IMG            css=div#.x-panel-collapsed .x-accordion-hd .x-tool-toggle ~ span:contains('$TEXT')
SELECTLIST    //input[@id = 'operation']/following-sibling::img
TABLECOL    //div[@class='x-grid3-cell-inner x-grid3-col-status' and contains(text(), '$TEXT')]
BUTTON        //table[@id='opr-button-pushtoadserver']//button[text()='Push to Ad Server']
TEXT        //label[text() = 'Targeting Name:']//following::input[@name ='name']
BUTTON        //label[text() = 'Targeting Name:']//following::button[text() ='Apply']
BUTTON        //label[text() = 'Targeting Name:']//following::button[text() ='Reset']
BUTTON      //div[@id='orgDetails']//span[text()='Payment Terms - Standard Cost Deductions' and contains(@class,'x-panel-header-text')]
TABLECOL    //div[@id='invoiceperiods']//div[@class='x-grid3-body']//div[@class='x-grid3-body']/div[$iRow]/table/tbody/tr/td[8]




USING CSS ADVANCED:

(BELOW CONTENT IS TAKEN FROM SAUCE_LABS)

Next sibling

Our first example is useful for navigating lists of elements, such as forms or ul items. The next sibling will tell selenium to find the next adjacent element on the page that’s inside the same parent. Let’s show an example using a form to select the field after username.
1
2
3
4
<form>
<input class="username"></input>
<input class="alias"></input>
</form>
Let’s write a css selector that will choose the input field after “username”. This will select the “alias” input, or will select a different element if the form is reordered.
1
css=form input.username + input

Attribute values

If you don’t care about the ordering of child elements, you can use an attribute selector in selenium to choose elements based on any attribute value. A good example would be choosing the ‘username’ element of the form without adding a class.
1
2
3
4
5
6
<form>
<input name="username"></input>
<input name="password"></input>
<input name="continue" type="button"></input>
<input name="cancel" type="button"></input>
</form>
We can easily select the username element without adding a class or an id to the element.
1
css=form input[name='username']
We can even chain filters to be more specific with our selections.
1
css=input[name='continue'][type='button']
Here Selenium will act on the input field with name=”continue” and type=”button”

Choosing a specific match

CSS selectors in Selenium allow us to navigate lists with more finess that the above methods. If we have a ul and we want to select its fourth li element without regard to any other elements, we should use nth-child or nth-of-type.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<ul id="recordlist">
<p>Heading</p>
    <li>Cat</li>
    <li>Dog</li>
    <li>Car</li>
    <li>Goat</li>
</ul>
If we want to select the fourth li element (Goat) in this list, we can use the nth-of-type, which will find the fourth li in the list.
1
css=ul#recordlist li:nth-of-type(4)
On the other hand, if we want to get the fourth element only if it is a li element, we can use a filtered nth-child which will select (Car) in this case.
1
css=ul#recordlist li:nth-child(4)
Note, if you don’t specify a child type for nth-child it will allow you to select the fourth child without regard to type. This may be useful in testing css layout in selenium.
1
css=ul#recordlist *:nth-child(4)

Sub-string matches

CSS in Selenium has an interesting feature of allowing partial string matches using ^=, $=, or *=. I’ll define them, then show an example of each:
^= Match a prefix
$= Match a suffix
*= Match a substring
1
css=a[id^='id_prefix_']
A link with an “id” that starts with the text “id_prefix_”
1
css=a[id$='_id_sufix']
A link with an “id” that ends with the text “_id_sufix”
1
css=a[id*='id_pattern']
A link with an “id” that contains the text “id_pattern”

Matching by inner text

And last, one of the more useful pseudo-classes, :contains() will match elements with the desired text block:
1
css=a:contains('Log Out')
This will find the log out button on your page no matter where it’s located. This is by far my favorite CSS selector and I find it greatly simplifies a lot of my test code.

Wednesday, September 18, 2013

Open a command prompt from folder without navigation

Just control+shift+r on the folder wer u need to launch the command prompt and select the open command window here option.
There u go!!



Wednesday, August 7, 2013

Some LINUX commands

1.Checkout:

svn checkout svn:/svn/automation_project/trunk .
 
2.compile in unix
javac -classpath commons-net-3.1.jar:mysql-connector-java-5.1.13-bin.jar:jxl.jar:servlet-api.jar DBConnection2.java
 
3.set classpath in unix
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin 
 
To compare two files ignoring differences in the case of the letters and blank spaces:
diff -iw part1 part_one
 
 

Sort Command Examples

Sort command in unix or linux system is used to order the elements or text. Sort command has the capability of sorting numerical values and strings. The sort command can order the lines in a text file.

The syntax of sort command is:

sort [options] filename
The options are:

-b : Ignores leading spaces in each line -d : Uses dictionary sort order. Conisders only spaces and alphanumeric characters in sorting -f : Uses case insensitive sorting. -M : Sorts based on months. Considers only first 3 letters as month. Eg: JAN, FEB -n : Uses numeric sorting -R : Sorts the input file randomly. -r : Reverse order sorting -k : Sorts file based on the data in the specified field positions. -u : Suppresses duplicate lines -t : input field separator
Sort Command Examples:

Before practicing the examples create the below two files in your unix system:

> cat order.txt Unix distributed 05 server Linux virtual 3 server Unix distributed 05 server Distributed processing 6 system > cat delim_sort.txt Mayday|4 Janmon|1 Declast|12
1. Sorting lines of text

The default sort command uses alphabetical order (ASCII order) to sort the file. It treats each line as a string and then sorts the lines.

> sort order.txt Distributed processing 6 system Linux virtual 3 server Unix distributed 05 server Unix distributed 05 server
2. Sorting based on the field positions.

You can specify the field positions using the -k option of sort command. The sort command uses the space or tab as the default delimiter. To sort based on the data in the second field, run the below command:

> sort -k2 order.txt Unix distributed 05 server Unix distributed 05 server Distributed processing 6 system Linux virtual 3 server
You can also specify more than field with k option as a comma separated list. The below command uses the second and fourth fields to sort the data.

> sort -k2,4 order.txt
3. Numeric sorting

Instead of the default alphabetical sorting order, you can make the sort command to sort in numeric order using the -n option. This is shown below:

> sort -nk3 order.txt Linux virtual 3 server Unix distributed 05 server Unix distributed 05 server Distributed processing 6 system
4. Sort in reverse order

By default, the sort command sorts the data in ascending order. You can change this to descending order using the -r option.

> sort -nrk3 order.txt Distributed processing 6 system Unix distributed 05 server Unix distributed 05 server Linux virtual 3 server
5. Suppressing duplicates or Print only unique values

You can produce only unique values in the output using the - u option of the sort command.

> sort -u order.txt Distributed processing 6 system Linux virtual 3 server Unix distributed 05 server
Another way is piping the output of sort command to uniq command.

> sort order.txt | uniq
6. Delimited file input

In the second, third and fourth examples we have sorted the data based on the field positions. Here the fields are separted by space or tab character. What if the fields are specifed by any other character? In such cases, we have to specify the input delimiter with the -t option. An example is shown below:

> sort -t'|' -nrk2 delim_sort.txt Declast|12 Mayday|4 Janmon|1
7. Sorting on months.

We can sort the data in the monthwise using the -M option of the sort command. This is shown below:

> sort -M delim_sort.txt Janmon|1 Mayday|4 Declast|12
 
Taken from http://www.folkstalk.com/2012/08/sort-command-examples-in-unix-linux.html
 
 
 

sed Case Insensitive Search Matching

 sed -e s/o1sales/o1adops/gI input_report_url.csv >i.csv 
 

Delete nonempty directory in Linux

rm -rf directoryname

Substring using bat command

>set fullname=c:\mypath\oldfile
>set changedname=%fullname:oldfile=newfile%
>echo %changedname%
c:\mypath\newfile
 
 
> set fullname=c:\mypath\oldfile
> set pathonly=%fullname:oldfile=%
> echo %pathonly%
c:\mypath\ 

Ref:http://stackoverflow.com/questions/2690382/substring-using-bat-command

Monday, July 29, 2013

TOMCAT STARTUP ISSUE :INFO: The APR based Apache Tomcat Native library which allows optimal performance in production


add a system property to the launch configuration of the tomcat server in eclipse.
 -Djava.library.path=c:\dev\tomcat\bin
And download the tcnative dll (or libnative.so for Linux) and put it in the bin folder.

Thursday, July 25, 2013

Start multiple instances of Selenium RC's and hub

Download seleniumgrid1 .navigate to the  folder and

1. create a batch file called rc_grid1.bat and paste the below

ant -Dport %1 -Denvironment="*firefox"  -DseleniumArgs="-userExtensions user-extensions.js " launch-remote-control

2.create a batch file called rc_hub and paste below

ant launch-hub

3.Launch hub and multiple RC's by creating another batch file called start_hub_rc.bat

start cmd /k Call rc_hub.bat 4444
pause 20
start cmd /k Call rc_grid1.bat 5555
start cmd /k Call rc_grid1.bat 6666
start cmd /k Call rc_grid1.bat 5570
start cmd /k Call rc_grid1.bat 5575
start cmd /k Call rc_grid1.bat 5580
start cmd /k Call rc_grid1.bat 5574
start cmd /k Call rc_grid1.bat 5578
start cmd /k Call rc_grid1.bat 7777
start cmd /k Call rc_grid1.bat 8888
start cmd /k Call rc_grid1.bat 9999
start cmd /k Call rc_grid1.bat 1010
start cmd /k Call rc_grid1.bat 1011
start cmd /k Call rc_grid1.bat 1012
start cmd /k Call rc_grid1.bat 1013
start cmd /k Call rc_grid1.bat 1014
start cmd /k Call rc_grid1.bat 1015
start cmd /k Call rc_grid1.bat 9998
start cmd /k Call rc_grid1.bat 1016
start cmd /k Call rc_grid1.bat 1017
start cmd /k Call rc_grid1.bat 1018
start cmd /k Call rc_grid1.bat 1019
start cmd /k Call rc_grid1.bat 1020
start cmd /k Call rc_grid1.bat 1021
start cmd /k Call rc_grid1.bat 1022
start cmd /k Call rc_grid1.bat 1023


You can see multiple rcs launched and connected to the hub.