Tuesday, May 15, 2012

Pass values from command line to java program/ant file

In order to pass values from command line to java program we can use "sysproperty"
Sample usage

   <target name="run_tests" depends="compile">
       <echo message="running tests" />
       <testng classpathref="classpath" haltOnfailure="true">
               <xmlfileset file="${xml}" />
            <sysproperty key="env" value="${env}"/>
            <sysproperty key="driver" value="${driver}"/>
       </testng>
    </target>

   @Test
    @Parameters ({"env","driver"})
    public void setUp(String env, String driver) {
           System.out.println(env+" success "+driver);
  }

 Execution : ant run_tests -Denv=test -Ddriver=ff


Wednesday, May 2, 2012

Configuration to make maven plugin work in eclipse

1. Update eclipse.ini file with the option
-vm
C:/Program Files/Java/jdk1.6.0_10/bin/javaw.exe

2.Configure eclipse to use jre in jdk definition from(Preference -> java -> installed jre)


Wednesday, April 11, 2012

xpath locators

xpath=(//a[@class='addthis_button'])[last()-2]
xpath=(//a[@class='addthis_button'])[last()]
xpath=(//a[@class='addthis_button'])[position()=2]
//a[contains(@class, concat("addthis_button_compact", " at300m"))]

More reference : http://shanmugavelc.blogspot.com/2011/11/selenium-css-locators.html

Tuesday, February 14, 2012

Flash with selenium

Selenium/Webdriver cannot click on the flash application. Only thing it can do is invoke the functions defined in as3 scripts using javascript.  For functions to be accessible to javascript it should be added to ExternalInterface. ExternalInterface is used to call javascript function from/to flash.

ExternalInterface.addCallback("setText", setText) makes setText method invokable from javascript

        WebDriver driver = new FirefoxDriver();
        WebDriverBackedSelenium selenium = new WebDriverBackedSelenium(driver, "");
        driver.get("http://sitestress.webmetrics.com/test/flashtest.html");
        selenium.getEval("var movie = window.document.extinterfaceexample; movie.jsToFlash('water in water');");

        driver.get("http://bowser.effectgames.com/~jhuckaby/zeroclipboard/");
//        selenium.type("fe_text", "bla bla bla");
        selenium.getEval("var playerid = window.document.ZeroClipboardMovie_1; playerid.setText('james bond')");

For above example  'ZeroClipboardMovie_1' is the object id of the flash movie. It is used to create a variable for accessing the as3 functions.

For more details checkout Flash Selenium

Tuesday, January 17, 2012

Auto it basics for entering text

Press escape key : Send("{ESCAPE}")
Press enter key : Send("{ENTER}")
Press tab key : Send("{TAB}")

Enter some content and press tab key : Send("water{TAB}")
Enter some content and press enter key : Send("water{ENTER}")

Autoit for File upload

Firefox

WinWaitActive("File Upload")
if WinExists("File Upload") Then
ControlSetText("File Upload", "", "Edit1", "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg")
Sleep(1000)
ControlClick("File Upload", "", "Button2")
EndIf

IE

WinWaitActive("Choose file")
if WinExists("Choose file") Then
ControlSetText("Choose file", "", "Edit1", "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg")
Sleep(1000)
ControlClick("Choose file" ,"", "Button2")
EndIf

Chrome

WinWaitActive("Open")
if WinExists("Open") Then
ControlSetText("Open", "", "Edit1", "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg")
Sleep(2000)
ControlClick("Open", "", "Button2")
EndIf

For more reference follow these links. These guys have given nice example
http://qtp-help.blogspot.com/2009/07/selenium-handle-dialogs.html
http://automationtricks.blogspot.com/2010/09/how-to-upload-file-in-selenium-with.html
http://iautomateit.wordpress.com/2011/07/15/working-around-file-upload-dialog-issues-with-selenium-2/
http://bharath-marrivada.blogspot.com/2011/02/selenium-autoitv3-file-upload-download.html

Thursday, January 12, 2012

FirefoxDriver with custom profile

Use profile manager to create profiles. In Windows machine profiles will be stored in the path

C:\Documents and Settings\user\Application Data\Mozilla\Firefox\Profiles\

FirefoxProfile profile = new ProfilesIni().getProfile("profileName");
FirefoxDriver driver = new FirefoxDriver(profile);

Once firefox window opens check that addon's, bookmark etc are appearing in the newly opened firefox window.