Skip to main content

Posts

Showing posts with the label selenium

Could not start Selenium session: You may not start more than one session at a time

Error is: java.lang.RuntimeException: Could not start Selenium session: You may not start more than one session at a time at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:107)   If you get this error on Selenium then this might be the problem… If in your test you are using a webdriver to create the DefaultSelenium or Selenium object then remove this line from your code:         selenium.start(); Happy Testing

Simulating Keyboard strokes using Selenium1

Many a times we want to simulate keyboard strokes in our selenium tests. Here is how you can do this using Selenium1.   Command: selenium.keyPressNative(<KeyEvent_TobePassed>);   For Ex: If you want to simulate pressing Tab then you need to pass the command: selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+"");   View the list of KeyEvents here: http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/event/KeyEvent.html   Hope this helps!

Shell Script to Check if Selenium Server is Running!

Many a times we would want to write up a script to start the selenium server using a shell script… So here is the script     #!/bin/sh # # @Author – Sirisha # @Date   - May 29 2012 # Script to start the Selenium Server on a given host #   # Defined the hostname hostname=somehostname # Defined the path to the selenium server serverPath=~/seleniumServer/ # Define the Selenium Server version jar server=selenium-server-standalone-2.12.0.jar # Define the Search String for the server SERVICE_STRING="'java -jar $server'"   # Clear the terminal clear   echo "service string is: $SERVICE_STRING" echo "Starting Selenium Server on $hostname"   # Run the command to get the process list ps -ef | grep -v grep | grep selenium   # Check if the Selenium Server is already running if [ $? -eq 0 ] then     echo "$server is running, everything is fine" else     echo "$server is not running"  ...

AJAX Testing–Some Useful Links

Testing dynamic elements is always a challenge. I found some interesting/useful links which might prove useful to you too: http://agilesoftwaretesting.com/selenium-wait-for-ajax-the-right-way/ http://stackoverflow.com/questions/6850994/wait-for-javascript-file-to-load-in-selenium-2 http://saucelabs.com/blog/index.php/2011/04/how-to-lose-races-and-win-at-selenium/   Happy Testing!!!!

verifyTrue vs verifyEquals to compare strings

There is a clear winner here! Lets explore which one is better. Here is the scenario: “Lets say I have to test if the appropriate tooltip is flashed for a component” To get to the code directly, lets say I already have the tooltip text stored in a variable. Now all I have to do is to compare this string to the components tooltip text which I would get at runtime. So the algorithm would be Have the Expected Tooltip text stored in a variable Get the Actual Tooltip text for the component Compare the two strings – you should get the exact text We usually tend to use verifyTrue to compare because according to our algorithm we are expecting the result of the string comparison to be TRUE There is nothing wrong in using verifyTrue as if your test passes there is no difference in using verifyTrue or verifyEquals. The actual difference comes into picture only when your test fails. String varExpectedTooltipText = “Some tooltip”; // Method 1 - verifyTrue(selenium.getAttribute(...

How to check if my xpath is valid using firebug?

Yes, you can verify if your xpath is pointing to the right source on the web application under test using FireBug. Here is how:  Go to the Web Application under test We'll take Google for simplicity reasons Open FireBug -  Go to the Console   Console can also be seen at the bottom of the page, so don't worry they both are the same. They can be switched as follows:  Type in $x("Your xpath here") on the command line prompt as shown below: Hit Enter/Run You will get to see the element which was filtered out with your XPath expression

Script Error while running selenium scripts on IE

While running the selenium scripts on IE, we might get this error sometimes: Script Error on IE Solutions:  Possible that your pop-up blocker is enabled which is stopping selenium from opening another window (multi-window mode) - so add an exception to your pop-up blocker - Use this link to add/remove popup exceptions You can disable script errors on IE by disabling MDM.  Machine Debug Manager  Windows service (not only stop it, but prevent it from starting after the computer restarts). Follow this link to Disable Sometimes running the tests/starting the server as an ADMIN resolves the issue

Selenium: How to verify a hidden div tag exists

Most of the times we do have hidden div tags which need to be verified.  In most of the test designs, the first step towards testing a particular application is to verify that all the elements exist on the application under test.  Example:  Lets say we have a login page which has two text-fields. One for username the other for password. On the page, we also have a hidden div tag which is used by the developer to pass on the login failure message.  Usually its hidden but is set to visible when there is a login failure.  In usual test designs we would want to do something like this at the first step.  1. test all the components exist:  verifyTrue(selenium.isElementExists(LoginPage.username));  verifyTrue(selenium.isElementExists(LoginPage.password)); 2. Then give an incorrect username and password  selenium.type("LoginPage.username","SomeUserName"); selenium.type("LoginPage.password","SomePassword"); 3. Now verify that the...

Selenium n Safari

For all those who are stuck running Selenium tests on Safari... Here are a couple of tips: If you are using any version before 5 of Safari You can run your tests using any RC versions > 1.0 If you tests doesn't run then please verify the following:  Enable popup's on Safari - I know I sound silly but believe me thats the only issue sometimes Try running your tests using *safariproxy Verify the path given for the safari executable - it should be something like: C:\ProgramFiles\Safari\Safari.exe If you are using version 5.1  Then you have to run your tests on RC version 1.0.3 only Also change your tests to run using *safariproxy Don't forget enable pop ups :)  Even after doing all this - you'll still need an All the Best !!! And if you have a choice then pls run your tests on Safari Mac :) 

