Monday, 22 June 2015

IP Address Program (Core JAVA)



import java.net.InetAddress;

class IPAddress
{
   public static void main(String args[]) throws Exception
   {
      System.out.println(InetAddress.getLocalHost());
   }
}

Wednesday, 17 June 2015

Current Time Program (Core JAVA)

This code can also be used in selenium to get Test Case Start Time and Test Case End Time. We can develop function as developed in below mentioned code i.e. tNow(). This function can be used before the start of each test and at the end of each test (e.g. start of for loop and end of for loop).
Find below the code for Current Time:



import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class timeFunction {

 public static void main(String[] args) {
  System.out.println(tNow());
  
 }
    
   //Generate current start time and end time 
   public static String tNow(){
   //DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
   DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
   Calendar cal = Calendar.getInstance();
   String currTime=dateFormat.format(cal.getTime());
   return currTime;
   }
 
 }

Monday, 15 June 2015

Jenkins Tutorial (GitHub MAVEN JENKIN integration)

For MAVEN PROJECT: "mavenJenkinPrac"

  • Click on New Item:



  • Specify "Item name" i.e. "gitMavenJenkinPrac",select "Maven Project" and click on "OK"



  • Under "Source code management", select Git.
  • Specify Repository URL "https://github.com/XXXXXXXX/xxxxxxTesting.git"



  • Under Build, Specify Root POM i.e. "com.project/pom.xml"
  • Also Specify "Goals and options" i.e. "clean compile test"
  • Click on Apply and Save



  • Click on "Build Now"















Jenkins Tutorial (Basic Configuration Settings)




  • Then click on Configure System



  • Under JDK Installation specify:



  • Under Git, specify:



  • Under Ant, specify:



  • Under Maven, Speficy




Click on Apply and Save

Jenkins Tutorial (MAVEN JENKINS Integration)

For MAVEN PROJECT: "mavenJenkinPrac"

  • Click on New Item:


  • Specify "Item name" i.e. "mavenJenkinPrac",select "Maven Project" and click on "OK"




  • Under build, "Root POM " specify the path till pom.xml
  • specify goals and options, i.e. Clean compile test package
  • Click on Apply and Save




  • Click on "Build Now"












Jenkins Tutorial (ANT JENKIN Integration)

For ANT PROJECT: "antJenkinPrac"

  • Click on New Item:


  • Specify "Item name" i.e. "antJenkinPrac",select "Freestyle project" and click on "OK"






  • Under build select "Invoke ANT".
  • Select ANT version which you specified under jenkin configuration settings:
  • Specify Targest i.e. Clean compile run










  • Under "Build File" give full path till "build.xml"
  • Click on Apply and Save




  • Click on "Build Now"







GitHub Tutorial (Creating and Updating repository)


  • Goto gihub.com, create account
  • Goto git-scm.com
  • Click on Download for windows
  • install
  • Add environment variable


  • Clik on "+" sign
  • Give name to repository: gurdialProjects
  • Specify the local path:C:\Users\Gurdial\Documents\GitHub\gurdialProjects or we can modify according to your requirement
  • Click on "Create Repository"


  • Now goto local path where you have created repository
  • There will be 2 text documents available









  • Add file "Gurdial-Documentation" to local location




  • Right Click on file and then click on Git Gui






  • this window will get open




  • Click on Stage Changed





  • Click on "YES"
  • Add Commit Message
  • Click on Commit then click on Push
  • this window will appear




  • Now goto github
  • File has been added




  • Click on Publish Repository , Add Description





  • Click on "Publish"






  • Now www.github.com and and under repositories you will see "gurdialProjects"







Selenium WebDriver Gmail Automation (Includes Compose, verify whether email has been sent or not and get number of the unread email in inbox folder)

Selenium WebDriver Gmail Automation (Includes Compose, verify whether email has been sent or not and get number of the unread email in inbox folder)



package zellaxSolutions.automationTesting;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class newclass {

 public static void main(String[] args) throws InterruptedException {
  String subject="Write Subject Of Testing Email !!";
  WebDriver driver;
  driver=new FirefoxDriver();
  driver.navigate().to("https://www.google.co.in/?gfe_rd=cr&ei=Gmd-VdWTD-XH8AeqsbH4Bg&gws_rd=ssl");
  driver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
  driver.findElement(By.className("gb_la")).click();
  // Login to Gmail
  driver.findElement(By.id("Email")).sendKeys("Enter Email Address (FROM)");
  driver.findElement(By.id("next")).click();
  driver.findElement(By.id("Passwd")).sendKeys("Enter Password");
  //Click on SignIn
  driver.findElement(By.id("signIn")).click();
  Thread.sleep(3000);
  //Compose Email
  driver.findElement(By.xpath("//div[@class='z0']/div")).click();
  Thread.sleep(3000);
  driver.findElement(By.className("vO")).sendKeys("Enter Email Address (TO)");
  Thread.sleep(3000);
  driver.findElement(By.className("aoT")).sendKeys(subject);
  Thread.sleep(3000);
  driver.findElement(By.xpath("//td[@class='Ap']/div[2]/div[@class='Am Al editable LW-avf']")).sendKeys("Write Text For an email.!!! :)");
  Thread.sleep(3000);
  driver.findElement(By.xpath("//div/div[text()='Send']")).click();
  Thread.sleep(3000);
  driver.findElement(By.xpath("//div/div/span/a[text()='Sent Mail']")).click();
    
  // To verify whether an email has been sent or not
  if(driver.findElements(By.xpath("//tr/td[6]/div/div/div[2]/span/b[text()='"+subject+"']"))!=null){
   System.out.println("Email Sent Successfully... :)");
  }
  else{
   System.out.println("Email Sending Failed... :(");
  }
  
  // To get the number of the unread emails in inbox folder
  driver.findElement(By.xpath("//div[@class='TN GLujEb']/div/span[@class='nU n1']/a")).click();
  String inboxString=driver.findElement(By.xpath("//div[@class='aim ain']/div/div/div/span/a")).getText();
  String inboxElements = inboxString.substring(inboxString.indexOf("(") + 1, inboxString.indexOf(")"));
  System.out.print(inboxElements);
  driver.close();  
 }

}

