Question 1:
What is Selenium RC
(also known as Selenium 1.0)?
Answer
Selenium RC is an
offering from SeleniumHQ which tries to overcome following draw backs of
Selenium IDE –
·
Able to execute tests
only with Firefox
·
Not able to use
full-fledged programming language and being limited to Selenese
Question 2:
What are the main
components of Selenium RC?
Answer
Selenium RC has two
primary components –
·
Client libraries which
let you writes tests in language of your preference i.e. java, C#, perl, php
etc
·
Selenium sever which
acts as a proxy between browser and application under test (aut)
Question 3:
Why do I need Selenium
Server?
Answer
Selenium uses java
script to drives tests on a browser; Selenium injects its own js to the
response which is returned from aut. But there is a java script security
restriction (same origin policy) which lets you modify html of
page using js only if js also originates from the same domain as html. This
security restriction is of utmost important but spoils the working of Selenium.
This is where Selenium server comes to play an important role.
Selenium server stands
between aut and browser and injects selenium js to the response received from
aut and then it is delivered to broswer. Hence browser believes that entire
response was delivered from aut.
Question 4:
What is Selenium core? I
have never used it!!!
Answer
Selenium core is the
core js engine of Selenium which executes tests on browser, but because of same
origin policy it needs to be deployed on app server itself, which is not always
feasible. Hence Selenium core is not used in isolation. Selenium IDE as well as
Selenium RC use Selenium core to drive tests while over coming same origin
policy. In case of Selenium IDE tests are run in context of browser hence it is
not hindered by same origin policy and with Selenium RC, Selenium Server over
comes same origin policy.
Question 5:
Where is executable for
Selenium RC, how do I install it?
Answer
Installation is a
misnomer for Selenium RC. You don’t install Selenium RC you only add client
libraries to you project. For example in case of java you add client driver and
Selenium server jars in Eclipse or IntelliJ which are java editors.
Question 6:
I have downloaded
Selenium Server and Client libraries, how do I start Selenium Server?
Answer
To start Selenium
Server, you need to navigate to installation directory of Selenium server and
execute following command –
Java -jar .jar
This will start Selenium
server at port 4444 by default.
Notice that you need to
have java version 1.5 or higher available on your system to be able to use Selenium
server.
Question 7:
On my machine port 4444
is not freeL . How do Use
another port?
Answer
You can specify port
while running the selenium server as –
Java -jar .jar
–port 5555
Question 8:
I am new to programming;
can Selenium generate sample code from my Selenese scripts?
Answer
You can first record
tests in Selenium IDE and then use format option to convert them in a language
of your choice.
Question 9:
Can I start Selenium
server from my program instead of command line
Answer
If you are using java
then you can start Selenium server using SeleniumServer class. For this you
need to instantiate SeleniumServer and then call start() method on it.
seleniumServer = new SeleniumServer();
seleniumServer.start();
Question 10:
And how do I start the browser?
Answer
While using java you
need to create instance of DefaultSelenium class and pass it four parameters –
selenium = new DefaultSelenium(serverHost,
serverPort, browser, appURL);
selenium.start();
Herein you need to pass,
host where Selenium server
is running,
port of Selenium server,
browser where tests are
to be executed and
application URL
Question 11:
I am not using java to
program my tests, do I still have to install java on my system?
Answer
Yes, since Selenium
server is written in java you need java to be installed on your system to be
able to use it. Even though you might not be using java to program your tests.
Question 12:
What are the browsers
offering from Selenium?
Answer
Following browsers could
be used with Selenium –
*firefox
*firefoxproxy
*pifirefox
*chrome
*iexploreproxy
*iexplore
*firefox3
*safariproxy
*googlechrome
*konqueror
*firefox2
*safari
*piiexplore
*firefoxchrome
*opera
*iehta
*custom
Here pi and proxy stand
for proxy injection mode of Selenium server
Question 13:
During execution of
tests I see two browser windows; one my test application another window shows
commands being executed. Can I limit it to just one window?
Answer
Yes you can instruct
Selenium Server to launch just one window. To do so you must specify –singleWindow
while starting the Selenium server as –
Java -jar .jar
–singleWindow
Question 14:
My tests usually time
outL. Can I specify bigger time out?
Answer
This usually happens
while using open method with Selenium. One way to overcome this is to use
setTimeOut method in your test script another way is to specify time out while
starting Selenium server as following –
Java -jar .jar
–timeout
Question 15:
My system is behind
corporate network, how do I specify my corporate proxy?
Answer
You can specify your
corporate proxy as following while starting Selenium Server –
java -jar .jar
-Dhttp.proxyHost= -Dhttp.proxyPort= -Dhttp.proxyUser= -Dhttp.proxyPassword=
Question 16:
I am switching domains
in my test scripts. I move from “yahoo.com” to “google.com” and my tests
encounter permission denied errorL
Answer
Changing domains is also
a security restriction from java script. To overcome this you should start you
Selenium server in proxy injection mode as –
java -jar .jar
–proxyInjectionMode
Now Selenium server
would act as proxy server for all the content going to test application
Question 17:
Can I execute my
Selenese tests in another browser using Selenium server? I want to use only
Selenese script my tests but still want to execute my test in non firefox
browsers
Answer
Yes you can. To do so
you need to specify following parameters while starting Selenium server –
Browser
Test domain
Path to html suite (you
Selenese tests) and
Path to result
java
-jar <>.jar -htmlSuite
Question 18:
Can I log more options
during test execution?
Answer
If you want to log browser side option during test execution then
you should start Selenium server as following –
java -jar <>.jar
–browserSideLog
Question 19:
Can I use Selenium RC on
my UNIX/Mac also?
Answer
You can use Selenium RC
on any system which is capable I running Java. Hence you can use it on RC and
UNIX machines also
Question 20:
I want to test my
scripts on new experimental browser, how do I do that?
Answer
You can specify *custom
followed by path to browser to execute your tests on any browser while starting
Selenium server
*custom
Question 21:
I executed my tests
cases but where is the test report?
Answer
Selenium RC itself does
not provide any mechanism for test reporting. Test reporting is driven from the
framework you use for Selenium. For example with java client driver of Selenium
–
·
if you are using JUnit
then you can use ant plug-in of JUnit to generate test report
·
if you are using TestNG
then TestNG generates reports for you
Same reporting option is
available with PHP unit and other client libraries you are using.
Question 22:
How do I use recovery
scenarios with Selenium? I used to use them with QTP.
Answer
Power of recovery
scenarios lies with the programming language you use. If you are using java
then you can use Exception handling to overcome same. For example if you are reading
data from a file and file is not available then you should keep you code
statements in “try catch” block so that test execution could continue
even in the wake of errors. Such mechanism entirely boils down the errors you
want to recover from, while being able to continue with test execution.
Question 23:
How do I iterate through
options in my test script.
Answer
You can use loop
features of the programming language, for example you can use “for” loop in
java as following to type different test data in a text box –
// test data collection
in an array
String[] testData = {"test1", "test2", "test3"};
// iterate through each
test data
for (String
s : testData) {
selenium.type(“elementLocator”, testData);
}
Question 24:
Can I execute java
script from my tests? I want to count number of images on my page.
Answer
You can use method
getEval() to evaluate java script. For example if you want to count number of
images then you can pass following dom statement to getEval() as following –
selenium.getEval("window.document.images.length;");
Or to get All anchor
objects from a page
selenium.getEval("window.document.getElementsByTagName(‘a’);");
Question 25:
Is there a way for me to
know all available options when I start Selenium Server?
Answer
If you want to see all
options available while starting Selenium server then you should use option
“-h” while starting Selenium server -
Java –jar .jar –h
It would display you all the options which you
can use while starting the Selenium server.
Question 26:
I have created my own firefox profile; can I execute my test scripts on it
Answer
You may like to create your own firefox profile because Selenium always created a clean firefox profile while executing the tests and none of your FF settings and plug-in are considered with this clean profile. If you want to execute tests on FF with your settings then you should create custom profile for FF.
I have created my own firefox profile; can I execute my test scripts on it
Answer
You may like to create your own firefox profile because Selenium always created a clean firefox profile while executing the tests and none of your FF settings and plug-in are considered with this clean profile. If you want to execute tests on FF with your settings then you should create custom profile for FF.
To be able to execute
tests on a custom firefox profile you should specify its path while starting
Selenium server. For example if your new profile is stored at “awesome
location” in your directory then you should start Selenium server as following
–
Java –jar .jar -firefoxProfileTemplate "awesome location"
Question 27:
How do I capture server
side log from Selenium server?
Answer
Start your Selenium
Server as following –
java -jar .jar -log
selenium.log
And Selenium would start
logging server side info, i.e.
20:44:25 DEBUG [12]
org.openqa.selenium.server.SeleniumDriverResourceHandler -
Browser 12345/:top
frame1 posted START NEW
Question 28:
What are Heightened
Privileges Browsers?
Answer
Firefox and IE have
browser modes which are not restricted by java script’s same origin policy.
These browsers are known as browsers with elevated security privileges. In case
of Firefox it is known as chrome (It’s not the Google browser) and in case of
IE it is known as iehta
Question 29:
My application has lots
of pop up window, how do I work with them?
Answer
You need to know the
Window ID of pop window to be able to work with them.
First you need to bring
control on pop up window; execute selenium commands there, close the pop up
window and then bring control back to main window. Consider following example
where click on an image brings a pop up window –
// click on image brings
pop up window
selenium.click("css=img");
// wait for pop up window identified using
anchor target "ss"
selenium.waitForPopUp("ss",
getWaitPeriod());
selenium.selectWindow("ss");
// Some more operations on popup window
// Close the pop up window and Select the main
application window
// Main window is selected by adding null as
argument
selenium.close();
selenium.selectWindow("null");
// continue with usual operation J
Question 30:
While trying to execute
my tests with firefox I encountered following error – “Firefox Refused Shutdown
While Preparing a Profile”. How do I solve it?
Answer
This message simply
means that Selenium is not able to launch FF browser as it is already running
on your system. To overcome this you should close all running instances of FF
browser.
You should also check
your system process if there is any hidden FF profile running which is not
visible on screen. You should kill all FF processes and following this your
tests should run smooth
Question 31:
While trying to execute
my tests with firefox I encountered following error – “Firefox Refused Shutdown
While Preparing a Profile”. How do I solve it?
Answer
This message simply
means that Selenium is not able to launch FF browser as it is already running
on your system. To overcome this you should close all running instances of FF
browser.
You should also check your system process if
there is any hidden FF profile running which is not visible on screen. You
should kill all FF processes and following this your tests should run smooth
Question 32:
My application uses Ajax
heavily how do I use Selenium RC to work with Ajax operations?
Answer
Ajax operations don’t
reload a page like normal form submission but they make http requests behind
the scene. You cannot use waitForPageToLoad for such operations and instead
should use conditional wait for change in state of application. This could as
well mean waiting for presence of an element before continuing with test
operations. Consider following example in which type operation triggers Ajax
operation which is followed by conditional wait for presence of a text box –
// type operation brings element “q” on screen
without loading the page
selenium.type("elementLocator", "testData");
// conditional wait for element “q”
for (int second = 0;;
second++) {
if (second
>= 60) fail("timeout");
try { if (selenium.isElementPresent("q")) break; } catch (Exception e) {}
Thread.sleep(1000);
}
Question 33:
How do I upload a file
using Selenium? I need to upload a word file during test execution.
Answer
If you are using Firefox
then you can use “type” command to type in a File Input box of upload file. But
type operation does not work with IE and you would have to use “Robot” class in
java to work make file upload work.
Question 34:
Why do I get “permission
denied” error during execution of Selenium tests?
Answer
The primary reason of
permission denied error is same origin policy restriction from java script. To
overcome this error you can use browsers with elevated security privileges. In
case of Firefox you should use *chrome and in case of IE you should use
*iehta as browser for working with Selenium.
Question 35:
I am not able to use
“style” attribute to locate element with IE browserL
Answer
This is because IE
expects attribute values to be in caps while other browsers expect it to be
lower case letters. Hence
//tr[@style="background-color:yellow"]
works with other browsers
//tr[@style="BACKGROUND-COLOUR:yellow"]
works with IE
Question 36:
Are there any technical
limitations while using Selenium RC?
Answer
Besides notorious “same
origin policy” restriction from js, Selenium is also restricted from exercising
anything which is outside browser. For example you cannot click on “Tools”
option of your browser by just using Selenium.
Question 37:
But my tests need me to
exercise objects outside browser, how do I achieve it?
Answer
You can use Robot class
in java to achieve this, but it would be dirty solution even if you get through
this.
Question 38:
Does Selenium have any
offering for mobile browsers?
Answer
Selenium 2.0 (WebDriver)
provides iPhone as well Android drivers which could be used to drive tests on
mobile browsers
Question 39:
How does Selenium RC
stand with other commercial tools?
Answer
The biggest advantage of
Selenium RC is that it is absolutely free and has vast support of languages and
browsers (almost always). Selenium lags when it comes to test reporting as
Selenium does not have any in built reporting but this can be easily achieved
using the programming language you decide to work on with Selenium. A bigger
drawback is not being able to exercise objects which are outside browser
window, for example clicking on folder on your desktop.
Question 40:
How does Selenium RC
stand with other commercial tools?
Answer
The biggest advantage of
Selenium RC is that it is absolutely free and has vast support of languages and
browsers (almost always). Selenium lags when it comes to test reporting as
Selenium does not have any in built reporting but this can be easily achieved
Question 41:
Can I just use Selenium
RC to drive tests on two different browsers on one operating system without
using Selenium Grid?
Answer
If you are using java
client driver of Selenium then java testing framework TestNG lets you achieve
this. You can set tests to be executed in parallel using “parallel=test”
attribute and define two different tests, each using a different browser. Whole
set up would look as (notice the highlighted sections for browser in test
suite)–
xml version="1.0" encoding="utf-8"?>
DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Test Automation" verbose="10">
<parameter name="serverHost" value="localhost" />
<parameter name="appURL" value="http://tamil.yahoo.com"/>
<parameter name="proxyInjection" value="false" />
<parameter name="serverPort" value="4444"/>
<test name="Web Test1">
<parameter name="browser" value="*chrome" />
<parameter name="m" value="1">parameter>
<classes><class name="com.core.tests.TestClass1">class>classes>
test>
<test name="Web Test2">
<parameter name="browser" value="*iehta" />
<parameter name="m" value="2">parameter>
<classes><class name="com.core.tests.TestClass1"><class><classes>
<test>
<suite>
No comments:
Post a Comment