Monday, 16 June 2014

Sample Selenium Interview Question along with Answers


1) Which is the command used for displaying the values of a variable into the output console or log?
The command used for displaying the values of a variable into the output console or log–echo
If you want to display a constant string. The below mentioned command can be used
echo <constant string>
ex: echo “The sample message”
If you want to display the value of a variable it can be written like below
echo ${<variable name>>
ex: echo ${var1}
2) 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.
3) Which are the browsers supported by Selenium RC?
Browsers supported by Selenium RC are:
1. *firefox
2. *mock
3. *firefoxproxy
4. *pifirefox
5. *chrome
6. *iexploreproxy
7. *iexplore
8. *firefox3
9. *safariproxy
10. *googlechrome
11. *konqueror
12. *firefox2
13. *safari
14. *piiexplore
15. *firefoxchrome
16. *opera
17. *iehta
18. *custom
4) 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
5) What is the difference between an assert and a verify with Selenium commands?
Assert: Will fail and abort the current test execution.
Verify: Will fail and continue to run the test execution.
6) If a Selenium function requires a script argument, what would that argument look like in general terms?
StoreEval(script, variable) and storeExpression(expression, variableName).
7) If a Selenium function requires a pattern argument, what five prefixes might that argument have?
Five prefixes that Selenium pattern argument are:
glob, regexp, exact, regexpi.
8) Why Selenium RC is used?
We use Selenium RC for:
Selenium-IDE does not directly support:
1. Condition statements.
2. Iteration.
3. Logging and reporting of test results.
4. Error handling, particularly unexpected errors.
5. Database testing.
6. Test case grouping.
7. Re-execution of failed tests.
8. Test case dependency.
9. Capture screen shots on test failures.
The reason behind why Selenium-IDE does not support the above mentioned requirements is IDE supports only HTML language. Using HTML language we cannot achieve the above mentioned requirements. Because HTML does not support conditional, looping and external source connectives.
To overcome the above mentioned problems Selenium RC is used.
9) How many testing frameworks can QA Tester use in Selenium RC?
Testing frameworks aren’t required, but they can be helpful if QA Tester wants to automate test cases. Selenium RC supports Bromine, JUnit, NUnit, RSpec (Ruby), Test::Unit (Ruby), TestNG (Java), unittest (Python).
10) What is the architecture of Selenium RC?
The Selenium Server launches and kills browsers and acts as an HTTP proxy for browser requests.
Client libraries for various programming languages, each of which instructs the Selenium Server in how to test the AUT by passing it your test script’s Selenium commands.
The client libraries communicate with the Server passing each Selenium command for execution. Then the server passes the Selenium command to the browser using Selenium-Core JavaScript commands. The browser, using its JavaScript interpreter, executes the Selenium command, which effectively, runs the check you specified in your Selenese test script.
11) Does Selenium support mobile internet testing?
Selenium supports Opera and opera is used in most of the Smart phones. So whichever Smart phone supports opera, selenium can be used to test. So, one can use Selenium RC to run the tests on mobiles.
12) What are the basic annotations used to run TestNG tests in Selenium?
The basic annotations used to run TestNG tests in Selenium RC:
1. @BeforeClass: The annotated method with @BeforeClass will be run before the first test method in the current class is invoked.
2. @AfterClass: The annotated method with @AfterClass will be run after all the test methods in the current class have been run.
3. @BeforeMethod: The annotated method with @BeforeMethod will be run before each test method.
4. @AfterMethod: The annotated method with @AfterMethod will be run after each test method.
5. @Test: Marks a class or a method @Test with as part of the test.
13) What is the difference between Thread.Sleep() and Selenium.setSpeed()?
Selenium.setSpeed:
1. takes a single argument in string format
ex: selenium.setSpeed(“2000″) – will wait for 2 seconds
2. Runs each command in after setSpeed delay by the number of milliseconds mentioned in setSpeed.
Thread.sleep:
1. takes a single argument in integer format
ex: thread.sleep(2000) – will wait for 2 seconds
2. Waits for only once at the command given at sleep.
14)  How to configure Selenium RC with eclipse to run Junit Tests?
1) Download eclipse. click here to download the software
2) Open eclipse -> Workspace Launcher window will open
3) Create a workspace by giving meaningful name
3) Click on Workbench
4) Create a project of type java
5) Create a package under src folder of the package
6) Add Junit to the build path
7) Add selenium rc java client driver to the build path
8) Now drag and drop your test script (.which is exported from Selenium IDE) to the package created.
15) Actual end user simulation, Is the test conducted using this tool equivalent to an end user action?
Selenium performs actions in the background on the browser. It modifies the DOM structure of the HTML page in order to perform actions on the page. To be more precise it executes JavaScript on UI objects within the webpage to perform actions like click, type, select etc. This is the reason why you can execute tests with the browser minimized.
QTP claims to perform end user simulation, in other words executing QTP scripts are equivalent to a person performing those steps manually on the application.
16) Is it possible to use Selenium for multi-user Load Testing?
Yes, but it requires a LOT of hardware. We recommend you check out BrowserMob, which does load testing with real browsers and is powered by Selenium.


