Wednesday 30 October 2013

How to install maven in eclipse

We can install in two ways 

Way 1:


Way 2:
Open 

Help-> Install new software


a popup window will open then give this url.

If your eclipse is Indigo you can use this

http://download.eclipse.org/technology/m2e/releases/1.3/1.3.1.20130219-1424

Or else try with below links as wellMaven 3 - http://repo1.maven.org/maven2/.m2e/connectors/m2eclipse-subclipse/0.13.0/N/0.13.0.201207041403/

Maven 2 - http://download.eclipse.org/m2e-wtp/releases/





It will install maven in your eclipse.
Juno - http://download.eclipse.org/releases/juno

Tuesday 8 October 2013

What is the Selenium 2.0 architecture

If you are looking for more details about Selenium 

You can get details over here..

how to take screen shot whenever there is a failure in the framework or test cases in selenium script ?

Our aim is to take screen shot whenever test case fail.There are several way to take screen shots.
1) By putting try  catch - exception code in your framework whenever control comes to catch exception  then take a screen shot by screen shot take method.

2)  By putting listners
import java.io.File;

import org.testng.ITestResult;
import org.testng.Reporter;
import org.testng.TestListenerAdapter;

public class Screenshot extends TestListenerAdapter {
@Override
public void onTestFailure(ITestResult result) {
File file = new File("");

Reporter.setCurrentTestResult(result);
System.out.println(file.getAbsolutePath());
Reporter.log(file.getAbsolutePath());

Reporter.log("screenshot saved at "+file.getAbsolutePath()+"\\reports\\"+result.getName()+".jpg");
Reporter.log("<a href='../"+result.getName()+".jpg' <img src='../"+result.getName()+".jpg' hight='100' width='100'/> </a>");
BaseClass.selenium.captureScreenshot(file.getAbsolutePath()+"\\reports\\"+result.getName()+".jpg");
Reporter.setCurrentTestResult(null);
}

@Override
public void onTestSkipped(ITestResult result) {
// will be called after test will be skipped
}

@Override
public void onTestSuccess(ITestResult result) {
// will be called after test will pass
}

}

3) By writing After Method

@AfterMethod(alwaysRun = true, description = "take screenshot")
public void afterMethod_takeScreenshot(ITestResult result, Method m) throws Exception {
if (!result.isSuccess()) {
TakesScreenshot screen = (TakesScreenshot) driver;
File fileScreen = screen.getScreenshotAs(OutputType.FILE);
File fileTarget = new File("failure_" + m.getName() + ".png");
FileUtils.forceMkdir(fileTarget.getParentFile());
FileUtils.copyFile(fileScreen, fileTarget);
}
}

4)TestWatcher rule
http://junit-team.github.io/junit/javadoc/4.10/org/junit/rules/TestWatcher.html#!

What tools can I use to test Web services and APIs? what is the best tool for API testing

There are number of tools available in the market.
We can do web service testing by using either
Soap Ui,
Jmeter
or by using programming  we can write either in JAVA, Python, Ruby.

If you would like to go by programming.I would say that also depends on your development team what programming language web services are written. You might want to use the same programming language in order to have developers support.

For API testing you don't need to deal with browser related and UI/ elements related hassle.

Testing WebServices is much easier than testing GUI. In nut-shall, you need to understand how HTTP requests are made & how responses can be consumed? Requests and responses are usually in the form of JSON or XML so you need to know relevant libraries (depending on the language you are using).

JMeter is also a good choice given that it's open source/free, it's relatively easy to use, and because it gives you rudimentary performance data with your test runs (average, min, max, median response times for all requests).

If you're open to a programming approach to testing, There is a tool called REST Assured over JMeter or similar tool. http://code.google.com/p/rest-assured/ A combination of TestNG and RESTAssured makes things pretty simple.



http://www.testinggeek.com/testing-restful-webservices-or-api-testing-remember-papas-be-sfo-deed-help-gc-and-dvla-pc#!

How to setup proxy settings for Chrome browser in selenium java

We can set up proxy settings for chrome as below.
Here I have stored proxy url, user name, password in config.properties file and calling to here.. other wise you can give details directly over here as well.

//Proxy settings
 
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
       proxy.setProxyType(ProxyType.MANUAL); 
proxy.setHttpProxy(CONFIG.getProperty("hostname"));
proxy.setSslProxy(CONFIG.getProperty("hostname"));
proxy.setFtpProxy(CONFIG.getProperty("hostname"));
proxy.setSocksUsername(CONFIG.getProperty("username"));
proxy.setSocksPassword(CONFIG.getProperty("password"));
  
   DesiredCapabilities cap = new DesiredCapabilities();
   cap.setCapability(CapabilityType.PROXY, proxy); 
  //DesiredCapabilities capabilities = DesiredCapabilities.chrome();
  //capabilities.setCapability("chrome.switches", Arrays.asList("--proxy-server=http://user name:password@proxyurl:8080"));
  // WebDriver driver = new ChromeDriver(capabilities);
 
driver = new ChromeDriver(cap);
builder = new Actions(driver); 
bckdbrowser = new WebDriverBackedSelenium(driver,
ConfigReader.ENVIRONMENT_URL);
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS );