I have the following issue. When I start my selenium test, to get to the part where the actual test is performed, I need to start the browser, log in, do some other operations, and then it comes the part I want to test.
Isn't there a way to do the first part only once, leave the session and the browser open. And for a next test Run only continue this session, without starting up.
So basically I would have a test initializing, and leaving the session open. And other tests which use this initialized session, reuse the session every time.
I am using Java, and Selenium RC.
Thanks!
In one line: You can use firefox profile for that.
In Detail: 1. Login in your firefox manually (Use, Remember me option of your website if its there. else it should be ok) 2. Go to Firefox Menu > Help > Troubleshooting Information > Profile Folder (Click on it). 3. When you invoke you selenium webdriver (not sure about RC though), use this
This way you'll be directly logged in to your account. This also is faster as many data is picked from browser cache unlike fresh firefox profile
I would suggest using testng which lets you use java annotations for pre processing like invocation of certain piece of code only before class or test suite using @BeforeClass, @BeforeSuite respectively. Herein you can define selenium server instantiation, browser invocation to be done either before a class of test suite (there are many other options also available) and then this could be reused in subsequent test methods.
It depends a bit upon your environment. I use C# with Selenium RC (and therefore NUnit test framework). Since you use Java (and presumably JUnit) it works the same way. Both JUnit and NUnit let you specify special code that executes before each test, after each test, before each suite, or after each suite.
In your case, you want to supply code to run before a suite (a suite simply being a collection of all your test cases in one namespace (C#) or class (Java)). In C# I use code like this--the
[TextFixtureSetUp]
directive is what lets NUnit recognize this as suite setup code.The equivalent designation in Java is to use the
@BeforeClass
attribute as inMy recent article Web Testing with Selenium Sushi: A Practical Guide and Toolset is very focused on C# but it may provide you with some general ideas that you could apply to your Java work.