Wednesday, 22 January 2014

Copying the One Excel sheet to another excel sheet and Update test cases staus using Java and JXL

import java.io.File;

import jxl.Workbook;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.Colour;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;


public class SampleExcelStatus
{
      @BeforeTest
      public void setup() throws Exception
     
      {
           
      }

      @Test
      public static  void SecondExcelFile() throws Exception
      {   
        Workbook workbook = Workbook.getWorkbook(new File("E:/6409_TestCases_Checkout.xls"));
        WritableWorkbook copywb = Workbook.createWorkbook(new File("E:/6409_TestCases_CheckoutResultsSatya.xls"), workbook);
        WritableSheet sheet1=copywb.getSheet(0);
       
        for(int URowcount=12; URowcount<sheet1.getRows();URowcount++)
            {
                   Label label = new Label(10,URowcount-1,"Pass");
                   WritableCellFormat cfobj=new WritableCellFormat();
                    /*cfobj.setBackground(Colour.GREY_25_PERCENT);
                    cfobj.setAlignment(Alignment.LEFT);
                    cfobj.setOrientation(Orientation.HORIZONTAL);*/
                    cfobj.setBorder(Border.ALL, BorderLineStyle.THIN,Colour.BLACK);
                    label.setCellFormat(cfobj);
                   
                    sheet1.addCell(label);
            }
       
        copywb.write();
        copywb.close();
        workbook.close();
       
      }
     
            @AfterClass
            public void tearDown()
            {
            //    driver.close();
            }  
}

Monday, 7 October 2013

Maveen Central Repository & Download from Reposotoriy

When you build a Maven’s project, Maven will check your pom.xml file, to identify which dependency to download. First, Maven will get the dependency from your local repository Maven local repository, if not found, then get it from the default Maven central repositoryhttp://repo1.maven.org/maven2/
This is how the Maven central repository website looks like


According to Apache Maven :
Downloading in Maven is triggered by a project declaring a dependency that is not present in the local repository (or for a SNAPSHOT, when the remote repository contains one that is newer). By default, Maven will download from the central repository.
In Maven, when you’re declared library does not exist either inlocal repository nor Maven center repository, the process will stop and output error messages to your Maven console.

1. Example

The org.jvnet.localizer is only available at Java.net repository.
pom.xml
    <dependency>
        <groupId>org.jvnet.localizer</groupId>
        <artifactId>localizer</artifactId>
        <version>1.8</version>
    </dependency>
When you build this Maven project, it will fail and output dependency not found error message.
Updated 12/12/2012
The
org.jvnet.localizer is now available in Maven center repository.

2. Declare Java.net repository

