Thursday, June 19, 2014

How to execute single testcase in two different broswer parallelly in single machine using TestNG.

How to execute single testcase in two different broswer parallelly in single machine using TestNG.

How to execute single testcase in two different browsers parallel in single machine using TestNG.

Sample Test Case

package hello;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class ParallelExecution {
        @Test
        @Parameters("browserType")  // use @Parameters to pass the input through xml
        public void dummyTest(String browserType){
            WebDriver driver;
            if(browserType.equals("FF")){
                driver= new FirefoxDriver();
                driver.quit();
            }else if(browserType.equals("IE")){
                System.setProperty("webdriver.ie.driver", "./Drivers/IEDriverServer.exe");
                driver = new InternetExplorerDriver();
                driver.quit();
            }
     }
}


testng.xml

<suite name="Suite" parallel="tests" thread-count="2"> //here parallel="tests" means run both the test in parallel and thread-count="2" means run two test cases parallel. 
  <test name="Test1">
  <parameter name="browserType" value="FF" />  //to pass the input to the java class
   <classes>
          <class name="hello.ParallelExecution"/>   //here hello is package name and ParallelExecution is class name
   </classes>
  </test>
  <test name="Test2">
  <parameter name="browserType" value="IE" />
   <classes>
          <class name="hello.ParallelExecution"/> //here hello is package name and ParallelExecution is class name
   </classes>
  </test>
</suite> 

Architecture of Selenium

Architecture of Selenium


Wednesday, June 18, 2014

Using not() in XPath. (ex- you want to write the xpath for the element whose class is not equal to 'abc').

Using not() in XPath. (ex- you want to write the xpath for the element whose class is not equal to 'abc').

Using not() in XPath. (ex- you want to write the xpath for the element whose class is not equal to 'abc').

Requirement-
In the below html code, we have to write the xpath for the span (high lighted in green color) tags present inside td tags where td class="closeTrigger" and tr class is not "week-selected".

HTML code-

<tr>
<td class="weekend closeTrigger">
<span>5</span></td>
<td class="closeTrigger">
<span>6</span></td>
<td class="closeTrigger">
<span>7</span></td>
<td class="closeTrigger">
<span>8</span></td>
<td class="closeTrigger">
<span>9</span></td>
<td class="closeTrigger">
<span>10</span></td>
<td class="weekend closeTrigger">
</tr>
<tr class="week-selected">
<td class="weekend closeTrigger date-selected">
<span>11</span></td>
<td class="closeTrigger">
<span>12</span></td>
<td class="closeTrigger">
<span>13</span></td>
<td class="closeTrigger todays-date">
<span>14</span></td>
<td class="closeTrigger">
<span>15</span></td>
<td class="closeTrigger">
<span>16</span></td>
<td class="weekend closeTrigger">
</tr>
<tr>
<td class="weekend closeTrigger">
<span>17</span></td>
<td class="closeTrigger">
<span>18</span></td>
<td class="closeTrigger">
<span>19</span></td>
<td class="closeTrigger">
<span>20</span></td>
<td class="closeTrigger">
<span>21</span></td>
<td class="closeTrigger">
<span>22</span></td>
<td class="weekend closeTrigger">
</tr>


Correct xpath- //tr[not(@class='week-selected')]//td[@class='closeTrigger']//span

For reference, here is the verified snapshot from firepath.




webpage-

Login to http://www.makemytrip.com/

Note- Here we need to take care while writing the xpath for password field because that has some hidden html code.

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

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

WebDriver driver =new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.makemytrip.com");
driver.findElement(By.id("login_dropOpenItem")).click();
driver.findElement(By.id("username")).sendKeys("rishi.vg1@gmail.com");
driver.findElement(By.xpath("//input[@id='password_text']")).sendKeys("somepassword");
driver.findElement(By.id("login_btn")).click();
}
}

Tuesday, June 17, 2014

Select value from dropdown without using Select class. Good example.

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

public class SelectFromDropDown {
    public static void main(String[] args) {
        WebDriver driver=new FirefoxDriver();
        driver.get("https://makemytrip.com/");
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.findElement(By.xpath("//div//span[2][contains(@class,'flL travelers rght_space room_sec1')]")).click();
        Actions act = new Actions(driver);
        act.sendKeys(Keys.chord(Keys.DOWN,Keys.DOWN)).perform(); //press down key two times to select 3
    }
}

Monday, June 16, 2014

How to Generate XSLT report ?

How to Generate XSLT report ?

How to Generate XSLT report ?

Its a kind of user friendly report. XSLT stands for XML (Extensible Markup Language) Stylesheet Language for Transformations.  XSLT gives interactive (user friendly) reports with "Pie Chart".

Steps to generate XSLT Report-

1) 1st execute the test cases using ANT tool. Here are the steps to setup and execute the framework through ANT tool - click here

2) Download the XSLT. Please follow the below steps to download.

i) click on this button shown below.



ii) Then click on the download button.



3) After downloading, unzip the downloaded folder-

After unzipped, you will get,



4) Now from the above, copy lib and testng-results.xsl inside your project directory. Don't copy build.xml because you have created that already while doing ANT setup.
Here we are referring the same project which we have already done using POM- LinkedIN_Project_By_POM



5) After copying above files, add the jars files to your project through build path from the lib folder which you have copied in the above step.



6) Now we are ready to gen the XSLT report. As we have already executed our test cases through ANT so now,
i) open cmd and navigate to the project directory.



ii) Then just type ant generateReport and hit enter.



iii) Now a folder will be generated with the name testng-xslt



iv) Open this report in browser-



This is the xslt report-

Print the name of the people in the gmail chatbox list and number of people in the gmail chat box in lefthand side. Realtime scenario.

Print the name of the people in the gmail chatbox list and number of people in the gmail chat box in lefthand side. Realtime scenario.