Difference Between Implicit Wait and Explicit Wait


Implicit Wait – 

An implicit wait is to tell WebDriver to stop the DOM for a certain amount of time. The default setting is 0. 

Syntax – driver.manage().timeouts().Implicitly Wait(10, TimeUnit.SECONDS); 

Explicit Wait - 

What is the difference between absolute and relative Xpath?


Absolute Xpath : 

1) start selection from the document node
2) Starts with //
3) e.g. “/html/body/p” matches all the paragraph elements

Google Search Box : /html/body/div[1]/div[2]/div[1]/div[1]/div[3]/div/div/div/form/fieldset[2]/div/div/div

Relative Xpath  : 

1) start selection matching anywhere in the document
2) Starts with /
3) e.g. “//p” matches all the paragraph elements starts with p

Google Search Box : //*[@id='gbqfqwb']

TestNG Error Codes


We write automation framework using TestNG and when we run it we get errors sometimes. So, it becomes important for us to know about error messages. 

I have put some of the error messages that we get when we go wrong and execute TestNG XML file:

1.If two tests are having the same name then we see below error

at org.testng.TestNG.checkTestNames(TestNG.java:981)
at org.testng.TestNG.sanityCheck(TestNG.java:970)
at org.testng.TestNG.run(TestNG.java:1002)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:109)

2.If the testname doesnot enclosed in double quotes("") then we get below error


Launched a tutorial on 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



How to Zoom In and Zoom Out in Website

In case, you want to zoom in and out in any website using Selenium. You can follow below commands:

To Zoom In:

WebElement Sel= driver.findElement(By.tagName("html"));
sel.sendKeys(Keys.chord(Keys.CONTROL, Keys.ADD));

To Zoom Out to normal page, use below command:

html.sel(Keys.chord(Keys.CONTROL, "0"));

This can be useful when you need to pin point something while showing your automation framework to any user. 

How to get data from an Excel sheet?


If you're looking how to pick username and passwords or any data from an excel sheet then below steps will help you out:

1) Download J-Excel jar (What is J-Excel), you can get the path to download J-Excel jar by clicking here
2) Now, add this jar to your build path. You can look for the steps here.
3) Create a new class and add below code:

public class Excel {
static Sheet s ;
 public static void main(String[] args) throws BiffException, IOException {
  
FileInputStream fis = new FileInputStream("C:\\Users\\DELL\\Desktop\\r.xls");
Workbook w = Workbook.getWorkbook(fis);
s = w.getSheet(0);

Generate Random Data


In your scripts, you always want to generate random data to automate SignUp forms, below is code to generate random password. If you need script to generate data to complete forms like available here, do write an email to me:

--------------

public static void main(String[] args) {

//can put any array below depending on requirement
String array = "abcde1234567890~!@#$%^&*()_+";

//calculates its length
int i = array.length();

 //password with length 10
for (int j =0; j<=10; j++)

//randomly picking up 10 characters
{
 int k = (int)(Math.random()*i);
char pass = array.charAt(k);
 System.out.print(pass);
 }
 }

Interview Questions and Answers on Automation Testing

Click on the questions below to get the answers


1) What is Automation ?

Answer: In general, it is the process of implementing particular work automatically by using a machine, to reduce the need of human work in the production of goods and services.
2) What is meant by Automation in software testing ?

Answer: It is a process of testing an application(executing the tests, comparing expected and actual results under some controlled conditions and generating the reports) automatically by using a 'Tool' to reduce the need of human effort. This tool may be Selenium / QTP / RFT / SilkTest etc.
3) Why do we need automation in software testing ?

Answer: Humans can do mistakes. If a work is repetitive then we may skip some work intentionally or unintentionally due to time pressure, boring task, etc. In order to overcome these problems 'automation testing' has been introduced to reduce manual task, to save cost and time, to improve accuracy, to perform repetitive execution of tests, to customize defect reporting etc. and hence automation is needed, as it replaces human with great features.
4) Which type of testing can be Automated ?