Issues Running Selenium Scripts Remotely

In real time we hardly have a simple setup like running on the same box which acts as a server and client :( So we might have to run the scripts remotely almost all the time...Well there might be issues while doing so...Here are some! Can't launch the browser at all: Check the host name you are using in your code first! There is a possibility that the DNS isn't able to map the hostname with the IP - so try running your tests specifying the IP instead of the hostname Check the path you provided to the executable of the browser - verify its found on the same path on your remote location Now the final check is to verify you can run the browser version on the RC version for ex: you can't run FF7 on RC1 :)  Browser Opens but tests aren't running This happens because the RC isn't able to talk to your browser - though it initiates the browser but can't talk to it anymore Solution: Upgrade your RC :)  Running on a Headless Box Selenium can't run u...

Difference between isVisible() and isElementPresent()

Many a times I wondered what's the difference between the two functions. Here is what I have: isElementPresent() - This method basically tests if the element we are looking for is present somewhere on the page. isVisible() - looks for display: none style tag - this might throw a null pointer if we aren't careful...thus to see if an element is visible first check if the element is present using isElementPresent() method. Then try checking if the element is visible! Observe that isElementPresent() won't mind even if our element is not visible. For ex: lets say the below is the html code for a component on my test application: now if you test the above component with selenium.isElementPresent("testinput") - returns true! selenium.isVisible("testinput") - returns false!

Failing to Run a single Testng Group

We all have various testng groups added/modified/deleted each time we update our test cases. Many a times we would want to run only a single testng group though! Failing tests? Pre Condition: My Test Automation Suite is based on Selenium-Ant-Testng When we want to run a single testng group lets say "sereUnitTests": If you don't have a beforemethod/beforetest/beforeclass annotation, then you should check your code...Its possible that something went wrong at the code level If you have a beforemethod/beforetest/beforeclass annotation, then you should check for the groups listed under each annotation For Ex: my beforemethod looks like this: @BeforeMethod(groups={"unit", "integration"}) public void openReader() throws SeleniumException { // Some functionality } But I see that the group which I wanted to run isn't listed thus testng notices that there is a before method to be initiated before your actual tests run but then doesn't ...

Running Firefox with Firebug

Many a times our XPATH's would fail on test execution. This is when we would want to run the browser with the firebug extension. Just add this section of code in your code:  File file = new File("firebug-1.5.4.xpi"); FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.addExtension(file); WebDriver driver = new FirefoxDriver(firefoxProfile); 

Error while running selenium script on IE6

The following is the code:  1).selenium.click("css=img[alt=\"Search\"]"); // For clicking Search Button 2).selenium.waitForPopUp("winSLocation", "30000"); // Wait for popup 3).selenium.selectWindow("name=winSLocation"); // Popup window 4).selenium.type("id=sLocation", "dal"); // dal Value assigning to the text in Pop up 5).selenium.click("id=btnSearch"); // Then click on search button 6).selenium.waitForPageToLoad("30000"); // wait for popup to get all value from dal 7).selenium.click("id=r1c1"); // to selecting the dal value from required values After  Clicking the Search button (means 1st point )we are getting the following error in selenium RC Command history “file:///C:/DOCUME~1/yamunach/LOCALS~1/Temp/customProfileDir872f1cda4df44c588669558e67f77656/core/RemoteRunner.hta “  This Error is ...

Selenium: Get DropDown Options

How to get the options of a dropdown list? Here are the ways to get it: Option 1: - There is a built in function in selenium getselectoptions() which can be called to get the list of options available for the select tag. For ex: string[] dropDownItems = selenium.GetSelectOptions("//select[@id='someid']"); Option 2: - If you want to get the text of the dropdown items which are in this format Option One Option Two then you can get the text for the options using: var iCount = (int) selenium.GetXpathCount("//select[@id='someid']/option"); var optionsList = new List (); for (int i = 1; i { String option = selenium.GetText("//select[@id='someid']/option[" + i + "]"); optionsList.Add(option); } Option 3: To get the id for the select options. We need the following code: var iCount = (int) selenium.GetXpathCount("//select[@id='someid']/option"); var optionsList = new List (); for (int i = 1; i { String option =...

XHR Issue with Selenium - Firefox

When we try executing our suite on Firefox, there is an issue with the new Selenium 1.0.3 server: Got result: XHR ERROR: URL = http://www.____.com/ Response_Code = 503 Error_Message = Serrvice Temporarily Unavailable on session b882a11224b7____ This doesn't occur with the older selenium server jar but just the new one. Root Cause: This occurs mainly due to Open command If we alter the open command to have its second argument as TRUE...it works! Reference: Reference2 Also suggest  that you might want to use the latest version of Selenium RC...RC's 2 and above don't throw the XHR error... Get the latest RC here .

Selenium throws an exception when running on Firefox

we get this error when we are trying to run a testng annotated java selenium code on firefox: "[testng] com.thoughtworks.selenium.SeleniumException: this.getCurrentWindow is not a function" Then all the other annotations are SKIPPED. A workaround for such an error would be to put the line of code which gives this error under a try block. In my case it was openReader() I changed the code as below: try{ openReader()} catch(Exception e){System.out.println(e.toString());} The class should throw the Exception too! This solved the problem and after the exception is printed, the execution continues!