To tell Maven to get the dependency from Java.net, you need to declared a remote repository in your pom.xml file like this :
pom.xml
    <repositories>
        <repository>
            <id>java.net</id>
            <url>https://maven.java.net/content/repositories/public/</url>
        </repository>
    </repositories>
Now, Maven’s dependency library look-up sequences is changed to :
  1. Search in Maven local repository, if not found, go step 2, else exit.
  2. Search in Maven central repository, if not found, go step 3, else exit.
  3. Search in java.net Maven remote repository, if not found, prompt error message, else exit.
Maven’s dependency mechanism help to download all the necessary dependency libraries automatically, and maintain the version upgrade as well.



Changing the Maven Local Repository




The maven local repository is a local folder that is used to store all your project’s dependencies (plugin jars and other files which are downloaded by Maven). In simple, when you build a Maven project, all dependency files will be stored in your Maven local repository.
By default, Maven local repository is default to .m2 folder :
  1. Unix/Mac OS X – ~/.m2
  2. Windows – C:\Documents and Settings\{your-username}\.m2

1. Update Maven Local Repository

Normally, I will change the default local repository folder from default .m2 to another more meaningful name, for example, maven-repo.
Find {M2_HOME}\conf\setting.xml, update localRepository to something else.
{M2_HOME}\conf\setting.xml

<settings>
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ~/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
 
<localRepository>D:/maven_repo</localRepository>

2. Saved it

Done, your new Maven local repository is now changed to D:/maven_repo.

2. Saved it

Done, your new Maven local repository is now changed to D:/maven_repo.

Four simple reasons why Automation projects fail

Automated testing tools were supposed to make things easier. Getting them to execute pre-scripted tests — instead of relying on QA pros to carry out tests by hand — saves time and money. Moving to automated testing is a no-brainer, right?
In theory, the case for automated testing tools makes sense. And yet, in years of writing about software testing, I haven’t heard a single test manager say that automation saves time and money and boosts software quality.
What I hear over and over again are variants on the same theme: Test automation projects are far more challenging than they initially appear. They require scripting skills, which some testers lack. And while the initial stage of setting up tools and writing test scripts is the most demanding phase of an automation project, the most successful projects never really go on autopilot. They are never done.
Don’t get me wrong, I am not building a case against automated testing. Nor am I saying that automation doesn’t make sense for the long run. Virtually all QA pros I talk to believe it does, and they also say there is a certain inevitability about making the move to automation. Certain tests are better left to computers rather than to human testers.
In this installment of Quality Time, I discuss four reasons why automated testing projects are challenging. Understanding these challenges can help QA managers avoid some common pitfalls, accurately assess their readiness for automated testing and set more realistic expectations for upcoming projects.

Reason 1: Test automation projects are software development projects.
 Failure to fully grasp this notion is a recipe for disaster. You can’t set up automated testing tools without team members who can write code. As Lisa Crispin, a resident SearchSoftwareQuality expert, explained in her tip on devising a test automation strategy, “automating tests is software development. It must be done with the same care and thought that goes into writing production code.”
This poses a significant hurdle for testers who lack coding skills. That challenge is best met by mastering those skills, not by shying away from projects that demand them. “Learn how to script tests — learn a scripting language like Ruby,” Coveros CEO Jeff Payne said, addressing an audience of software testers at STAREAST 2013 earlier this year. Companies are looking for testers who can automate, and those without coding skills will ultimately be left behind, he said.

Reason 2: You can’t succeed at automated testing until you succeed at manual testing.
The success of any test project, manual or automated, ultimately hinges on testing the set of things most likely to deliver the highest-quality software to the user. If you don’t know what to test, you are not ready to automate the testing process, according to expert Mike Kelly, in our story, When to use manual vs. automated software testing tools: “I see a lot of teams focus on automation, as a cost-lowering technique, when what they really need to focus on first is testing the right things.”
Kelly’s commonsense rule reminds me of a rule art students are often asked to follow in painting 101: No abstract paintings until you prove your ability to paint realistically. In other words, don’t tackle the variation on the theme until you have mastered the theme itself.

