Wednesday, February 1, 2012

Creation of Firefox profile for Selenium


 We use Selenium with firefox profile to test our JS functions in selenium console of firefox profile.

 Before we can create profile, take a backup of  firefox  so that the bookmarks and default settings of firefox won't vanish.

 Steps to take backup:
  1. For Windows 7 users, go to C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\ and copy the default folder and paste it some local directory.
  2.  Windows XP users,C:\Users\username\Application Data\Mozilla\Firefox\Profiles\ and copy the default folder and paste it some local directory.

Steps to create profile.
  1.     Make sure all your firefox instance are closed
  2.     Click Start>Run(windows xp) or click start ,type in search (windows 7)
  3.     Type “firefox.exe -ProfileManager -no-remote”    or C:\Program Files (x86)\Mozilla Firefox\firefox.exe -ProfileManager -no-remote
  4.     Select “Create Profile” 
  5.    Click “Next”
  6.     Enter new profile name (i.e. selenium)   Optional:  Select a directory folder to store your new profile
  7.     Click “Finish”
  8.   Don't Select “Don’t ask at startup”
  9.    Click “Start Firefox” and configure settings ,  From “View\Toolbars” tab, uncheck “Bookmarks Toolbar”
        Right click from toolbar and click “Customize”
        Remove “Google search” by dragging it to the “Customize Toolbar” window
        From the “Customize Toolbar” window, click “Use Small Icons” check box then hit “Done”
        Click “Tools\Options” then set the following:
        a. “Main” tab
        - set Home Page to “about:blank”
        - uncheck “Show the Downloads..” option
        b. “Tabs” tab
        - Select “a new window” for new pages
        - Uncheck all warning options
        c. “Content” tab
        - uncheck “Block pop-up” windows option
        d. “Privacy” tab
        - uncheck all “History” options
        e. “Security” tab
        - uncheck all “Security” options
        - click “Settings” and uncheck all warning options
        f. “Advanced” tab
        - Uncheck “autoscrolling” option from “General” tab
        - uncheck “warn me …” and “Ssearch Engines”option from “Update” tab
        From “Tools\Add-ons” install the following:
        - Firebug: allows you to edit, debug, and monitor CSS, HTML, and JavaScript on your application under test
        - Selenium IDE: allows you to record, edit, and debug Selenium tests
        - From the address bar type “about:config” and add the following by right-click anywhere on the page and selecting “new”
        - extensions.update.notifyUser (type=boolean; value=false)
        - extensions.newAddons (type=boolean; value=false) 
  10.  Now , your profile is set. To restart the default firefox , close the firefox profile, and Click Start>Run(windows xp) or click start ,type in search (windows 7) . Type “firefox.exe -ProfileManager -no-remote”    or C:\Program Files (x86)\Mozilla Firefox\firefox.exe -ProfileManager -no-remote . Select default and then click on “Don’t ask at startup”
  11. Now you can see your default  firefox with all your bookmarks.
If, by any chance, the bookmarks are gone,then follow,

Steps to restore the default profile

  1.  Copy the default folder from the local directory  
  2. Paste it in C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\default.which will replace the default profile . 
Steps to launch Selenium Server with the created profile
  1.   Go to the folder containingselenium server jar 
  2. Now start selenium server with firefox profile by giving the right location of profile     
    java -jar selenium-server.jar -firefoxProfileTemplate “<Selenium Profile Directory>”

     ex :  java -jar selenium-server-standalone.jar  -firefoxProfileTemplate "C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\jvme65u6.selenium"
  3.  To launch selenium test using profile through ant,
 <target name="startServer">
        <echo>Start Selenium Server...</echo>
        <java jar="${lib.dir}/selenium-server.jar" fork="true" spawn="true">
            <arg line="-port ${selenium.port} -trustAllSSLcertificates"/>
            <arg line="-log log.txt"/>   
            <arg value="-userExtensions"/>
                <arg value="${lib.dir}/user-extensions.js"/>
        </java>
    </target>

