Wednesday, 29 April 2015

'Visual Studio Community 2013' Installation.

Visual Studio Community is a free for developing the applications.
Visual Studio Community can be used in a classroom learning environment, academic research or for contributing to open source projects.

For more information on 'Visual Studio Community 2013' visit the below links.
https://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx
https://www.visualstudio.com/products/visual-studio-community-vs

System Requirements:

1. Download the 'Visual Studio Community 2013' from https://www.visualstudio.com/en-us/news/vs2013-community-vs.aspx
Click the link 'Download Visual Studio Community 2013'.

2. Click on 'Save File' button.

3. 'vs_community.exe' is downloaded in to the download folder of the system.

4. Click on 'vs_community.exe' to install 'Visual Studio Community 2013' edition.

5. Accept the 'License Terms' and click on 'Next' button.

 6. Click on 'INSTALL' button.

Now just sit down and relax while the installation is in process.

7. Click 'LAUNCH' to launch 'Visual Studio Community 2013' for the first time.



8. Choose color theme and click 'Start Visual Studio' button.


9. 'Visual Studio' IDE is launched.

Monday, 27 April 2015

Java Webdriver - Click using javascript

Most of the times we will be using 'WebElement' API methods to perform the 'click' operations in the automation scripts developed using webdriver.
'Click' operation can also be performed by using javascript(i.e. using 'JavascriptExecutor').
Javascript click can be used as the workaround in the automation script when ever webdriver 'WebElement' api methods are failing to perform the click operation.

Webelement holding the ObjectLocator path.
WebElement srchBttn = driver.findElement(By.name("btnG"));

Type cast the driver instance to 'JavascriptExecutor'.
JavascriptExecutor js = (JavascriptExecutor) driver;

Performs the click operation using javascript.
js.executeScript("arguments[0].click();", srchBttn);

Below code demonstrates click operation using 'Javascript'.
Sample code:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class JSClick {
    static WebDriver driver = null;
  
    public static void main(String[] args) throws InterruptedException {
        driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
        driver.get("http://www.google.com/");  
        Thread.sleep(2000);
              
        //Enter Search Text.
        WebElement txtFieldElement = driver.findElement(By.id("lst-ib"));
        txtFieldElement.sendKeys("webdriver");
        Thread.sleep(1000);
      
        //Click on Search button.
        //Click --- starts ---
            WebElement srchBttn = driver.findElement(By.name("btnG"));
            JavascriptExecutor js = (JavascriptExecutor) driver;
            js.executeScript("arguments[0].click();", srchBttn);

        //Click --- ends ---
          
        Thread.sleep(3000);                        
        driver.close();
        driver.quit();
    }  
  
}

Below code demonstrates click operation using 'WebElement' API methods of webdriver.
Sample code:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class JSClick {
    static WebDriver driver = null;
  
    public static void main(String[] args) throws InterruptedException {
        driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
        driver.get("http://www.google.com/");  
        Thread.sleep(2000);
              
        //Enter Search Text.
        WebElement txtFieldElement = driver.findElement(By.id("lst-ib"));
        txtFieldElement.sendKeys("webdriver");
        Thread.sleep(1000);
      
        //Click on Search button.
        //Click --- starts ---
            WebElement srchBttn = driver.findElement(By.name("btnG"));
            srchBttn.click();

        //Click --- ends ---
          
        Thread.sleep(3000);                        
        driver.close();
        driver.quit();
    }     
}

Environment:
Above script is executed on
OS: Windows 7
Brower: Firefox 37
Selenium Webdriver : 2.45.0
Java : 7

Sunday, 26 April 2015

Java Webdriver - Mouseover using javascript

Most of the times we will be using 'Actions' class API methods to perform the mouseover events in the automation scripts developed using webdriver.
Mouseover operation can also be performed by using javascript(i.e. using 'JavascriptExecutor').
Javascript mouseover can be used as the workaround in the automation script when ever webdriver 'Action' class api methods are failing to perform the mouseover.

Webelement holding the ObjectLocator path.
WebElement element = driver.findElement(By.xpath("//a"));

Type cast the driver instance to 'JavascriptExecutor'.
JavascriptExecutor js = (JavascriptExecutor) driver;

Performs the mouseover operation using javascript.
js.executeScript("arguments[0].onmouseover()", element);

Below code demonstrates mouseover using 'Javascript'.
Sample code:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class MouseOver {
    static WebDriver driver = null;
   
    public static void main(String[] args) throws InterruptedException {
       
        driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
       
        driver.get("http://net-comber.com/mouseovr.html");       
        Thread.sleep(2000);
               
        //MouseOver Logic --- starts ---
            WebElement element = driver.findElement(By.xpath("//a"));
            JavascriptExecutor js = (JavascriptExecutor) driver;
            js.executeScript("arguments[0].onmouseover()", element);

        //MouseOver Logic --- ends ---
           
        Thread.sleep(3000);                         
        driver.close();
        driver.quit();
    }   
}