Answer: We can automate Regression testing, Functional testing, Stress testing, Performance testing, Load testing, Smoke testing, Compatibility testing, Data-Driven testing etc.
5) When to do automation testing ?

Answer: It is not always advantageous to automate test cases. We can do automation:
- When the application is stable.
- For long term projects.
- When you have lot of regression work.
- When the scenario is easily debuggable.
6) What are the advantages and disadvantages of Automation Testing ?
Answer:

Advantages :
- Reduces human resources.
- Using an automation tool, test scripts can be executed faster when compared to manual execution and hence saves time.
- Repeatable execution of tests may lead to make mistakes when it is done manually but when we automate the same task, accuracy will be improved.
- Test cases can be reused in various versions of software which saves time and cost.

Disadvantages:
- Unemployment rate increases as machine replaces human.
- It is not so easy to write automation test scripts, it requires skilled and experienced resources.
- We cannot automate everything as it is advantageous only for repeatable and reusable test cases.
- Initial cost for automation is very high unless it is open source.
- Debugging skills should be high otherwise its effect will be dangerous (mainly it kills time, so, we cannot reach dead-line).

7) Name some test automation tools?
Answer:

- Selenium (Open Source)
- HP QuickTest Professional (Commercial)
- IBM Rational Functional Tester (Commercial)
- HP WinRunner (Commercial)
- SilkTest (Commercial)
- HTTP Test Tool (Open Source)
- WATIR (Open Source)
- Maveryx (Open Source)
- eggPlant (Commercial)

8) What kind of tests should NOT be automated?
Answer:

- Automating tests that only need to be executed once doesn't make sense.
- Tests without predictable results – test automation should give us confidence in the results of the tests. If there are intermittent failures then the tests cannot be reliable.
- Tests that need to be verified visually
- Tests that need to be executed quickly. At first, writing an automated test takes longer. If we want a quick check, we should test it manually however, if that test is a good one which should be run regularly, then it should be automated in time
- Usability Testing – at times it becomes impossible to perform testing by automation as the computer cannot efficiently judge if the system is of any use to its users.

Difference between Jexcel and Apache POI


JExcel

Apache POI

  • It doesn’t support Excel 2007 and Xlsx format. It supports only Excel 2003 and .Xls format

  • It supports both

  • JXL doesn’t support Conditional formatting

  • It supports

  • JXL API was last updated in 2009

  • Apache POI is actively maintained

  • It doesn't support rich text formatting

  • Apache POI supports it

  • It has very less documents and examples as compare to Apache POI

  • It has extensive set of documents and examples


You can download Apache POI jar by clicking here
You can download JExcel jars by clicking here

Example of JExcel Click Here

Access Modifiers in Java


We always use Public, Private, Protected in our Selenium scripts. Before using these, we should know how and where to use these access modifiers. Here is the table showing where we can call these modifiers:

Access Modifier
within class
within package
outside package by 
subclass only
outside 
package
Private
Y
N
N
N
Default
Y
Y
N
N
Protected
Y
Y
Y
N
Public
Y
Y
Y
Y


Basic Selenium Commands