Reason 3: Test automation does not mean testing with automation added.
A key misconception about test automation is that it’s easy, said test expert Hans Buwalda, addressing an audience of software testers in the “Lightning Strikes the Keynotes” session at STAREAST 2013. “But I am still waiting for my easy project,” said Buwalda, chief technology officer for software testing service firm LogiGear in San Mateo, Calif. He believes automated testing is harder than manual testing. You can’t simply add automated tests to an existing test process. Instead, you have to rethink your entire approach. Which tests are best automated? Which ones should remain manual? Answering those questions requires creative thinking, he said. “Don’t lose your creativity [when you move to automated testing],” he told the audience.

Reason 4: Avoid automated testing autopilot.

When teams successfully complete the initial stage of setting up automated testing, there is a tendency to keep on running the same tests over and over again. Test expert Robert Galen of RGalen Consulting Group in North Carolina, said this is a big mistake. Running more tests faster does not result in higher-quality software. Better software is the result of running the right tests and continually re-evaluating which tests are the right ones, Galen explained in our story, Test automation ROI commoditizes testers, hurts test organizations.
In other words, the most successful automated testing projects are never complete. You keep on asking which tests will help produce the best software, and then script them accordingly. This approach helps ensure success with automated testing tools. But when you start running the same old tests in autopilot mode, trouble lies ahead.



Code to Restart and Shutdown the System in QTP

strComputer = "dscp xxxxx“         ' Mention machine name / IP address
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOperatingSystem In colOperatingSystems
    objOperatingSystem.Reboot()
//objOperatingSystem.Win32Shutdown(1)    ‘ “1” is for Shut Down -->for shudowning

Next

Code To Know Complete System Information In QTP

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
                        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
           
Set colSettings = objWMIService.ExecQuery _
                        ("Select * from Win32_OperatingSystem")
           
For Each objOperatingSystem in colSettings
            Msgbox "OS Name: " & objOperatingSystem.Name
            Msgbox "Version: " & objOperatingSystem.Version
            Msgbox "Service Pack: " & _
                                    objOperatingSystem.ServicePackMajorVersion _
                                                & "." & objOperatingSystem.ServicePackMinorVersion
            Msgbox "OS Manufacturer: " & objOperatingSystem.Manufacturer
            Msgbox "Windows Directory: " & _
                                    objOperatingSystem.WindowsDirectory
            Msgbox "Locale: " & objOperatingSystem.Locale
            Msgbox "Available Physical Memory: " & _
                                    objOperatingSystem.FreePhysicalMemory
            Msgbox "Total Virtual Memory: " & _
                                    objOperatingSystem.TotalVirtualMemorySize
            Msgbox "Available Virtual Memory: " & _
                                    objOperatingSystem.FreeVirtualMemory
            Msgbox "Size stored in paging files: " & _
                                    objOperatingSystem.SizeStoredInPagingFiles
Next
           
Set colSettings = objWMIService.ExecQuery _
                        ("Select * from Win32_ComputerSystem")
           
For Each objComputer in colSettings
            Msgbox "System Name: " & objComputer.Name
            Msgbox "System Manufacturer: " & objComputer.Manufacturer
            Msgbox "System Model: " & objComputer.Model
            Msgbox "Time Zone: " & objComputer.CurrentTimeZone
            Msgbox "Total Physical Memory: " & _
                                    objComputer.TotalPhysicalMemory
Next
           
Set colSettings = objWMIService.ExecQuery _
                        ("Select * from Win32_Processor")
           


For Each objProcessor in colSettings
            Msgbox "System Type: " & objProcessor.Architecture
            Msgbox "Processor: " & objProcessor.Description
Next
           
Set colSettings = objWMIService.ExecQuery _
                        ("Select * from Win32_BIOS")
           
For Each objBIOS in colSettings
            Msgbox "BIOS Version: " & objBIOS.Version
Next