P. 1
Selenium Documentation

Selenium Documentation

|Views: 848|Likes:
Publicado porDivyesh Dave

More info:

Published by: Divyesh Dave on Mar 16, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

04/21/2011

pdf

text

original

If you Google “Selenium RC user-extension” ten times you will find ten different approaches to using
this feature. Below, is the official Selenium suggested approach.

9.6.1 Example

C#

1. Place your user extension in the same directory as your Selenium Server.

2. If you are using client code generated by the Selenium-IDE you will need to make a
couple small edits. First, you will need to create an HttpCommandProcessor object
with class scope (outside the SetupTest method, just below private StringBuilder
verificationErrors;)

HttpCommandProcessor proc;

1. Next, instantiate that HttpCommandProcessor object as you would the
DefaultSelenium object. This can be done in the test setup.

proc = new HttpCommandProcessor( "localhost" , 4444, "*iexplore" , "http://google.ca/" );

9.5. Using User-Extensions With Selenium-IDE

119

Selenium Documentation, Release 1.0

1. InstantiatetheDefaultSeleniumobjectusing theHttpCommandProcessorobjectyou created.

selenium = new DefaultSelenium(proc);

1. Within your test code, execute your user-extension by calling it with the DoCommand() method
of HttpCommandProcessor. This method takes two arguments: a string to identify the user-
extension method you want to use and string array to pass arguments. Notice that the first letter
of your function is lower case, regardless of the capitalization in your user-extension. Selenium
automatically does this to keep common JavaScript naming conventions. Because JavaScript is
case sensitive, your test will fail if you begin this command with a capital. inputParams is the
array of arguments you want to pass to the JavaScript user-extension. In this case there is only
one string in the array because there is only one parameter for our user extension, but a longer
array will map each index to the corresponding user-extension parameter. Remember that user
extensions designed for Selenium-IDE will only take two arguments.

string[] inputParams = { "Hello World" };

proc.DoCommand( "alertWrapper" , inputParams);

1. Start the test server using the -userExtensions argument and pass in your
user-extensinos.js file.

java -jar selenium-server.jar -userExtensions user-extensions.js

using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;

namespace SeleniumTests
{

[TestFixture]

public class NewTest
{

private ISelenium selenium;
private StringBuilder verificationErrors;
private HttpCommandProcessor proc;

[SetUp]
public void SetupTest()
{

proc = new HttpCommandProcessor( "localhost" , 4444, "*iexplore" , "http://google.ca/" );
selenium = new DefaultSelenium(proc);
//selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://google.ca/");
selenium.Start();
verificationErrors = new StringBuilder();

}

120

Chapter 9. User-Extensions

Selenium Documentation, Release 1.0

[TearDown]
public void TeardownTest()
{

try
{

selenium.Stop();

}
catch
(Exception)
{

// Ignore errors if unable to close the browser

}

Assert.AreEqual( "" , verificationErrors.ToString());

}

[Test]
public void TheNewTest()
{

selenium.Open( "/" );

string[] inputParams = { "Hello World" ,};

proc.DoCommand( "alertWrapper" , inputParams);

}

}

}

Appendixes:

9.6. Using User-Extensions With Selenium RC

121

Selenium Documentation, Release 1.0

122

Chapter 9. User-Extensions

CHAPTER

TEN

.NET CLIENT DRIVER
CONFIGURATION

.NET client Driver can be used with Microsoft Visual Studio. To Configure it with Visual do as Follow-
ing.

• Launch Visual Studio and navigate to File > New > Project.

• Select Visual C# > Class Library > Name your project > Click on OK button.

123

Selenium Documentation, Release 1.0

• A Class (.cs) is created. Rename it as appropriate.

• Under right hand pane of Solution Explorer right click on References > Add References.

124

Chapter 10. .NET client driver configuration

Selenium Documentation, Release 1.0

• Select following dll files - nmock.dll, nunit.core.dll, nunit.framework.dll,ThoughtWorks.
Selenium.Core.dll,

ThoughtWorks.Selenium.IntegrationTests.dll,

Thought-

Works.Selenium.UnitTests.dll and click on Ok button

125

Selenium Documentation, Release 1.0

With This Visual Studio is ready for Selenium Test Cases.

126

Chapter 10. .NET client driver configuration

CHAPTER

ELEVEN

JAVA CLIENT DRIVER
CONFIGURATION

In General configuration of Selenium-RC with any java IDE would have following steps:

• Download Selenium-RC from the SeleniumHQ downloads page

• Start any java IDE

• Create new project

• Add to your project classpath selenium-java-client-driver.jar

• Record your test from Selenium-IDE and translate it to java code (Selenium IDE has automatic
translation feature to generate tests in variety of languages)

• Run selenium server from console

• Run your test in the IDE

These points have been delineated below with reference to Eclipse and IntelliJ:

You're Reading a Free Preview

Descarga
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->