Any problems??? feel free to comment...

Tuesday, January 24, 2012

Integrating Selenium with jenkins/Hudson


 
Integrating Selenium with Jenkins
Jenkins is a build server designed for Java. Jenkins is responsible for checking if your application needs building, building it, triggering any testing that you have defined and, finally, reporting on the state of the build. Jenkins is easily available and can display JUnit reports in graphical format with drilldown capabilities.
Download Jenkins
Download Jenkins war from Jenkins website. Save it in one of our drive. For ex: D:\Jenkins.war
Start Jenkins:
Open command prompt and navigate to the folder containing jenkins.war and give java –jar jenkins.war
You can see
[Winstone 2012/01/25 08:46:47] - Beginning extraction from war file
Jenkins home directory: C:\Users\username\.jenkins found at: $user.home/.jenkins
[Winstone 2012/01/25 08:46:52] - HTTP Listener started: port=8080
[Winstone 2012/01/25 08:46:52] - AJP13 Listener started: port=8009
[Winstone 2012/01/25 08:46:52] - Winstone Servlet Engine v0.9.10 running: contro
lPort=disabled
Jan 25, 2012 8:46:52 AM jenkins.model.Jenkins$6 onAttained
INFO: Started initialization
Jan 25, 2012 8:46:53 AM jenkins.model.Jenkins$6 onAttained
INFO: Listed all plugins
Jan 25, 2012 8:47:25 AM jenkins.model.Jenkins$6 onAttained
INFO: Prepared all plugins
Jan 25, 2012 8:47:26 AM jenkins.model.Jenkins$6 onAttained
INFO: Started all plugins
Jan 25, 2012 8:47:26 AM jenkins.model.Jenkins$6 onAttained
INFO: Augmented all extensions
Jan 25, 2012 8:47:34 AM jenkins.model.Jenkins$6 onAttained
INFO: Loaded all jobs
Jan 25, 2012 8:47:34 AM jenkins.model.Jenkins$6 onAttained
INFO: Completed initialization
Jan 25, 2012 8:47:34 AM hudson.TcpSlaveAgentListener <init>
INFO: JNLP slave agent listener started on TCP port 64776

Jenkins  home directory will be created in C:\Users\username\.jenkins
Check to see, if Jenkins is running
Jenkins will be launched on port 8080, hence, open the URL http://localhost:8080/, to see the dashboard of Jenkins
You can see,




Create new project
1.       Enter job name as SelAutomationCI
2.       Select “build a free style software project”
3.       Click OK
Enter the details of repository
4.       In the Source code management section, select the repository type and enter the repository location.