Below are some basic commands of selenium which you can try and use while writing your script for automation of any website. If you face any problem, you can raise your query by completing the form available at Contact Us page:

  1. driver.get("http://www.google.com"); To open an application
  2. driver.findElement(By.id("passwd-id")); Finding Element using Id
  3. driver.findElement(By.name("passwd")); Finding Element using Name
  4. driver.findElement(By.xpath("//input[@id=’passwd-id’]")); Finding Element using Xpath
  5. element.sendKeys("some text"); To type some data
  6. element.clear(); clear thecontents of a text field or textarea
  7. driver.findElement(By.xpath("//select")); Selecting the value
  8. select.findElements(By.tagName("option")); Selecting the value
  9. select.deselectAll(); This will deselect all OPTIONs from the first SELECT on the page
  10. select.selectByVisibleText("Edam"); select the OPTION withthe displayed text of “Edam”
  11. findElement(By.id("submit")).click(); To click on Any button/Link
  12. driver.switchTo().window("windowName"); Moving from one window to another window
  13. driver.switchTo().frame("frameName"); swing from frame to frame (or into iframes)
  14. driver.switchTo().frame("frameName.0.child"); to access subframes by separating the path with a dot, and you can specify the frame by itsindex too.
  15. driver.switchTo().alert(); Handling Alerts
  16. driver.navigate().to("http://www.example.com"); To Navigate Paeticular URL
  17. driver.navigate().forward(); To Navigate Forward
  18. driver.navigate().back(); To Navigate Backword
  19. driver.close(); Closes the current window
  20. driver.quit(); Quits the driver and closes every associated window.
  21. driver.switch_to_alert(); Switches focus to an alert on the page.
  22. driver.refresh(); Refreshes the current page.
  23. webdriver.manage().window().setPosition(new Point(-2000, 0); to minimize browser window

How to setup Classpath for Java in Windows 7?



We all know the importance of CLASSPATH for Java. Setting PATH/CLASSPATH is very easy if we have the correct steps. I've listed down the steps which will help you to set CLASSPATH/PATH for Java:
 
Step 1: Download Java or JDK from the following URL according to your computer configuration:
Step 2: Install it by click on setup.exe and following the steps.
Step 3: By default JDK installs at "C:\Program Files\Java\jdkxxx.xx" location only. Unless we change the location at the time of installation.
Step 4: Go to JDK installed location, open bin folder available at the location. Now, copy the path.
Step 5: Right-click on My Computer icon available at your desktop and select Properties.
Step 6: Now, click on Advanced System Settings and click on Advanced tab from the dialog box opened
Step 7: Click on Environment Variables and then System Variables.

Step 8: Edit path and add the copied bin (which we did in Step 4) in that. Below are some images to help you:



Step 9: Click on OK of Environment Variables window and System Properties window.
Step 10: To verify whether Classpath or path of java is set up correctly or not.

Open Command Prompt and enter java -version. You'll find a statement like mentioned below:

java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)

Prerequisites to Start Learning Selenium Webdriver


You will need the following to start using Selenium WebDriver or in other words you can say prerequisites required to setup Selenium Webdriver??


  • Java Development Kit (JDK) ( To download it, click here)
  • Eclipse IDE - (To download it, click here)
  • Jar Files (Java Client Driver) - (To download it, click here)

What is HTMLUnitDriver?


HTMLUnitDriver is fastest (50% faster than Firefox), lightweight, platform independent. However, we don't use it. We always prefer to use Firefox, Chrome, IE but not HTMLUnitDriver

Do you know why?? 

Here is the answer:

How to Login and Logout in Gmail

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Openbrowser
{
public static void main(String args[]) throws InterruptedException
{
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
driver.get("http://gmail.com/");
driver.findElement(By.id("Email")).sendKeys("raghav@mobikwik.com");
driver.findElement(By.id("Passwd")).sendKeys("9910979218");
driver.findElement(By.id("signIn")).click();
Thread.sleep(4000);
driver.findElement(By.xpath("//*[@id='gb']/div[1]/div[1]/div[2]/div[5]/div[1]/a/span")).click();
driver.findElement(By.id("gb_71")).click();
}
}

Selenium Webdriver Commands


This is the key of Selenium Webdriver Commands. These are the most commands which will help you in writing your scripts. 


Selenium WebDriver Commands
Selenium Webdriver Commands

Chrome and Internet Explorer driver



Download 32 Bit Chrome Driver by clicking on below Download link:

DOWNLOAD

You can use 32 Bit Chrome Driver on 32 Bit as well as 64 Bit Windows. There is no 64-bit Chrome on Windows yet (See this ticket), as a result there is no ChromeDriver for 64-bit Windows.

Here 32/64 bit are in terms of browser's architecture, not the OS.

Download 64 Bit Internet Explorer Driver by clicking on below Download link:

DOWNLOAD