Friday, 13 March 2015

PRACTICE FOR XPATH

Locators:

1.ID
2.name
3.Partiallinktext
4.LinkText
5.classname
6.CSSselector
7.Xpath



Using ID:

copy html code for tat particular element ...paste in Notepad...


<input id="username" class="textField" type="text" value="" name="username" 
   placeholder="Username">



Step 1:

driver. findelement(By.id("username")).sendkeys("admin");

Step 2:using xpath

//tagname [@property name='propertyvalue']


tagname= input

property name= id

property value = username


Xpath: //input[@id='username']



NOTE:

If  id  value is number present  dont take id....plz remeber...dont take id...
 eg..

<input id="gs_taif0" class="gsfi" disabled="" autocomplete="off" aria-hidden="true" style="border: medium none; padding: 0px; margin: 0px; height: auto; width: 100%; position: absolute; z-index: 1; background-color: transparent; color: silver; left: 0px;" dir="ltr">


tagname= input

property name= id

property value= gs_taif0  -- here 0 is number  so dont take id..bcz it wil change every refresh..



Using NAME:

<input id="username" class="textField" type="text" value="" name="username" 
   placeholder="Username">

Step 1:

driver. findelement(By.name("username")).sendkeys("admin");

Step 2:using xpath

synatax:

//tagname [@property name='propertyvalue']


tagname= input

property name= name

property value = username


Xpath: //input[@name='username']



Note:

If id is has Number in property value  than give prepference to name......       




Using Text:

<label id="keepLoggedInLabel" for="keepLoggedInCheckBox" 
   style="-moz-user-select: none; cursor: default;">Keep me logged in</label>


tagname= label

property name= text

property value = Keep me logged in



syntax

//tagname[ property name()= 'property value']

//label[text()='Keep me logged in']



Note:

for text mostly use  "contains" bcz sme gap wil be there.....if space is thr r not use  "contains"

actually tats is gud..to find text.....

Syntax

//tagname[ contains( property name,'property value')]

//label[contains(text(),'Keep me logged in')]




CSS selector-  Cascaded  Style sheet

syntax

htmltag [Property name='property value']



<input id="username" class="textField" type="text" value="" name="username" 
   placeholder="Username">


htmltag = input

property name= name

property value = username



CSS:   input[name='username']

            input[type='text']   or   in firepath u can see  css option is thr u can use tat one...

  

Using xpath:

This is gud way to find element.....


<input type="submit" jsaction="sf.chk" name="btnK" aria-label="Google Search" value="Google Search">


syntax

//tagname[@property name='Property value']


tagname= input


property name= value


property value = Google



1.//input[@value='Google']


2.//input[@name='Google']


3.//input[@type='Google']


4.//input[@style='Google']


5.//input[@id='Google']



6.//input[text()='Google']

7.//input[contains(text,'Google')]


8.
//input[@value='Google']/../../...     tis new action nwdys using to go parent element


Relative xpath:

eg;

<table style="width:100%">
  <tr>
    <td>Jill</td>
    <td>Smith</td> 
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td> 
    <td>94</td>
  </tr>
</table>



//td[text()='Eve']

parent element

//tr[td[text()='Eve']]


new method nowdys using tis way....


//td[text()='Eve']/..                 tis go to tr parent element



//td[text()='Eve']/../tr[2] 



Using Gruop Index

check in html  code if hve same id nd same name nd same value nd same classname...

thn go for group index...




(//div)[2]

(//div)[3]

To find last element in group index we use ...(las t ) word... first word not possible...

(//div)[last]


Sunday, 8 March 2015

Selenium Grid

What is Selenium Grid?


Selenium Grid is a part of the Selenium Suite that specializes on running multiple tests across different browsers, operating systems, and machines in parallel.


What is a Hub and Node?

The Hub

  • The hub is the central point where you load your tests into.
  • There should only be one hub in a grid.
  • The hub is launched only on a single machine, say, a computer whose OS is Windows 7 and whose browser is IE.
  • The machine containing the hub is where the tests will be run, but you will see the browser being automated on the node.

The Nodes

  • Nodes are the Selenium instances that will execute the tests that you loaded on the hub.
  • There can be one or more nodes in a grid.
  • Nodes can be launched on multiple machines with different platforms and browsers.
  • The machines running the nodes need not be the same platform as that of the hub.


Tell  u one gud way to test  selenium grid...

1.create three folders  any drive C OR D drive...
      eg:
            folder name  like give

                     1. test1
                     2.test2
                     3.test3

2.keep selenium server standalone jar file in all three folders..

TEST1 FOLDER -HUB

first TEST1 folder..inside keep selenium server standalone -change  to name to...( sss ) y because easy to type in cmd prompt...





TWO WAYS U CAN START HUB...

1.FIRST STEP

type in cmd prompt

eg..Default C drive change to E ......type E: --enter --change to  E drive..thn  type cd test1 ..thn type blow code

code: java -jar sss.jar -role hub









2.SAME  STEP DIFFERENT WAY

1.open notepad  paste tis code inside notepad...

code :   java -jar sss.jar -role hub

save  name as -(test1.bat)------ save as inside TEST1 folder..





double click on  test1.bat  file it wil open cmd prompt and created as hub





Then type in firefox or chrome.. as ---- localhost:4444

it opens page like as below






TEST2 FOLDER - NODE1


same thing do for test2 folder also

1.keep selenium server standalone  jar file
2.create bat file inside test2 folder also

FIRST STEP:

1.go to cmd prompt set to path upto test2 folder..thn type blow code

code:java -jar sss.jar -role node -hub http://192.168.43.16:4444/grid/register -port 5566






PRESS ENTER -it wil display below like screen-means node created































Refresh in chrome or firefox once ...u can see down screen..




















Running a Sample Test Case on the Grid