Integration Of Selenium With Saucelabs




What is Saucelabs?
Sauce Labs is a cloud platform for executing automated and manual mobile and web tests. Sauce Labs supports running automated tests with Selenium WebDriver (for web applications) and Appium (for native and mobile web applications).

Why do we need Saucelabs?
Straight forward answer : Browser Compatibility. We need to test all our testcases in various versions of browsers and various platforms too. We can’t install all those stuff in our local box. Now this Saucelabs plays a major role.

How to integrate your Test scripts with Saucelabs?
It’s quite simple buddies, Just need to follow few steps
Step 1: Sign up for a Sauce Labs account (Free Trail)
Step 2: Get your Access Key from your account (Login and click on ‘My Account‘, Now you will see Access key)
Step 3: Choose the Testcases which you want to run on the cloud
Step 4: Check your Results (Click on ‘Archives‘ to view the video, Screenshots)

Here’s a sample code for your reference



import java.net.URL;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;

public class SauceSele {

// enter your saucelabs user name here
public static final String USERNAME = “YourUserName”;

//enter your access key here
public static final String ACCESS_KEY = “XXXXXXXXXXXXXXXXXXXXXX55641A”;
public static final String SauceLabURL = “http://” + USERNAME + “:”
+ ACCESS_KEY + “@ondemand.saucelabs.com:80/wd/hub”;
private WebDriver driver;

@Test(priority = 1)
public void test_Windows_Firefox() throws Exception {
DesiredCapabilities caps = DesiredCapabilities.firefox();
caps.setCapability(“platform”, “Windows 7”);
caps.setCapability(“version”, “38”);
caps.setCapability(“name”, “Testing on Firefox 38”);
this.driver = new RemoteWebDriver(new URL(SauceLabURL), caps);
driver.get(“https://seleniumbycharan.wordpress.com/”);
System.out.println(driver.getTitle());
System.out.println(“BrowserName :” + caps.getBrowserName() + ” – ”
+ “Version : ” + caps.getVersion());
System.out
.println(“————————————————————————————“);
}

@Test(priority = 2)
public void test_Windows_IE() throws Exception {

DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability(“platform”, “Windows 8.1”);
caps.setCapability(“version”, “11”);
caps.setCapability(“name”, “Testing on IE 11”);

this.driver = new RemoteWebDriver(new URL(SauceLabURL), caps);
driver.get(“https://seleniumbycharan.wordpress.com/”);
System.out.println(driver.getTitle());
System.out.println(“BrowserName :” + caps.getBrowserName() + ” – ”
+ “Version : ” + caps.getVersion());
System.out
.println(“————————————————————————————“);

}

@Test(priority = 3)
public void test_Windows_Chrome() throws Exception {

DesiredCapabilities caps = DesiredCapabilities.chrome();
caps.setCapability(“platform”, “Windows XP”);
caps.setCapability(“version”, ” 43.0″);
caps.setCapability(“name”, “Testing on Chrome 43”);

this.driver = new RemoteWebDriver(new URL(SauceLabURL), caps);
driver.get(“https://seleniumbycharan.wordpress.com/”);
System.out.println(driver.getTitle());
System.out.println(“BrowserName :” + caps.getBrowserName() + ” – ”
+ “Version : ” + caps.getVersion());
System.out
.println(“————————————————————————————“);

}

@Test(priority = 5)
public void test_Mac_Safari() throws Exception {

DesiredCapabilities caps = DesiredCapabilities.safari();
caps.setCapability(“platform”, “OS X 10.9”);
caps.setCapability(“version”, “7”);
caps.setCapability(“name”, “Testing on Safari”);

this.driver = new RemoteWebDriver(new URL(SauceLabURL), caps);
driver.get(“https://seleniumbycharan.wordpress.com/”);
System.out.println(driver.getTitle());
System.out.println(“BrowserName :” + caps.getBrowserName() + ” – ”
+ “Version : ” + caps.getVersion());
System.out
.println(“————————————————————————————“);

}

@Test(priority = 6)
public void test_Linux_Firefox() throws Exception {

DesiredCapabilities caps = DesiredCapabilities.firefox();
caps.setCapability(“platform”, “Linux”);
caps.setCapability(“version”, “36”);
caps.setCapability(“name”, “Testing on Linux firefox”);

this.driver = new RemoteWebDriver(new URL(SauceLabURL), caps);
driver.get(“https://seleniumbycharan.wordpress.com/”);
System.out.println(driver.getTitle());
System.out.println(“BrowserName :” + caps.getBrowserName() + ” – ”
+ “Version : ” + caps.getVersion());
System.out
.println(“————————————————————————————“);

}

@AfterTest
public void tearDown() throws Exception {
driver.quit();
System.out.println(“driver was closed”);
}
}

That’s it! All your testcases was executed on different versions and different platforms.You can view the results on clicking ‘Archives‘ in your saucelabs dashboard.

What did I do here? No browser was invoked? Surprised?
Generally we’ll use WebDriver driver = new FirefoxDriver(); command to invoke a browser.
But here we don’t need that, we call RemoteWebDriver class to connect remote driver pointed at ondemand.saucelabs.com specifying your Sauce Labs account credentials and desired browser configuration.

We have DesiredCapabilities to set the configuration.
* browser Represents the browser to be used as part of the test run.
* version Represents the version of the browser to be used as part of the test run.
* os Represents the operating system to be used as part of the test run.
You can also name your job too.

You can also run your tests in parallel using TestNG, JUNIT yada yada. You can also integrate with your CI (Jenkins).This is quite simple and useful right!!

Compatibility Testing Using Browserstack with Selenium



BrowserStack allows users to make manual and automation testing on different browsers and operation systems.To execute your test scripts using BrowserStack, you need to set parameters of Browsers and Platforms.

There are few steps to be followed to integrate Selenium with BrowserStack.

Step 1 : SignUp for BrowserStack account (Free Trail)
Step 2 : Get your UserName and Access Key (Click on Account at the top and click on ‘Automate‘)
Step 3 : Create your Test scripts using TestNG
Step 4 : Create a TestNG.xml file to run tests in parallel (set platforms and browsers with desired versions).
Step 5 : Execute TestNG.xml.
Step 6 : To view your results, Login and click on ‘Automate‘ link. You can view your project results.

Here I’m providing a sample code. I’m using TestNG to run tests in parallel.

package package1;

import java.io.File;
import java.io.IOException;
import java.net.URL;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class BrowserStackTestCase {

private WebDriver driver;
public static final String USERNAME = “ARORAGLOBALSERVICES”;
public static final String AUTOMATE_KEY = “YourAccessKey”;
public static final String URL = “http://” + USERNAME + “:” + AUTOMATE_KEY
+ “@hub.browserstack.com/wd/hub”;

@BeforeTest
@Parameters(value = { “browser”, “version”, “platform” })
public void setUp(String browser, String version, String platform)
throws Exception {
DesiredCapabilities capability = new DesiredCapabilities();
capability.setCapability(“platform”, platform);
capability.setCapability(“browserName”, browser);
capability.setCapability(“browserVersion”, version);
capability.setCapability(“project”, “MyProject”);
capability.setCapability(“build”, “2.01”);
driver = new RemoteWebDriver(new URL(URL), capability);
}

@Test(priority = 1)
public void testcase001() throws Exception {
driver.get(“http://www.google.com”);
System.out.println(“Page title : ” + driver.getTitle());
Assert.assertEquals(“Google”, driver.getTitle());
WebElement element = driver.findElement(By.name(“q”));
element.sendKeys(“Merry christmas”);
element.sendKeys(Keys.ENTER);

}

@Test(priority = 2)
public void testcase002() {
driver.get(“http://seleniumhq.org”);
System.out.println(“Page title : ” + driver.getTitle());
Assert.assertEquals(“Selenium – Web Browser Automation”,
driver.getTitle());
}

@AfterMethod
public void takeScreenShot(ITestResult result) {
if (result.getStatus() == ITestResult.FAILURE) {
driver = new Augmenter().augment(driver);

File srcFile = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(srcFile, new File(“D:\\Screenshot”
+ result.getParameters().toString() + “.png”));
} catch (IOException e) {
e.printStackTrace();
}
}
}

@AfterTest
public void tearDown() throws Exception {
driver.quit();
}

}

Now setup your configuration in xml file. Copy the below code:

  Most Frequently Asked Interview Questions" - Manual Testing


Q. What is a Defect?
Ans. Any flaw imperfection in a software work product.
(or)
Expected result is not matching with the application actual result.

Q. What is Severity?
Ans. It defines the important of defect with respect to functional point of view i.e. how critical is defect  with respective to the application.

Q. What is Priority?
Ans. It indicates the importance or urgency of fixing a defect

Q. What is Re-Testing?
Ans. Retesting the application to verify whether defects have been fixed or not.

Q. What is Regression Testing?
Ans. Verifying existing functional and non functional area after making changes to the part of the software or addition of new features.

Q. What is Recovery Testing?
Ans. Checking if the system is able to handle some unexpected unpredictable situations is called recovery testing.

Q. What is End-to-End Testing?
Ans. Testing the overall functionality of the system  including the data integration among all the modules is called end to end testing.

Q. What is Exploratory Testing?
Ans. Exploring the application, understanding the functionality, adding (or) modifying existing test cases for better testing is called exploratory testing.

Q.What is functionality Testing
Ans. Functionality testing is performed to verify that a software application performs and functions correctly according to design specifications.

Q. What is Non-functionality Testing?
Ans. Validating various non functional aspects of the system such as user interfaces, user friendliness security, compatibility, Load, Stress and Performance etc is called non functional testing.
 

10 Most Frequently Asked Interview Questions

I have got many request for the manual testing interview questions. So, here are some of the interview questions which you would like to know about.


Q1. What is a test plan?

A: A software project test plan is a document that describes the objectives, scope, approach and focus of a software testing effort. The process of preparing a test plan is a useful way to think through the efforts needed to validate the acceptability of a software product. The completed document will help people outside the test group understand the why and how of product validation. It should be thorough enough to be useful, but not so thorough that none outside the test group will be able to read it.

Q2. What is configuration management?

A: Configuration management (CM) covers the tools and processes used to control, coordinate and track code, requirements, documentation, problems, change requests, designs, tools, compilers, libraries, patches, changes made to them and who makes the changes. Rob Davis has had experience with a full range of CM tools and concepts. Rob Davis can easily adapt to your software tool and process needs.

Q3. What if the software is so buggy it can't be tested at all?

A: In this situation the best bet is to have test engineers go through the process of reporting whatever bugs or problems initially show up, with the focus being on critical bugs. Since this type of problem can severely affect schedules and indicates deeper problems in the software development process, such as insufficient unit testing, insufficient integration testing, poor design, improper build or release procedures, managers should be notified and provided with some documentation as evidence of the problem.

Q4. How do you know when to stop testing?

A: This can be difficult to determine. Many modern software applications are so complex and run in such an interdependent environment, that complete testing can never be done. Common factors in deciding when to stop are...
  • Deadlines, e.g. release deadlines, testing deadlines;
  • Test cases completed with certain percentage passed;
  • Test budget has been depleted;
  • Coverage of code, functionality, or requirements reaches a specified point;
  • Bug rate falls below a certain level; or
  • Beta or alpha testing period ends.

Most Frequently Asked Testing Types



In this post, we are trying to cover the most frequently asked testing terms in most of the interviews. 
 
Q1. What is Testing:

It is process of verifying are we developing the right product or not and also    validating the developed product is right or not
     Software Testing = Verification + Validation

Q2. What is Verification?

It is a process of verifying: Are we developing the right product or not. Known as static testing.

Q3.What is Validation?

It is a process of validating: Does the developed product is right or not. Also called as dynamic testing.

Q4. What is black box testing?

Black box testing is functional testing, not based on any knowledge of internal software design or code. Black box testing are based on requirements and functionality.

Q5. What is white box testing?

White box testing is based on knowledge of the internal logic of an application's code. Tests are based on coverage of code statements, branches, paths and conditions.

Q6. What is unit testing?

Unit testing is the first level of dynamic testing and is first the responsibility of developers and then that of the test engineers. Unit testing is performed after the expected test results are met or differences are explainable/acceptable.

Running Selenium Code on Multiple Browsers

Below is the code which might be helpful to you. This code will allow you to launch your URL in Google Chrome, Internet Explorer as well as in Firefox:

public class browsers {
public static WebDriver driver = null;
public static void openbrowser (String browser)
{
if (browser.equalsIgnoreCase("Firefox"))
{
System.out.println("initiated");
driver = new FirefoxDriver();
}