Elements of JMeter


Below figure represents most widely used components of JMeter called as elements:

JMeterTutorial

Studying all of the JMeter Components will be confusing so I am covering only the most important JMeter elements:
  1. Thread Group
  2. Samplers
  3. Configuration
  4. Listeners

Thread Group

Event By ThoughtWorks : Beyond Automation - Continuous Integration : Gurgaon



This is just to inform you about the upcoming event on Beyond Automation - Continuous Integration. This event is being organised by ThoughtWorks on Saturday 06 Dec, 2014 09:00 AM at:

ThoughtWorks Technologies (India) Pvt Ltd. 

6th Floor, 
Tower Building No. 14
DLF Cyber City Phase III
Gurgaon-122002, Haryana

Beyond Automation - Continuous Integration’ will be an interactive workshop which aims to challenge your skill set to a level beyond automation. Continuous delivery has become the mantra in the agile world to get the automation test results feedback at the earliest in a short span of time. When there are frequent code pushes in a distributed or non-distributed team, it becomes important to have your set of tests with each build as every time doing it manually is a difficult task.

The topics covered will be appropriate for testers with basic knowledge of selenium. Also do bring your own Windows machines having Java and Selenium setup.

For registration, do visit below link:

If you face any issue, you can contact me by completing the Contact Us form.

JMeter Tutorial : Introduction to JMeter


This is just an introduction to JMeter. Below are some points covered in this video:

- How to install and configure JMeter?
- Why JMeter and Features of JMeter
- History of JMeter
- Parameters of JMeter
- Introduction to Sampler, Threads, Listeners, Controllers, Timer, Pre-Processor, Post-Processor, Test Plan, Work Bench etc






Continuous Integration Tool : Jenkins + Selenium + TestNG


A complete tutorial for Continuous Integration Tool : Jenkins

What is Continuous Integration?

“Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily - leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration
errors as quickly as possible” – Martin Fowler

CI - Workflow














CI - Benefits

  • — Immediate bug detection
  •  No integration step in the lifecycle
  •  A deployable system at any given point
  • — Record of evolution of the project

Jenkins

About Jenkins

  • Branched from Hudson
  • —Java based Continuous Build System
  • Runs in servlet container
  • Glassfish, Tomcat
  • Supported by over 400 plugins
    • SCM, Testing, Notifications, Reporting, Artifact Saving, Triggers, External Integration
  • Under development since 2005
  • http://jenkins-ci.org/

Jenkins - History


  • 2005 - Hudson was first release by Kohsuke Kawaguchi of Sun Microsystems
  • 2010 – Oracle bought Sun Microsystems
    • Due to a naming dispute, Hudson was renamed to Jenkins
    • Oracle continued development of Hudson (as a branch of the original)

What can Jenkins do?


  • Generate test reports
  • —Integrate with many different Version Control Systems
  • Push to various artifact repositories
  • Deploys directly to production or test environments
  • Notify stakeholders of build status 
  • …and much more

Step By Step : Process to Install and Configure Jenkins With your Script.

1) Download Jenkins by clicking here:












2) Keep the downloaded Jenkins.war file where your project is placed. For Example:











3) Open Command Prompt and go to the project path. Like:






4) After going to that path, write java -jar jenkins.war and press Enter.

How to take Screenshots if Test Case fails?


One basic question which comes in everyone's mind is : What happens if test case fails? Where was the error in script and How can we capture it?

So, the solutions is always (at least in most of the cases) to take screenshots of webpage when the test run fails.

With one look at the screenshot we can get an idea of where exactly the script got failed. Moreover reading screenshot is easier compare to reading 100's of console errors

To get screenshot on test failure, we should put the entire code in try-catch block. In the catch block we should paste the screenshot code:

public class TakeScreenshot {
 
   WebDriver driver;
 
 @BeforeTest
 public void start(){
  driver = new FirefoxDriver();
 }


Run a Bat File with Java Program


Sample JAVA Code:

public class RunBat {

public static void main(String[] args) throws IOException, InterruptedException{

Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("cmd /c F:\\bb.bat");
process.waitFor();
}
}

How to handle Authentication PopUp using Selenium?

Sometime we have to automate websites which shows authentication Pop Up like mentioned below:











In order to automate this PopUp, we will pass UserId and Password via URL:

http://username:password@anytestwebsite.com

Java Script:

String URL = "http://" + username + ":" + password + "@" + anytestwebsite.com;
driver.get(URL);
Alert alert = driver.switchTo().alert();
alert.accept();

Database Connection in Selenium


  • Below is the source code to connect your MySQL database with Selenium :
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection ("jdbc:mysql://localhost:3306/demo","username","password");
Statement stmt = (Statement) con.createStatement();
// Below statement we use for executing sql queries.
stmt.executeQuery("Select * from dbtable");

In order to connect, you will need to add one jar file which you can download by clicking here

