Thursday, July 31, 2014

Selenium: svg tags and Css Selectors


SVG tags and Css Selectors


Sample:
<div id="fsdf" class="dsdfds"/>
    <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="264" height="250"/>
        <defs/>
        <rect rx="dsfd" ry="45" fill="sdf"/>
                <g class="highcharts-tracker" zIndex="1"/>  
                    <g />  
                        <rect fill="rgb(123,222,222)   NEED TO GET HERE  />


example :
1. //[local-name()='svg']
2. //*[local-name()='svg']
3. //*[local-name()='svg']//*[local-name()='g']
4. //*[local-name()='svg']//*[local-name()='g'][1]
5. //*[local-name()='g'][@class='highcharts-tracker']/*[local-name()='g']
6. //*[local-name()='g'][@class='highcharts-tracker']/*[local-name()='g']/*[local-name()='rect'][1]

7. //*[@class='highcharts-tracker']/*[local-name()='g']/*[local-name()='rect'][1]
8. //*[@class='highcharts-tracker']//*[local-name()='rect'][1] 

driver.findElement(By.xpath("//*[@class='highcharts-tracker']//*[local-name()='rect'][1]")).click()


OTHER EXAMPLES
driver.findElement(By.cssSelector("//*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']//*[local-name()='tspan' and text()='Me']"));  
driver.findElement(By.cssSelector("//*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']//*[local-name()='tspan' and text()='You']"));  
driver.findElement(By.cssSelector("//*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']//*[local-name()='tspan' and text()='None']")); 

Ref:
http://automatethebox.blogspot.in/2012/10/how-to-locate-element-in-svg-tag-in.html
https://code.google.com/p/selenium/issues/detail?id=6441

 
 
  

Selenium : System Information

Selenium : System Information

  • System.getProperty("os.name")
  • System.out.print((RemoteWebDriver) driver).getCapabilities().toString())



---------------------------------------------------------------------------------------------------


/Created By:Deepak
//how to use  : 1.Send your driver as arguement
//    This function returns dictionary variable .
//    sys_info.get("browserName");
//    sys_info.get("version");
//    sys_info.get("os_name");
//    sys_info.get("os_version");
     
      static Dictionary system_info(WebDriver driver)
      {
            String browsername="",version="";
            System.out.println(System.getProperty("os.name"));
            String[] a=((RemoteWebDriver) driver).getCapabilities().toString().split(",");
                       
            for(int i=0;i<=a.length-1;i++){
                  if(a[i].contains("browserName"))
                        browsername=a[i];
                  else if(a[i].contains("version"))
                        version=a[i];
            }
            Dictionary sys_info=new Hashtable();
            sys_info.put("browserName", browsername);
            sys_info.put("version", version);
            sys_info.put("os_name", System.getProperty("os.name"));
            sys_info.put("os_version",System.getProperty("os.version"));
            return sys_info;
      }
-----------------------------------------------------------------------------------------

Monday, July 28, 2014

Selenium : Display frame name and switch using frame names

Selenium : Display frame names when frame id is not present



List<WebElement> ele = driver.findElements(By.tagName("frame"));
                System.out.println("Number of frames in a page :" + ele.size());
                for(WebElement el : ele){
                  //Returns the Id of a frame.
                    System.out.println("Frame Id :" + el.getAttribute("id"));
                  //Returns the Name of a frame.
                    System.out.println("Frame name :" + el.getAttribute("name"));
                }

Monday, July 21, 2014

QTP : Open different browsers

Open different browsers




SystemUtil.Run "iexplore.exe" ,"url"
SystemUtil.Run "firefox.exe" ,"url"
SystemUtil.Run "chrome.exe" ,"url"

misc :Disable Chrome update


Disable Chrome update


Process 1
  1.     On your Chrome browser's address bar, type in 'about:plugins' and hit ENTER.
  2.     Find the plugin called 'Google Update' and click disable.
  3.     Restart your browser for the changes to take effect.

Process2
  1.     Control Panel -> Administrative Tools -> Schedules Tasks (or search for Task Scheduler in Control Panel) . Look for Active Tasks, delete all Google Auto Updates Tasks
  2.     From Chrome browser, open chrome://plugins/ , disable Google Update.
  3.     From Start menu, run msconfig.exe -> Start up tab, disable Google Update ( though it seems automatically come up again)




Monday, July 7, 2014

Selenium :Array Vs Listes Vs Map Vs Set Vs Queues

Listes Vs HashTable Vs Queues

Looping through set,map,list

There are mainly 3 common segregation :

  •  Listes = Similar to array but has add,remove,sort,not need to declare size and can store any datatype.

  •  Set =Similar to Lists but no duplicates

  •  Map = Similar to dictionary

Lists

Lists allow duplicate items, can be accessed by index, and support linear traversal.