Friday, 5 June 2015

Running different suites using TestNG

Running different suites:


For this we require 3 files:


1. testng.xml (for 1st suite)
2. testng1.xml (for 2nd suite)
3. suite.xml (for running testng.xml and testng1.xml)

Please find below code for testng.xml



<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >


<suite name="Suite1" parallel="tests">


  <test name="exampletest1.0_Mozila">

  <parameter name="browser" value="MFF"/>

    <classes>

       <class name="FirstMavenProject.zellaxSolutionsProject01.firstTest" />

    </classes>

  </test>

 

  <test name="exampletest2.0_Chrome" >

 

          <parameter name="browser" value="CH"/>

    <classes>

       <class name="FirstMavenProject.zellaxSolutionsProject01.firstTest" />

    </classes>

  </test>

    </suite>

Please find below code for testng1.xml



<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >


<suite name="Suite2">


  <test name="exampletest1.0">

    <classes>

       <class name="FirstMavenProject.zellaxSolutionsProject01.firstTest" />

    </classes>

  </test>

  

    <test name="exampletest2.0">

    <classes>

       <class name="FirstMavenProject.zellaxSolutionsProject01.secondTest" />

    </classes>

  </test>

    </suite>

Please find below code for suite.xml


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >


<suite name="suite of suites">

    <suite-files>

        <suite-file path="testng.xml" />

        <suite-file path="testng1.xml" />

    </suite-files>

</suite>

Parallel Execution of Tests in Different Browser using TestNG

For parallel excution of tests in different browsers:

To accomplish this task, We need two files:

1. Leads.java
2. testng.xml

Please find below the code for Leads.java:



import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.ie.InternetExplorerDriver;

import org.testng.annotations.AfterClass;

import org.testng.annotations.BeforeClass;

import org.testng.annotations.Parameters;

import org.testng.annotations.Test;



public class Leads {

    public WebDriver driver;

    @Parameters("browser") 

      // Passing Browser parameter from TestNG xml

      @BeforeClass

      public void beforeTest(String browser) {

      // If the browser is Firefox, then do this

      if(browser.equalsIgnoreCase("firefox")) {

      driver = new FirefoxDriver();

      // If browser is IE, then do this 

      }else if (browser.equalsIgnoreCase("ie")) {

      // Here I am setting up the path for my IEDriver

      System.setProperty("webdriver.ie.driver", "C:\\chrome\\IEDriverServer.exe");

      driver = new InternetExplorerDriver();

      }else if (browser.equalsIgnoreCase("chrome")) {

     

      // Here I am setting up the path for my ChromeDriver

      System.setProperty("webdriver.chrome.driver", "C:\\chrome\\chromedriver.exe");

      driver = new ChromeDriver();

      }

      // Doesn't the browser type, lauch the Website

      driver.get("http://localhost:100/");

      }

    @Test

    public void leads() throws InterruptedException

    {

        driver.findElement(By.name("user_name")).sendKeys("admin1");

        driver.findElement(By.name("user_password")).sendKeys("admin1");

        driver.findElement(By.name("Login")).click();

        Thread.sleep(3000);

        driver.findElement(By.name("user_name")).clear();

        driver.findElement(By.name("user_name")).sendKeys("admin");

        driver.findElement(By.name("user_password")).clear();

        driver.findElement(By.name("user_password")).sendKeys("admin");

        driver.findElement(By.name("Login")).click();

        Thread.sleep(3000);

        driver.findElement(By.linkText("New Lead")).click();

        Thread.sleep(3000);

        driver.findElement(By.name("lastname")).sendKeys("ATH");

        driver.findElement(By.name("company")).sendKeys("ATH");

        driver.findElement(By.name("button")).click();

        Thread.sleep(3000);

       

    }

    @AfterClass

    public void afterClass()

    {

        driver.close();

        driver.quit();

    }


}

Please find below the code for testng.xml:



<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="zellaxSolutions" parallel="tests">


<test name="Leads with Firefox" >

<parameter name="browser" value="firefox" />

    <classes>

        <class name="Leads" ></class>         

    </classes>   

</test>



<test name="Leads with IE">

<parameter name="browser" value="ie" />

    <classes>

        <class name="Leads" ></class> 

    </classes>

</test>


<!--  <test name="Leads with Chrome">

<parameter name="browser" value="chrome" />

    <classes>

        <class name="Leads" ></class> 

    </classes>

</test>-->

</suite>