  • To connect Oracle database with Selenium, write below code:
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost: 
1521:orcl","username","password");
Statement stmt = con.createStatement();
stmt.executeQuery("Select * from dbtable");

In order to connect, you will need to add one jar file which you can download by clicking here

Selenium Webdriver Architecture


This diagram is just to show how Selenium Webdriver works. If anyone asks for Selenium Webdriver architecture then just need to design the below diagram and explain it. I share this as it is one of the most frequently asked Selenium Question

Selenium Architecture
Selenium Webdriver Architecture

Selenium Remote Control Architecture


This diagram is just to show how Selenium Remote Control works. If anyone asks for Selenium RC architecture then just need to design the below diagram and explain it. I share this as it is one of the most frequently asked Selenium Question


Selenium RC Architecture
Selenium Remote Control Architecture

Alert handling in Selenium


public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
String Url = "http://sislands.com/coin70/week1/dialogbox.htm";
driver.get(Url);
WebElement alert = driver.findElement(By.xpath("///div[1]/center/table/tbody/tr/td/form[1]/p/input"));
alert.click();
Alert popup = driver.switchTo().alert();
System.out.println(popup.getText());
popup.accept();
Thread.sleep(3000);
driver.close();

}

Pick Date From a Calendar in Selenium



public static void main(String[] args) throws InterruptedException {

WebDriver driver = new FirefoxDriver();
driver.get("http://jqueryui.com/datepicker/");
driver.manage().window().maximize();
driver.switchTo().frame(0);
driver.manage().timeouts().implicitlyWait(3000, TimeUnit.MILLISECONDS);
driver.findElement(By.xpath("//*[@id='datepicker']")).click();
driver.manage().timeouts().implicitlyWait(3000, TimeUnit.MILLISECONDS);
driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div/a[2]/span")).click();
List column = driver.findElements(By.tagName("td"));
for (WebElement j : column)
{
if (j.getText().contains("13")){
j.findElement(By.linkText("13")).click();
break;
}
}
Thread.sleep(5000);
}

How to write dynamic Xpath to identify elements on Webpage?


We always have concerns about writing Dynamic Xpath. So, I've listed below some ways to write xpath with example. If you face any problem, Contact Us:

1) Based on location
2) Using Single Attributes
3) Using Multiple Attributes
4) Using functions


All examples are based on following HTML Code:

input class="search-field" name="s" placeholder="Search …" title="Search for:" type="search" value=""

Run your script in Internet Explorer (IE)


 public static void main(String[] args) throws InterruptedException { DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer(); ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true); System.setProperty("webdriver.ie.driver", "C:/IEDriverServer.exe"); WebDriver driver = new InternetExplorerDriver(ieCapabilities); driver.get("http://google.com"); Thread.sleep(5000); driver.quit(); }

- Download IE Driver by Clicking Here

How to handle Cookies using Selenium Webdriver?



  • Sometimes, we face issues because of cookies session created by Selenium scripts and we have to delete them using Selenium Webdriver. So, here is the code:

public class Cookies
{
    public static void main(String[] args) 
    {
        WebDriver driver=new FirefoxDriver();
        driver.get("http://in.quikr.com/");
        
        Set cookies=driver.manage().getCookies();
        
        //To fetch out the number of cookies used by this site
        System.out.println("Number of cookies in this site "+cookies.size());
        
     //Using advanced For Loop
        for(Cookie cookie:cookies)
        {
            System.out.println(cookie.getName()+" "+cookie.getValue());
            
            //This will delete cookie By Name
            driver.manage().deleteCookieNamed(cookie.getName());
            
             }
         //This will delete all cookies.
        driver.manage().deleteAllCookies();
           } }

For any query, ContactUs

Mouse Hover in selenium



public static void main(String[] args) throws InterruptedException {

WebDriver driver = new FirefoxDriver();
driver.get("http://www.timeanddate.com/");
driver.manage().window().maximize();
WebElement menu = driver.findElement(By.xpath("//*[@id='nav']/ul/li[3]/a"));
Actions action = new Actions(driver);
action.moveToElement(menu).perform();
WebElement submenu = driver.findElement(By.xpath("//*[@id='nav']/ul/li[3]/ul/li[4]/a"));
action.moveToElement(submenu).click().perform();

Thread.sleep(5000);
driver.close();
}

For any queries, ContactUs

Get all links of a Webpage using Selenium


How to test links of any website?

public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.co.in/");
List links = driver.findElements(By.tagName("a"));
System.out.println(links.size());    // to check the number of links present at webpage
for (int i = 1; i {
System.out.println(links.get(i).getText());
}
}