Thursday, 10 July 2014

Selenium Online Training by Quontra Solutions

We are pleased to supply a lot of information and a dozen of free hands-on tutorials. All the available tutorials are surrounded with screenshots and downloadable code samples. This blog is created and will be maintained by Quontra Solutions. Quontra solutions Trainers have many years of experience in automated testing. Quontra Solutions is particularly interested in web technology and new programming languages. We are always trying to find a way to transfer knowledge to Students who are interested in the automated testing of software.
A variety of topics will be covered on this blog. Starting with recording tests with Selenium IDE and locating web elements and furthermore the use of design patterns and performance measurement to create a robust testing framework.
Selenium Tutorial using C# and NUnit
In this tutorial we are going to learn how to create your first test script using the language that most commonly used, c#. Since most languages are semantically the same, if you do not use c# it shouldn’t be too difficult to translate the tutorial into your language of choice. You have to download Nunit and at least Visual Studio Express c# edition to complete this tutorial. They are free to download and use.
  1. Follow steps 1-4 of Selenium Remote Control HTML Suite Tutorial. This will get the Selenium Remote Control Running.
  2. In Visual Studio let’s create a new project. You will have to create a new class library by going New> New Solution> Class Library and call it TheAutomatedTester
  3. Add a reference to the NUnit Framework by rightclicking on the solution and clicking add reference. Click on the browse tab and navigate to <%nunithome%>\bin and select nunit.framework.dll . This allows you now to create your first NUnit test.
  4. Now in the *.cs file put the code below into it. The code below will call Selenium Remote and say that it needs an instance on Firefox Chrome.
  1.        [TestFixture]
  2.        public class TheAutomatedTester
  3.        {
  4.                private ISelenium selenium;
  5.            private StringBuilder verificationErrors;
  6. [SetUp]
  7. public void SetupTest()
  8. {
  9.        selenium = new DefaultSelenium(“localhost”, 4444, “*chrome”, “http://localhost”);
  10. selenium.Start();
  11. verificationErrors = new StringBuilder();
  12.    }


  1. Now Lets create a test:
  1. [Test]
  2. public void AutomatedTester_Test()
  3. {
  4. selenium.Open(“/index.htm”);
  5. selenium.Click(“buttonName”);
  6. selenium.WaitForPageToLoad(“30000″);
  7. }
The code above would open the page index.htm for the root of your local web server then click on a button and wait for a page to load. If you want to see how to the other commands look I would suggest creating your command in Selenium IDE and then converting them to c# using the Options > Format commands.
  1. Once your test has run you will need to clean up Selenium object. The best way to do this is to create a teardown function in your test. It should look like something like the code below.
  1. [TearDown]
  2. public void TeardownTest()
  3. {
  4. try
  5. {
  6. selenium.Stop();
  7. }
  8. catch (Exception)
  9. {// Ignore errors if unable to close the browser
  10. }
  11. Assert.AreEqual(“”, verificationErrors.ToString());
  12. }
If you make sure that your code has this teardown then you will be able to reuse the Selenium Remote Control.
  1. Now compile the code into a DLL and Open it with NUnit. When you click the Run button in NUnit it will run your Selenium Test.
If you would like to make your test data driven put all the code to pull the data in the SetUp

Friday, 4 July 2014

Selenium Interview Questions

Below are the few commonly asked Selenium Interview Questions
What is Selenium?
Selenium is a suite of tools for browser automation. It is composed of “IDE”, a recording and play back mechanism, “WebDriver” and    remote control “RC” which provides APIs for browser automation in variety of languages and “Grid”, which allows many tests using APIs to be run in parallel. The recorded tests can be imported in most languages like html, Java , .net , perl , ruby etc. The exported test can be run in any browser and any platform using selenium remote control “RC”
 What are the components of selenium ?
Selenium IDE – Plugin to Firefox to record and play test in Firefox and also export tests in different languages. The most appealing format is the html test case which seems to be based on fit html
Selenium RC- Allows playing of exported test in different platform/OS
Selenium Grid – Allows to control lots of selenium machines(you typically don’t need this only for load test -and hence may ignore it).
What are the capabilities of Selenium WebDriver or Google WebDriver or Selenium 2.0? 
Capabilities of Selenium WebDriver or Google WebDriver or Selenium 2.0 are:
One should use WebDriver when requiring improved support for
  1. Mult-browser testing including improved functionality for browsers not well-supported by Selenium-1.0.
  2. Handling multiple frames, multiple browser windows, pop-ups, and alerts.
  3. Page navigation.
  4. Drag-and-drop.
  5. AJAX-based UI elements.
Which are the browsers supported by Selenium RC?
Browsers supported by Selenium RC are:
  1. Firefox
  2. Mock
  3. Firefoxproxy
  4. pifirefox
  5. iexploreproxy
  6. iexplore
  7. firefox3
  8. Safari proxy
  9. Google chrome
  10. conqueror
  11. firefox2
  12. safari
  13. piiexplore
  14. firefoxchrome
  15. Opera
  16. iehta
What are the Operating Systems supported by Selenium?
Operating Systems supported by Selenium are:
Selenium IDE
Works in Firefox 2+ Start browser, run tests Run tests
Operating Systems Supported:
  1. Windows
  2. OS X
  3. Linux
  4. Solaris
  5. Others whichever supports Firefox 2+
Selenium Remote Control:
Used for starting browser and run tests
Operating Systems Supported:
  1. Windows,
  2. OS X
  3. Linux
  4. Solaris
  5. Others
Selenium Core:
Used for running tests
Operating Systems Supported:
  1. Windows
  2. OS X
  3. Linux
  4. Solaris
  5. Others
What is the difference between assert and Verify Commands?
There are two mechanisms for validating elements that are available on the application under test. The first is assert: this allows the test to check if the element is on the page. If it is not available, then the test will stop on the step that failed. The second is verify: this also allows the test to check whether the element is on the page, but if it isn’t, then the test will carry on executing.
What is the price of Selenium license per server?
Selenium is open source software, released under the Apache 2.0 license and can be downloaded and used without charge.
How much does Selenium license cost per client machine?
Selenium is open source software, released under the Apache 2.0 license and can be downloaded and used without charge.
Where to download Selenium?
Selenium can be downloaded and installed for free from seleniumhq.org

How to take a screenshot in Selenium Webdriver

code will help you how to take a snapshot in selenium webdriver.

Also one thing noticed is that sometimes “import org.openqa.selenium. TakesScreenshot;” this import don’t appear and you have to manually add this line to your code to make this work. import java.io.File;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class Chrome {
WebDriver driver;
@BeforeMethod
public void launchChrome()
{
System.setProperty(“webdriver.chrome.driver”, “E:\Harsimran-PC\workspace\chromedriver_win_26.0.1383.0\chromedriver.exe”);
driver = new ChromeDriver();
driver.get(“http://google.co.in”);
}
@Test
public void googleScreenshot()
{
try {
File scrnsht =((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// This is where magic happens FileUtils.copyFile(scrnsht, new
File(“e:\google_page.png”));
} catch (Exception e) {
e.printStackTrace();
}
}
@AfterTest
public void kill()
{
driver.close();
}
}

Usage of sql jdbc 4.0 driver

This post is related to using sql jdbc driver 4.0

If you are using sql jdbc driver then these are things to note and follow:
1) Download sqljdbc driver from http://www.microsoft.com/en-in/download/details.aspx?id=11774
2) Now if your jdk is 32-bit then set the 32-bit driver path to your system property or 64-bit if your jdk is 64-bit
3) Now if you are using integrated security then copy the authorization .dll to your system32 folder and set that property to your system path as well.
4) If you still get issues with it then let us know