Below code demonstrates mouseover using 'Actions' class API methods of webdriver.

Sample code:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class MouseOver {
    static WebDriver driver = null;
   
    public static void main(String[] args) throws InterruptedException {
       
        driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
       
        driver.get("http://net-comber.com/mouseovr.html");       
        Thread.sleep(2000);
               
        //MouseOver Logic --- starts ---
            WebElement element = driver.findElement(By.xpath("//a"));
            Actions action = new Actions (driver);
            action.moveToElement(element).build ().perform ();
        //MouseOver Logic --- ends ---
           
        Thread.sleep(3000);                         
        driver.close();
        driver.quit();
    }   
}

if "action.moveToElement(element).build ().perform ();" is not working then add below code
"action.moveToElement(element,0,0).build ().perform ();".

Environment:
Above script is executed on
OS: Windows 7
Brower: Firefox 37
Selenium Webdriver : 2.45.0
Java : 7

Thursday, 9 April 2015

C# - Integrating Nant with Jenkins Continuous Integration tool.

Jenkins is open source tool to perform continuous integration.
For starting the Jenkins server, java should be installed and configured. Since jenkins server runs on Java.

Prerequisite:
1. Java is already installed.
    click url https://java.com/en/download/ for java installation.

2. Java build path is already set.
   click url https://docs.oracle.com/javase/tutorial/essential/environment/paths.html for setting the build path

3. Nant is already configured.
    click url http://automation-home.blogspot.com/2015/04/csharp-nant-configuration-and-executing-nant-echo-message.html Nant configuration.

Below steps demonstrates integrating Nant with Jenkins Continuous Integration tool.  
 
1. Download Jenkins war from url: https://jenkins-ci.org/

2. Copy the 'jenkins.war' to some folder ex: 'C:\Jenkins'

3. Open the command prompt and navigate to the folder where Jenkins war is present.

4. Run the command 'java -jar jenkins.war' in command prompt.


5. Open the browser and type http://localhost:8080/


6. Click 'Manage Jenkins' link.

7. Click 'Manage Plugins' link.

8. Click 'Available' tab.

9. 'Available' tab is opened.

    Select 'NAnt' plugin and click button 'Download now and install after restart'.


10. Restart the System.

     Start jenkins(i.e. 'java -jar jenkins.war' ) after restarting the system.

11. Go to ‘Manage Jenkins’ -> ‘Manage Plugins’ -> ‘Installed‘ tab.

12. Now go to the Jenkins Dashboard screen.


13. Create New Job.


14. Enter item name ex: 'SampleTestSolution', Select 'Freestyle project' and click on 'OK' button.
 



15. Specify Nant Build file and target details and click on 'Save' button.


"HelloWorld.build" file:
------------------------
<?xml version="1.0" encoding="utf-8" ?>
<project name="HelloWorld" default="go">
<property name="message" value="Hello World from praveen.!"/>
   <target name="go">
       <echo message="${message}"/>
  </target>
</project>

16. Navigate to Home page and run the build.

17. See the results in Console.  


Note: The above approach is demonstrated by executing the simple build file(i.e. with echo message), with out any scheduling configuration in Jenkins.

Wednesday, 8 April 2015

C# - Nant configuration and executing Nant 'echo' message.

Nant is a free build tool for .NET projects(similar to 'Ant' is a build tool for Java), using Nant developer can build(i.e. compile) the project without using visual studio(i.e. code can be compiled outside of Visual Studio).
Nant has support for compiling and executing C#, VB.NET, Nunit and also support for generating NDoc(i.e. creating documentation).

Below are the steps for configuring the Nant:

1. Download Nant latest version from 'http://nant.sourceforge.net/'

Click the "<version>-bin.zip" to download the zip folder.


2. Copy the Nant zip file to some other folder and unzip the Nant binaries.

3. Open the command prompt and type command 'nant
   Note: In command prompt, user should not be in the folder path where the nant zip is extracted.
If the message 'nant' is not recognized...... is displayed, that means Nant is not yet configured in the system.

4. Set the PATH for Nant

Copy the nant bin path in the System Variable
 Ex: 'C:\installs\nant-0.92-bin\nant-0.92\bin'

5. Open the new command prompt again(close the command prompt if already opened) and type 'nant' command.
   Note: In command prompt user should not be in the folder path where the nant zip is extracted.

Nant is configured now.

6. Now lets start by writing Nant script to print echo message.

Sample HelloWorld.build file:
<?xml version="1.0" encoding="utf-8" ?>
<project name="HelloWorld" default="go">

<property name="message" value="Hello World from praveen.!"/>
<target name="go">
<echo message="${message}"/>
</target>

</project>

7. Save the file as 'HelloWorld.build'.

8. open the command prompt and navigate to the path where build script is present.




9. Type command nant in command prompt.
Note: While executing nant command make sure there is only one build file in the folder(i.e there is another approach to execute build file, if there are multiple build files in the folder).