Integrating Selenium with Jenkins:
1.       In the Build Section, there are 4 options through which you can integrate your projects to selenium
2.       In my project, I use ant as building tool which can run suite. (Check the blog, http://seleniumready.blogspot.in/2012/10/sample-ant-script-for-running-targets.html )
3.       In build Option->Add build step, we need to select invoke ant CItarget



 
1.       In the targets section, write the target which runs the suite. In our case: run
2.       Click on Advanced.
3.       Enter the  build file location in Build File field






1.       In Post Build action section, Click on  Publish junit test results report and enter the location to store the results xml’s, as shown below.
2.       Click on Email notification, to get the result of unstable builds, or build failure.
3.       Click on Save.
4.       To run the build, Click on build now.





1.       the build History section, You can see the build number with the time stamp.






.       Clicking on the build link, will show the console output.
.       You can see selenium test running on Hudson.

Monday, September 19, 2011

Challenges faced in ext js

Hi,
I.m working on ext js application, whose speciality is,all the elements of the page are dynamic.This indicates that its not automation friendly.
I'll post some of the locators which i used to locate elements.


Selecting from drop down
There is a select list, which contains a text box and down arrow image button, clicking on button image, opens a drop down which contains element with dynamic id's.
Dynamic elements are : drop down elements (div's) , and image button.
 Clue is, input box has an id.

This can be located as.

//input[@id='abc']/following-sibling::img

this clicks on image .now we need to select the dropdown list element , which also has dynamic id.
So,i used text function as,

//div[text()='CPA']

which clicks on cpa in the dropdown list.

Locating elements with same name ,based on their position using css

I hadto locate 3 elements with same id.(Accounts). All had same name, no other unique identifier.

So,i could locate them using,

css=div#salestabs  td[class*=Accounts ]
css=div#salestabs  td[class*=Accounts ]  div:nth(1)
css=div#salestabs  td[class*=Accounts ]  div:nth(2)


Css will locate element based on their parent element.The above css looks so simple, but the dom is so complex.

div has class name x-combo-list-inner,under that


<div class="x-combo-list-item">YYYY-Month</div>
<div class="x-combo-list-item  x-combo-selected">YYYY-MM</div>
<div class="x-combo-list-item  x-combo-selected">MM-YYYY</div>

and then div closes(</div>)

Another div having same class name and same list of combo items as mentioned above. is located below the above div.

 <div class='x-combo-list-inne'>
<div class="x-combo-list-item">YYYY-Month</div>
<div class="x-combo-list-item  x-combo-selected">YYYY-MM</div>
<div class="x-combo-list-item  x-combo-selected">MM-YYYY</div>
 </div>

this can be located as

css=div[class*='x-combo-list-inner'] div:nth(2)---locates  3rd element of 1st div.

css=div[class*='x-combo-list-inner'] div:nth(5)--locates 3rd element of 2nd div.


Post will be continued as n wen i find more challenges.....

















Friday, February 4, 2011

Suite creation in Junit4

Suite creation in Junit4

First Test


package com;


import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class FirstOne {
    
    private static SeleniumServer seleniumServer;
    private static Selenium selenium = new DefaultSelenium( "localhost",4444, "*chrome","http://www.google.com");
    
    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
        seleniumServer = new SeleniumServer();
        seleniumServer.start();
        selenium.start();
    }

    @AfterClass
    public static void tearDownAfterClass() throws Exception {
          selenium.stop();
          seleniumServer.stop();
    }

    @Test
    public void Testing() throws Exception{
        selenium.open("/");
        selenium.waitForPageToLoad("6000");
        selenium.type("q", "search");
        selenium.click("btnG");
 }

}


Second Test



package com;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class SecondOne {

 private static SeleniumServer seleniumServer;
 private static Selenium selenium = new DefaultSelenium( "localhost",4444, "*chrome","http://www.google.com");
 
 @BeforeClass
 public static void setUpBeforeClass() throws Exception {
  seleniumServer = new SeleniumServer();
        seleniumServer.start();
        selenium.start();
 }

 @AfterClass
 public static void tearDownAfterClass() throws Exception {
    selenium.stop();
       seleniumServer.stop();
 }

 @Test
 public void Testing() throws Exception{
  selenium.open("/");
  selenium.waitForPageToLoad("6000");
  selenium.type("q", "selenium");
  selenium.click("btnG");
 }
}

Suite Class 


package com;



import org.junit.runner.RunWith;

import org.junit.runners.Suite;



@RunWith(Suite.class)

@Suite.SuiteClasses({FirstOne.class, SecondOne.class})

public class TestSuite {

//nothing

}

Saturday, January 29, 2011

Program to login into a webpage using selenium Webdriver

Login into a page with username text box having id as loginid,password id as password and button id as button.

import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class Login {      public static void main(String[] args) throws Exception {                WebDriver driver = new FirefoxDriver();             driver.get("http://");             WebElement id = driver.findElement(By.id("loginID"));             WebElement pass = driver.findElement(By.id("password"));             WebElement button = driver.findElement(By.id("Button"));                         id.sendKeys("Cheese");             pass.sendKeys("password");             button.click();                              }             }