Selenium Tutorial using C# and NUnit

We are pleased to supply a lot of information and a dozen of free hands-on tutorials. All the available tutorials are surrounded with screenshots and downloadable code samples. This blog is created and will be maintained by Quontra Solutions. Quontra solutions Trainers have many years of experience in automated testing. Quontra Solutions is particularly interested in web technology and new programming languages. We are always trying to find a way to transfer knowledge to Students who are interested in the automated testing of software.
A variety of topics will be covered on this blog. Starting with recording tests with Selenium IDE and locating web elements and furthermore the use of design patterns and performance measurement to create a robust testing framework.
Selenium Tutorial using C# and NUnit
In this tutorial we are going to learn how to create your first test script using the language that most commonly used, c#. Since most languages are semantically the same, if you do not use c# it shouldn’t be too difficult to translate the tutorial into your language of choice. You have to download Nunit and at least Visual Studio Express c# edition to complete this tutorial. They are free to download and use.
  1. Follow steps 1-4 of Selenium Remote Control HTML Suite Tutorial. This will get the Selenium Remote Control Running.
  2. In Visual Studio let’s create a new project. You will have to create a new class library by going New> New Solution> Class Library and call it TheAutomatedTester
  3. Add a reference to the NUnit Framework by rightclicking on the solution and clicking add reference. Click on the browse tab and navigate to <%nunithome%>\bin and select nunit.framework.dll . This allows you now to create your first NUnit test.
  4. Now in the *.cs file put the code below into it. The code below will call Selenium Remote and say that it needs an instance on Firefox Chrome.
  1.        [TestFixture]
  2.        public class TheAutomatedTester
  3.        {
  4.                private ISelenium selenium;
  5.            private StringBuilder verificationErrors;
  6. [SetUp]
  7. public void SetupTest()
  8. {
  9.        selenium = new DefaultSelenium(“localhost”, 4444, “*chrome”, “http://localhost”);
  10. selenium.Start();
  11. verificationErrors = new StringBuilder();
  12.    }


  1. Now Lets create a test:
  1. [Test]
  2. public void AutomatedTester_Test()
  3. {
  4. selenium.Open(“/index.htm”);
  5. selenium.Click(“buttonName”);
  6. selenium.WaitForPageToLoad(“30000″);
  7. }
The code above would open the page index.htm for the root of your local web server then click on a button and wait for a page to load. If you want to see how to the other commands look I would suggest creating your command in Selenium IDE and then converting them to c# using the Options > Format commands.
  1. Once your test has run you will need to clean up Selenium object. The best way to do this is to create a teardown function in your test. It should look like something like the code below.
  1. [TearDown]
  2. public void TeardownTest()
  3. {
  4. try
  5. {
  6. selenium.Stop();
  7. }
  8. catch (Exception)
  9. {// Ignore errors if unable to close the browser
  10. }
  11. Assert.AreEqual(“”, verificationErrors.ToString());
  12. }
If you make sure that your code has this teardown then you will be able to reuse the Selenium Remote Control.
  1. Now compile the code into a DLL and Open it with NUnit. When you click the Run button in NUnit it will run your Selenium Test.
If you would like to make your test data driven put all the code to pull the data in the SetUp.

QTP vs Selenium

Features Selenium QTP
Cost Open Source & Comfortable User needs license for QTP which is very costly.
Efforts and Skill User needs to have good amount of Java skill and more coding effort is required to implement the functions It requires less effort to create a script, as it has a very good user friendly script development environment
Test Case Termed as Testcase. Each Testcase has block of coding statements Termed as Automation Script
Support for web browsers Supports IE, Firefox, Safari and Opera Supports IE & Firefox only
Support for File upload (system) Not available Supports all kinds of File upload
Database Support With the help of DSN (ODBC32 Interface) Requires Extensive Coding
Language Support VBScript Selenese, Java, Ruby, Perl, PHP, Python, C#, Groovy
Technical Support Since it is an open source, it has no official tech support QTP offers very good technical support via phone, mail, web forum
Application Type It can be used to test only web based applications It can test web-based as well as desktop applications