Tuesday 28 January 2014

First Selenium Script

I have created object of Firefoxprofile and FireboxBinary class , so that Selenium can identify the firefox and run it.



import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxBinary;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.firefox.FirefoxProfile;

public class Test1 {
 
    public static void main(String[] args) {

     File f = new File("C:\\Program Files (x86)\\Mozilla Firefox15\\firefox.exe")   FirefoxBinary binary = new FirefoxBinary(f);
    FirefoxBinary binary = new FirefoxBinary(f);

     FirefoxProfile profile = new FirefoxProfile();
     profile.setPreference("webdriver.firefox.bin", "C:/Program Files (x86)/Mozilla Firefox15/");
     
WebDriver wd = new FirefoxDriver(binary,profile);

      String baseURL = "http:/www.yahoo.com";
      String actualTitle="";
      String expectedTitle="Yahoo";
 
      wd.get(baseURL);
      actualTitle = wd.getTitle();

        if( actualTitle.contentEquals(expectedTitle)) {
         System.out.println("Matched -" + actualTitle);
       }  else{
        System.out.println("Not Matched - "+actualTitle);
        }
   }
 }

Friday 4 October 2013

Count the Running instance of a process




howmanyareRunning("notepad.exe")

Function howmanyareRunning(iprocessName)


Dim objWMIService, objProcess, colProcess, strComputer, processName, instances

strComputer = "."
instances = 0
processName = iprocessName '"firefox.exe"

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process")

For Each objProcess in colProcess
If objProcess.Name = processName Then instances = instances + 1
Next

If processName = "wscript.exe" Then
    If instances = 1 Then
    WScript.Echo "There is no other VBScript running except this one!"
    Else
    WScript.Echo "There are currently " & "(" & instances _
       & ") " & "VBScript" & " Instances running!"
    End If
Else
    WScript.Echo "There are currently " & "(" & instances & ") " & _
            """" & processName & """" & " Instances running!"
End If

End Function


OUTPUT
=======


Sunday 8 September 2013

Get Files list from a folder

OUTPUT


 
Function GetFileNamesfromFolder(sFolder)

    Dim filenames
    Dim fso, folder,files
    Dim firstfile
    On Error Resume Next

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set folder = fso.GetFolder(sFolder)
    Set files = folder.Files
    
     firstfile =true 
      For each folderIdx In files
   
       if firstfile then
        filenames =folderIdx.Name
        firstfile =false
       else
           filenames = filenames & "," & folderIdx.Name
       End If
        'msgbox filenames 
      Next
    GetFileNamesfromFolder=filenames

End Function

Example: 


AllFiles =GetFileNamesfromFolder("c:\") 
  msgbox AllFiles
 msgbox Replace(AllFiles,",",vbcrlf)


OUTPUT
=======
All file names in comma seperated format

Further:
you can use split to spilt all names into array

AllFiles =GetFileNamesfromFolder("c:\") ArrayOfFiles = Split(AllFiles,",")