Array Vs List

    (1) The size of the arrays is fixed:

    (2) Inserting a new element in an array of elements is expensive, because room has to be created for the new elements and to create room existing elements have to shifted.

    (3) Deletion not possbile with arrays until unless some special techniques are used.

    (4) Tests executing the following statements:
    • createArray10000: Integer[] array = new Integer[10000];
    • createList10000: List<Integer> list = new ArrayList<Integer>(10000);
     5) Performance :
     Results (in nanoseconds per call, 95% confidence):
    a.p.g.a.ArrayVsList.CreateArray1         [10.933, 11.097]
    a.p.g.a.ArrayVsList.CreateList1          [10.799, 11.046]
    a.p.g.a.ArrayVsList.CreateArray10000    [394.899, 404.034]
    a.p.g.a.ArrayVsList.CreateList10000     [396.706, 401.266]
    Conclusion: no noticeable difference in performance.

    (6) Also Arraylist becomes the most flexible , when you have ArrayList Objects .ArrayList object satisfies all the above points and also can store any Datatype .

    Example :
    import java.util.ArrayList;
    import java.util.List;
    public class ArrayLst {
        public static void main(String... args)
        {
            ArrayList al = new ArrayList();
            al.add("Java4s");
            al.add(12);
            al.add(12.54f);
            for(int i=0;i<al.size();i++)
            {
                Object o = al.get(i);
                if(o instanceof String || o instanceof Float || o instanceof Integer)
                System.out.println("Value is "+o.toString());    
            }
        }
    }
     
    Output :
    Value is Java4s
    Value is 12
    Value is 12.54

      Maps Vs Dictionary

      Hashes are look-ups in which you give each item in a list a "key" which will be used to retrieve it later. . Duplicate keys are not allowed.
      • HashMap - A basic key-value-pair map that functions like an indexed list.
      • Dictionary - A hashtable that supports generic types and enforces type-safety.
       http://stackoverflow.com/questions/2889777/difference-between-hashmap-linkedhashmap-and-treemap
      • HashMap is implemented as a hash table, and there is no ordering on keys or values.
      • TreeMap is implemented based on red-black tree structure, and it is ordered by the key.
      • LinkedHashMap preserves the insertion order
      • HashTable do not allow null keys and null values in the HashTable(Slow and Old )

      Note :Why use HashMap instead of Dictionary and Hastable

      http://stackoverflow.com/questions/2884068/what-is-the-difference-between-a-map-and-a-dictionary

      Dictionary = abstract class in Java 
      Map = interface. 

      Since, Java does not support multiple inheritances, if a class extends Dictionary, it cannot extend any other class.Therefore, the Map interface was introduced.Dictionary class is obsolete and use of Map is preferred.

      Queues

      Queues control how items in a list are accessed. You typically push/pop records from a queue in a particular direction (from either the front or back). Not used for random access in the middle.
      • Stack - A LIFO (last in, first out) list where you push/pop records on top of each other.
      • Queue - A FIFO (first in, first out) list where you push records on top and pop them off the bottom.

      Sunday, July 6, 2014

      QTP : Important operations

      QTP : Important operations





      DATASHEET:


      GLOBAL SHEET
      A
      B
      C



      3





      1







      LOCAL SHEET
      A
      B
      C



      a





      b





      c






      To : Fetch only those cells from localsheet which  has been mentioned in Global sheet .ie., fetch only 3 and 1 cell in the same order from local sheet .
      Output: ca
       
      rowcount = DataTable.GetSheet("Global").GetRowCount  
      for i=1 to rowcount step 1
      DataTable.GetSheet("Global").SetCurrentRow(i)      
      val=DataTable.Value("A","Global")                              '
      DataTable.GetSheet("Local").SetCurrentRow(val)
      msgbox (DataTable.Value("A","Local")
      next

      WEBTABLE
      r=Browser("Google").Page("title:=.*").WebTable(“name:= TTable").RowCount 
      c=Browser("Google").Page("title:=.*").WebTable(“name:=TTable").ColumnCount(r)
      strData= Browser("Google").Page("title:=.*").WebTable(“name:=TTable").GetCellData(1,1)
      Set ChldItm = Browser("Google").Page("title:=.*").WebTable(“name:=TestTable,"index:=0").ChildItem(1,1,"micclass",index)

      if(ChldItm .GetRoproperty("micclass")<>"Page") then
      .....
      ....
      end if

      EXCEL:
      Set xl = createobject("excel.application")
      xl.Visible = True
      Set Wb= xl.Workbooks.Open("C:\qtp1.xls")
      Set  ws=Wb.Worksheets("Sheet1")
      Row=ws.UsedRange.Rows.Count

      data = ws.cells(1,1).value

      wb.saveas" "
      wb.save
      wb.close
      xl.quit

      DATABASE
      Set con=createobject("adodb.connection")
      Set rs=createobject("adodb.recordset")

      con.open"Driver={SQL Server};server=MySqlServer;uid=MyUserName;pwd=MyPassword;database=pubs"
      rs.open "select * from emp",con

      Do while not rs.eof
      VbWindow("Form1").VbEdit("val1").Set rs.fields("v1")
      VbWindow("Form1").VbEdit("val2").Set rs.fields("v2")
      VbWindow("Form1").VbButton("ADD").Click
      rs.movenext
      Loop

      'Release objects'Release objects
      Set rs= nothing
      Set con= nothing

      FILES , FOLDERS
      Set fso=createobject("Scripting.FileSystemObject")

      Set ctrl__folder=fso.GetFolder(Sourcefolder)
      Set  sub_folder=get_folder.SubFolders
      Set  sub_files =get_folder.Files

      for each i in sub_folder
                     sub_folder.name
      next

      TEXT FILE
      Set txt=fso.CreateTextFile("C:\qtptest.txt")
      Set ctrl_file=fso.getfile("C:\qtptest.txt")
      Set txt_file=ctrl.openastextstream(1)

      Do while txt_file.AtEndOfStream <> true
      Msgbox  txt_file.ReadLine 
      Loop
      ----------------------------------------------------------------------------
      ·        mid("ABC",1,2)     'answer=AB
      ·        instr(1,"ABC","B") 'answer=2
      ·        len("ABC")     'answer=3
      ·        ubound(a,2)   ' a(2)(3) ---answer=3