Selenium Grid Questions
Question 91:
How do I cut down text execution time for my selenium tests? I want
to execute my tests on a combination of different machines and
browsers.
Answer
Selenium grid is your friendJ. Selenium grid lets you distribute tests across browsers and machines of your choice.
Question 92:
How does Selenium grid works?
Answer
Selenium grid uses combination of Selenium RC servers to execute
tests in multiple browsers on different machine. Herein one Selenium RC
server works as hub while other RC servers work as slaves, which could
be controlled by hub. Whenever there is a request for a specific
configuration for test execution then hub looks for a free RC slave
server and if available then test execution begins on it. Once test
execution is over then RC slave server would be available for next set
of test execution.
Question 93:
Can you show me one diagram which describes functionality of Selenium grid?
Answer
In the following diagram Selenium hub is controlling three Selenium RC servers which are running for configurations –
· IE on Windows
· FF on Linux
· FF on windows
Question 94:
Which jar files are needed to works with Selenium GRID?
Answer
You need to download and add following jar files to your Selenium set up to be able to work with Selenium. These jar files are –
· selenium-grid-remote-control-standalone-.jar
· selenium-grid-hub-standalone-.jar
· selenium-grid-tools-standalone-.jar
Question 95:
How do I start Selenium Grid hub from my machine?
Answer
You should have “ant” set up on your system to be able to work with
Grid. Once you have downloaded Selenium Grid, navigate to its
distribution directory and execute following command -
ant launch-hub
This would start grid hub on port 4444 locally. You can verify this by navigating to following URL – http://localhost:4444/console
Question 96:
How do I start Selenium Grid Slave Server from my system?
Answer
Navigate to download directory of Selenium gird and execute following command –
ant launch-remote-control
This would launch remote control server at port 555. At this point if you navigate to http://localhost:4444/console then you would see this remote control listed under “Available Remote Controls”
Question 97:
How do I start Selenium grid slave on a different port than 5555?
Answer
You can use option “-Dport” followed by port number to start grid slave on a specific port.
ant -Dport=1111 launch-remote-control
ant -Dport=2222 launch-remote-control
Question 98:
How do I start grid RC slaves on a different system than my local
host so than hub could control and contact a specific configuration?
Answer
You should specify following configuration while starting RC slave –
ant -Dport= -Dhost= -DhubURL= launch-remote-control
Herein “hostname” is the host where RC slave is running and “hub url” is URL of machine where grid hub is running.
Question 99:
How do I specify an environment while starting grid slave machine?
Answer
You could specify an environment using “-Denvironment” while starting a slave machine.
ant -Denvironment=”Safari on Mac” launch-remote-control
Herein Safari on Mac is the environment which would be used to recognize configuration of RC slave.
Question 100:
How do I use machine specific configuration in my Selenium tests?
Answer
You could specify machine specific configuration while instantiating Selenium as –
Selenium = new DefaultSelenium(“localhost”, 4444, **’Safari on Mac’**, ‘http://yahoo.com’);
And then you use this selenium instance to carryout operation on your web application.
Question 101:
But how does my tests know that ‘Safari on Mac’ mean a safari
browser? How does mapping between names like ‘Safari on Mac’ and
original browser options available in Selenium work?
Answer
Selenium grid uses a file called “grid_configuration.yml” which
defines configurations of all browsers. You would have to add this in
your project. This file looks like –
Question 102:
How does Selenium grid hub keeps in touch with RC slave machine?
Answer
Selenium grid hub keeps polling all RC slaves at predefined time to
make sure they are available for testing. If not then Selenium hub
disconnect any unavailable RC slaves and makes it clear that any RC
slave is not available for testing. The deciding parameter is called –
“remoteControlPollingIntervalInSeconds” and is defined in
“grid_configuration.yml” file.
Question 103:
My RC becomes unresponsive at times and my Selenium grid hub keeps
waiting for RC slave to respondL. How do I let hub know to give up on RC
slave after a certain time?
Answer
You could state Selenium grid hub to wait for RC slave for a
predefined time, and if RC slave does not responds with in this time
then hub disconnects test execution on that slave. This parameter is
called “sessionMaxIdleTimeInSeconds” and this parameter can be defined
in “grid_configuration.yml” file.
Question 104:
What if my hub goes down while Selenium RC slaves are up and running?
Answer
There is one heart beat mechanism from RC slave to hub which is
reciprocal to mechanism used by hub to slave machines. RC slaves use a
parameter called “hubPollerIntervalInSeconds” to keep track of running
grid hub. This parameter can be defined while starting the hub as –
ant -DhubPollerIntervalInSeconds= launch-hub
if hub does not respond within this time then RC slaves deregister themselves from hub.
Question 105:
Can Selenium grid be used for performance testing?
Answer
Selenium grid is for functional testing of application across
different configuration. Performance testing is usually not carried out
on actual devices but on a simulated http request/response mechanism. If
you want to use Selenium Grid for performance testing then you would
have to invest heavily on s/w and h/w infrastructure.
Question 106:
Are there additional logs available while working with Selenium grid?
Answer
You can find Selenium grid hub logs in “log/hub.log” and Remote Control logs in “log/rc-*.log” folder.
Question 107:
There are various options available while starting a Selenium server, how do I use them with Selenium grid?
Answer
You can use “
seleniumArgs” Java property while
launching the remote control and specify any of the option which you
would with normal Selenium set up. For example you can run Selenium RC
slave in single window mode using following command –
ant -DseleniumArgs=”-singleWindow -debug” launch-remote-control
Question 108:
I see duplicate entries in my hub console, same RC slave listed more than once :-O
Answer
This is because you are killing RC slave very ferociously. For
example you if you just close the console without actually ending the
process in more civil manner. To avoid this you should kill all RC
slaves in more civil manner. If you encounter this error then you should
restart Selenium hub and RC slaves would them register themselves to
hub.
Question 109:
How do I specify my corporate proxy while starting Selenium grid hub or slave machines?
Answer
You could use setting for “http.proxyHost” abd “http.proxyPort” while starting hub and remote control machines –
ant -Dhttp.proxyHost= -Dhttp.proxyPort= launch-hub
ant -Dhttp.proxyHost= -Dhttp.proxyPort= launch-remote-control
Question 110:
How do I use Selenium Grid while using Java, .Net or Ruby
Answer
With java you can take advantage of parallel testing capabilities of TestNG to drive your Selenium grid tests
With .Net you can use “Gallio” to execute your tests in parallel
With Ruby you can use “DeepTest” to distribute your tests
Question 111:
How about the test report when I use Selenium grid for test execution?
Answer
This entirely boils down to framework you use to write your tests. For example in case of java, TestNG reports should suffice.
Web Driver (Selenium 2.0) Questions
Question 112:
What is Selenium 2.0? I have heard this buzz word many times.
Answer
Selenium 2.0 is consolidation of two web testing tools – Selenium
RC and WebDriver, which claims to give best of both words – Selenium and
WebDriver. Selenium 2.0 was officially released only of late.
Question 113:
Why are two tools being combined as Selenium 2.0, what’s the gain?
Answer
Selenium 2.0 promises to give much cleaner API then Selenium RC and
at the same time not being restricted by java script Security
restriction like same origin policy, which have been haunting Selenium
from long. Selenium 2.0 also does not warrant you to use Selenium
Server.
Question 114:
So everyone is going to use Selenium 2.0?
Answer
Well no, for example if you are using Selenium Perl client driver
than there is no similar offering from Selenium 2.0 and you would have
to stick to Selenium 1.0 till there is similar library available for
Selenium 2.0
Question 115:
So how do I specify my browser configurations with Selenium 2.0?
Answer
Selenium 2.0 offers following browser/mobile configuration –
· AndroidDriver,
· ChromeDriver,
· EventFiringWebDriver,
· FirefoxDriver,
· HtmlUnitDriver,
· InternetExplorerDriver,
· IPhoneDriver,
· IPhoneSimulatorDriver,
· RemoteWebDriver
And all of them have been implemented from interface WebDriver. To
be able to use any of these drivers you need to instantiate their
corresponding class.
Question 116:
How is Selenium 2.0 configuration different than Selenium 1.0?
Answer
In case of Selenium 1.0 you need Selenium jar file pertaining to
one library for example in case of java you need java client driver and
also Selenium server jar file. While with Selenium 2.0 you need language
binding (i.e. java, C# etc) and Selenium server jar if you are
using Remote Control or Remote WebDriver.
Question 117:
Can you show me one code example of setting Selenium 2.0?
Answer
Here is java example of initializing firefox driver and using Google Search engine –
protected WebDriver webDriver;
//@BeforeClass(alwaysRun=true)
public void startDriver(){
webDriver = new FirefoxDriver();
// Get Google search page and perform search on term “Test”
webDriver.get(“http://www.google.com”);
webDriver.findElement(By.name(“q”)).sendKeys(“Test”);
webDriver.findElement(By.name(“btnG”)).click();
Question 118:
Which web driver implementation is fastest?
Answer
HTMLUnitDriver. Simple reason is HTMLUnitDriver does not execute
tests on browser but plain http request – response which is far quick
than launching a browser and executing tests. But then you may like to
execute tests on a real browser than something running behind the scenes
Question 119:
What all different element locators are available with Selenium 2.0?
Answer
Selenium 2.0 uses same set of locators which are used by Selenium
1.0 – id, name, css, XPath but how Selenium 2.0 accesses them is
different. In case of Selenium 1.0 you don’t have to specify a different
method for each locator while in case of Selenium 2.0 there is a
different method available to use a different element locator. Selenium
2.0 uses following method to access elements with id, name, css and
XPath locator –
driver.findElement(By.id(“HTMLid”));
driver.findElement(By.name(“HTMLname”));
driver.findElement(By.cssSelector(“cssLocator”));
driver.findElement(By.xpath(“XPathLocator));
Question 120:
How do I submit a form using Selenium?
Answer
You can use “submit” method on element to submit form –
element.submit();
Alternatively you can use click method on the element which does form submission.
Question 121:
Can I simulate pressing key board keys using Selenium 2.0?
Answer
You can use “sendKeys” command to simulate key board keys as –
element.sendKeys(” and some”, Keys.ARROW_UP);
You can also use “sendKeys” to type in text box as –
HTMLelement.sendKeys(“testData”);
Question 122:
How do I clear content of a text box in Selenium 2.0
Answer
You can use “clear” method on text box element to clear its content –
textBoxElement.clear();
Question 123:
How do I select a drop down value using Selenium2.0?
Answer
To select a drop down value, you first need to get the select
element using one of element locator and then you can select element
using visible text –
Select selectElement = new Select(driver.findElement(By.cssSelector(“cssSelector”)));
selectElement.selectByVisibleText(“India”);
Question 124:
What are offering to deal with popup windows while using Selenium 2.0?
Answer
You can use “switchTo” window method to switch to a window using
window name. There is also one method “getWindowHandles” which could be
used to find all Window handles and subsequently bring control on
desired window using window handle –
webDriver.switchTo().window(“windowName”);
for (String handle : driver.getWindowHandles()) {
driver.switchTo().window(handle);
}
Question 125:
How about handling frames using Selenium 2.0?
Answer
You can use “switchTo” frame method to bring control on an HTML frame –
driver.switchTo().frame(“frameName”);
You can also use index number to specify a frame –
driver.switchTo().frame(“parentFrame.4.frameName”);
This would bring control on frame named – “frameName” of the 4th sub frame names “parentFrame”
Question 126:
Can I navigate back and forth in a browser in Selenium 2.0?
Answer
You can use Navigate interface to go back and forth in a page.
Navigate method of WebDriver interface returns instance of Navigation.
Navigate interface has methods to move back, forward as well as to
refresh a page –
driver.navigate().forward(); driver.navigate().back(); driver.navigate().refresh();
Question 127:
What is the order of fastest browser implementation for WebDriver?
Answer
HTMLUnitDriver is the fastest browser implementation as it does not involves interaction with a browser, This is followed by Firefox driver and then IE driver which is slower than FF driver and runs only on Windows.
Question 128:
Is it possible to use Selenium RC API with Selenium 2.0?
Answer
You can emulate Selenium 1.0 API with Selenium 2.0 but not all of Selenium 1.0 methods are supported. To achieve this you need to get Selenium instance from WebDriver and use Selenium methods. Method executions might also be slower while simulating Selenium 1.0 with in Selenium 2.0
Question 129:
Can you show me one example of using Selenium 1.0 in Selenium 2.0?
Answer
Code Sample:
// Create web driver instance
WebDriver driver = new FirefoxDriver();
// App URL
String appUrl = ”http://www.google.com”;
// Get Selenium instance
Selenium selenium = new WebDriverBackedSelenium(driver, appUrl);
// Tests using selenium
selenium.open(appURL);
selenium.type(“name=q”, ”testData”);
selenium.click(“name=btnG”);
// Get back the WebDriver instance
WebDriver driverInstance = ((WebDriverBackedSelenium) selenium).getUnderlyingWebDriver();
Question 130:
I had support of lots of browsers while using Selenium 1.0 and it
seems lacking with Selenium 2.0, for example how do I use <
awesome> browser while using Selenium 2.0?
Answer
There is a class called Capabilities which lets you inject new
Capabilities in WebDriver. This class can be used to set testing browser
as Safari –
//Instantiate Capabilities
Capabilities capabilities = new DesiredCapabilities()
//Set browser name
capabilities.setBrowserName(“this awesome browser”);
//Get your browser execution capabilities
CommandExecutor executor = new SeleneseCommandExecutor(“http:localhost:4444/”, “http://www.google.com/”, capabilities);
//Setup driver instance with desired Capabilities
WebDriver driver = new RemoteWebDriver(executor, capabilities);
Question 131:
Are there any limitations while injecting capabilities in WebDriver
to perform tests on a browser which is not supported by WebDriver?
Answer
Major limitation of injecting Capabilities is that “fundElement”
command may not work as expected. This is because WebDriver uses
Selenium Core to make “Capability injection” work which is limited by
java script security policies.
Question 132:
Can I change User-Agent while using FF browser? I want to execute my tests with a specific User-Agent setting.
Answer
You can create FF profile and add additional Preferences to it.
Then this profile could be passed to Firefox driver while creating
instance of Firefox –
FirefoxProfile profile = new FirefoxProfile();
profile.addAdditionalPreference(“general.useragent.override”, ”User Agent String”);
WebDriver driver = new FirefoxDriver(profile);
Question 133:
Is there any difference in XPath implementation in different WebDriver implementations?
Answer
Since not all browsers (like IE) have support for native XPath,
WebDriver provides its own implementation for XPath for such browsers.
In case of HTMLUnitDriver and IEDriver, html tags and attributes names
are considered lower cased while in case of FF driver they are
considered case in-sensitive.
Question 134:
My application uses ajax highly and my tests are suffering from time outs while using Selenium 2.0L.
Answer
You can state WebDriver to implicitly wait for presence of Element
if they are not available instantly. By default this setting is set to
0. Once set, this value stays till the life span of WebDriver object.
Following example would wait for 60 seconds before throwing
ElementNotFound exception –
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
WebElement element = driver.findElement(By.id(“elementID”));
Question 135:
What if I don’t want to use implicit wait and want to wait only for presence of certain elements?
Answer
You can use explicit wait in this situation to wait for presence of
certain element before continuing with test execution. You can use
“WebDriverWait” and “ExpectedCondition” to achieve this –
WebDriver driver = new FirefoxDriver();
WebElement myDynamicElement = (new WebDriverWait(driver, 60)).until(new ExpectedCondition<WebElement>(){
@Override
public WebElement apply(WebDriver d) {
return d.findElement(By.id(“myDynamicElement”));
}});
This is going to wait up to 60 seconds before throwing ElementNotFound exception.
Question 136:
What is RemoteWebDriver? When would I have to use it?
Answer
RemoteWebDriver is needed when you want to use HTMLUnitDriver.
Since HTMLUnitDriver runs in memory, you would not see a browser getting
launched –
// Create HTMLUnitDriver instance
WebDriver driver = new HtmlUnitDriver();
// Launch Yahoo.com
driver.get(“http://www.yahoo.com”);
Question 137:
What all languages available to be used with WebDriver?
Answer
Java and C# are on the forefront of WebDriver languages. Support is
also available for Python and Ruby. There is also one java script
library available for Friefox.
Question 138:
How do I handle java script alert using WebDriver?
Answer
WebDriver would support handling js alerts using Alert interface.
// Bring control on already opened alert
Alert alert = driver.switchTo().alert();
// Get the text of the alert or prompt
alert.getText();
// Click ok on alert
alert.accept();
Question 139:
Could I safely execute multiple instances of WebDriver implementations?
Answer
As far as HTMLUnitDriver and FF drivers are concerned, each
instance would be independent of other. In case of IE driver there could
be only one instance of IE driver running on Windows. If you want to
execute more than one instance of IE driver then you should consider
using RemoteWebDriver and virtual machines.
Question 140:
Is it possible to interact with hidden elements using WebDriver?
Answer
Since WebDriver tries to exercise browser as closely as real users
would, hence simple answer is No, But you can use java script execution
capabilities to interact with hidden elements.
Question 141:
I have all my tests written in Selenium 1.0 (Selenium RC), why should I migrate to Selenium 2.0 (WebDriver)?
Answer
Because –
· WebDriver has more compact and object oriented API than Selenium 1.0
· WebDriver simulates user behaviour more closely than
Selenium 1.0, for example if a text box is disabled WebDriver would not
be able to type text in it while Selenium 1.0 would be
· WebDriver is supported by Browser vendor themselves i.e. FF, Opera, Chrome etc
Question 142:
My XPath and CSS locators don’t always work with Selenium 2.0, but they used to with Selenium 1.0L.
Answer
In case of XPath, it is because WebDriver uses native browser
methods unless it is not available. And this cause complex XPath to be
broken. In case of Selenium 1.0 css selectors are implemented using
Sizzle Library and not all the capabilities like “contains” are
available to be used with Selenium 2.0
Question 143:
How do I execute Java Script in Selenium 2.0?
Answer
You need to use JavaScriptExecutor to execute java script in
Selenium 2.0, For example if you want to find tag name of an element
using Selenium 2.0 then you can execute java script as following –
WebElement element = driver.findElement(By.id(“elementLocator”));
String name = (String) ((JavascriptExecutor) driver).executeScript(
”return arguments[0].tagName”, element);
Question 144:
Why does not my java script execution return any value?
Answer
This might happen when you forget to add “return“ keyword while
executing java script. Notice the “return” keyword in following
statement –
((JavascriptExecutor) driver).executeScript(“return window.title;”);
Question 145:
Are there any limitations from operating systems while using WebDriver?
Answer
While HTMLUnitDriver, FF Driver and Chrome Driver could be used on
all operating systems, IE Driver could be used only with Windows.
Question 146:
Give me architectural overview of WebDriver.
Answer
WebDriver tries to simulate real user interaction as much as
possible. This is the reason why WebDriver does not have “fireEvent”
method and “getText” returns the text as a real user would see it.
WebDriver implementation for a browser is driven by the language which
is best to driver it. In case of FF best fit languages are Javascript in
an XPCOM component and in IE it is C++ using IE automation. Now the
implementation which is available to user is a thin wrapper around the
implementation and user need not know about implementation.
Question 147:
What is Remote WebDriver Server?
Answer
Remote WebDriver Server has two components – client and server.
Client is WebDriver while Server is java servlet. Once you have
downloaded selenium-server-standalone-.jar file you can start it from
command line as –
java -jar selenium-server-standalone-<version-number>.jar
Question 148:
Is there a way to start Remote WebDriver Server from my code?
Answer
First add Remote WebDriver jar in your class path. You also need
another server called “Jetty” to use it. You can start sever as
following –
WebAppContext context = new WebAppContext();
context.setContextPath(“”);
context.setWar(new File(“.”));
server.addHandler(context);
context.addServlet(DriverServlet.class, ”/wd/*”);
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(3001);
server.addConnector(connector);
server.start();
Question 149:
But what are the advantages of using Remote WebDriver over WebDriver?
Answer
You can use Remote WebDriver when –
· When you want to execute tests on a browser not available to you locally
· Introduction to extra latency to tests
But there is one disadvantage of using Remote WebDriver that you would need external servlet container.
Question 150:
Can you show me code example of using Remote WebDriver?
Answer
// Any driver could be used for test
DesiredCapabilities capabilities = new DesiredCapabilities();
// Enable javascript support
capabilities.setJavascriptEnabled(true);
// Get driver handle
WebDriver driver = new RemoteWebDriver(capabilities);
// Launch the app
driver.get(“http://www.google.com”);
Question 151:
What are the modes of Remote WebDriver
Answer
Remote WebDriver has two modes of operations –
Client Mode: This is where language bindings connect to remote instance. FF drive and RemoteWebDriver clients work this way.
Server Mode: In this mode language bindings set up the server. ChromeDriver works this way.
Question 152:
What Design Patterns could be used while using Selenium 2.0?
Answer
These three Design Patterns are very popular while writing Selenium 2.0 tests –
1. Page Objects – which abstracts UI of web page
2. Domain Specific Language – which tries to write tests which
could be understood by a normal user having no technical knowledge
3. Bot Style Tests – it follows “command-like” test scripting
Question 153:
So do I need to follow these Design patterns while writing my tests?
Answer
Not at all, these Design Patterns are considered best practices and
you can write you tests without following any of those Design Patterns,
or you may follow a Design Pattern which suites your needs most.
Question 154:
Is there a way to enable java script while using HTMLUnitDriver?
Answer
Use this –
HtmlUnitDriver driver = new HtmlUnitDriver();
driver.setJavascriptEnabled(true);
or this –
HtmlUnitDriver driver = new HtmlUnitDriver(true);
Question 155:
Is it possible to emulate a browser with HTMLUnitDriver?
Answer
You can emulate browser while using HTMLUnitDriver but it is not
recommended as applications are coded irrespective of browser you use.
You could emulate Firefox 3 browser with HTMLUnitDriver as –
HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_3);
Or you can inject desired capabilities while instantiating HTMLUnitDriver as –
HtmlUnitDriver driver = new HtmlUnitDriver(capabilities);
Question 156:
How do I use iPhone Driver?
Answer
You should start iPhone SDK and build iPhone driver. Down load
iPhone development tools and provision profile. Now iPhone driver can
connect through HTTP to the iphone simulator. You can also run simulator
on another machine in your network and WebDriver could connect to it
remotely.
Question 157:
Is it possible to convert Selenium IDE test to WebDriver test?
Answer
For now there is no
formatter available to convert Selenium IDE tests to corresponding
WebDriver tests, hence simple answer is No. Yes WebDriver style of code can be generated from Selenium IDE
Question 158:
Can WebDriver handle UntrustedSSLCertificates?
Answer
This feature is currently supported in Firefox browser and is awaiting implementation in IE and Chrome drivers.
Question 159:
Can I carry out multiple operations at once while using WebDriver?
Answer
You can use Builder pattern to achieve this. For example if you
want to move an element from one place to another you can use this –
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(element)
.moveToElement(otherElement)
.release(otherElement)
.build();
dragAndDrop.perform();
Question 160:
How do I simulate keyboard keys using WebDriver?
Answer
There is a KeyBoard interface which has three methods to support keyboard interaction –
- sendKeys(CharSequence)- Sends character sequence
- pressKey(Keys keyToPress) – Sends a key press without releasing it.
- releaseKey(Keys keyToRelease) – Releases a modifier key
Question 161:
What about Mouse Interaction?
Answer
Mouse interface lets you carry out following operations –
- click(WebElement element) – Clicks an element
- doubleClick(WebElement element) – Double-clicks an element.
- void mouseDown(WebElement element) – Holds down the left mouse button on an element.
- mouseUp(WebElement element) – Releases the mouse button on an element.
- mouseMove(WebElement element) – Moves element form current location to another element.
- contextClick(WebElement element) – Performs a context-click (right click) on an element.
Question 162:
How does Android Webdriver works?
Answer
Android WebDriver uses Remote WebDriver. Client Side is test code
and Server side is application installed on android emulator or actual
device. Here client and server communicate using JSON wire protocol
consisting of Rest requests.
Question 163:
What are the advantages of using Android WebDriver?
Answer
Android web driver runs on Android browser which is best real user
interaction. It also uses native touch events to emulated user
interaction.
But there are some drawbacks also like, it is slower than headless
WebKit driver. XPath is not natively supported in Android web view.
Question 164:
Is there a built-in DSL (domain specific language) support available in WebDriver?
Answer
There is not, but you can easily build your own DSL, for example instead of using –
webDriver.findElement(By.name(“q”)).sendKeys(“Test”);
You can create a more composite method and use it –
public static void findElementAndType(WebDriver webDriver, String elementLocator, String testData) {
webDriver.findElement(By.name(elementLocator)).sendKeys(testData);
}
And now you just need to call method findElementAndType to do type operation.
Question 165:
What is grid2?
Answer
Grid2 is Selenium grid for Selenium 1 as well as WebDriver, This allows to –
· Execute tests on parallel on different machines
· Managing multiple environments from one point
Question 166:
How do I start hub and slaves machines in grid 2?
Answer
Navigate to you selenium server standalone jar download and execute following command –
java -jar selenium-server-standalone-.jar -role hub And you start Slave machine by executing following command – Java –jar selenium-server-.jar –role webdriver -hub http://localhost:4444/grid/register -port 6666
Question 167:
And how do I run tests on grid?
Answer
You need to use the RemoteWebDriver and the DesiredCapabilities object to define browser, version and platform for testing. Create Targeted browser capabilities as –
DesiredCapabilities capability = DesiredCapabilities.firefox();
Now pass capabilities to Remote WebDriver object –
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
Following this, hub will take care of assigning tests to a slave machine
Question 168:
What parameters can be passed to grid2?
Answer
You can pass following parameters to grid 2 –
- -port 4444 (default 4444)
- -nodeTimeout (default 30) the timeout in seconds before the hub automatically releases a node that hasn’t received any requests for more than the specified number of seconds.
- -maxConcurrent 5 (5 is default) The maximum number of browsers that can run in parallel on the node.
Selenium Tool Implementation Misc Questions
Question 169:
How do I implement data driven testing using Selenium?
Answer
Selenium, unlike others commercial tools does not have any direct
support for data driven testing. Your programming language would help
you achieving this. You can you jxl library in case of java to read and
write data from excel file. You can also use Data Driven Capabilities of
TestNG to do data driven testing.
Question 170:
What is equivalent to test step, test scenario and test suite in Selenium.
Answer
If you are using Java client driver of Selenium then TestNG test
method could be considered equivalent to test step, a test tag could be
considered as test scenario and a suite tag could be considered
equivalent to a test suite.
Question 171:
How do I get attribute value of an element in Selenium?
Answer
You could use getAttribute method
With Selenium 1.0 –
String var = selenium.getAttribute("css=input[name='q']@maxlength");
System.out.println(var);
With Selenium 2.0 –
String var = webDriver.findElement(By.cssSelector("input[name='q']")).getAttribute("maxlength")
System.out.println(var);
Question 172:
How do I do database testing using Selenium?
Answer
Selenium does not support database testing but your language
binding does. For example while using java client driver you can use
java data base connectivity (jdbc) to establish connection to data base,
fetch/write data to data base and doing data comparison with front end.
Question 173:
I completed test execution and now I want to email test report.
Answer
If you are using “ant” build tool then you can use “mail” task to
deliver your test results. Similar capabilities are available in
Continuous Build Integration tools like – Hudson.
Question 174:
How do I make my tests more comprehensible?
Answer
Selenium tests which are written as –
selenium.click("addForm:_ID74:_ID75:0:_ID79:0:box”);
Make it tough to understand the element which is being exercised upon.
Instead of hard coding element locator in tests you should
externalize them. For example with java you can use properties file to
contain element locators and then locator reference is given in test
script. Following this approach previous test step would look as –
selenium.click(PolicyCheckbox);
And this is far more comprehensible.
Question 175:
Why should I use Page Object?
Answer
Page object is a design pattern which distinguishes the code
carrying out operations on page and code which carries out tests
(assertion/verification). While implementing page object you abstract
functioning of a page or part of it in a dedicated “Classs” which is
then used by test script to perform actions on page and reach a stage
when actual test could be performed.
Advantage of using page object is the fact that if application lay
out changes then you only need to modify the navigation part and test
would function intact.
No comments:
Post a Comment