Fish

Aboutme

Banner AD

Friday, April 26, 2013

WebDriver Playback in Selenium IDE

Selenium IDE:

As we all know selenium IDE is a plug-in for Firefox and we can record play back in Firefox only....from now onwards we have to modify that statement...Because

Selenium IDE is a plug-in for FIrefox and can record test in Firefox AND............You can run the same test in IE and Chrome and other browsers also..........


Download the latest version of Selenium IDE (2.0)

Below is the Release Notes:


Selenium IDE - Release Notes

2.0.0

WebDriver playback support:

By using this option we can run IDE script in different browsers...

Steps to Execute your script in IE or chrome

Prerequisites:

Java should be installed in your machine
Download selenium server jar file


Set the WebDriver Playback Settings in Selenium IDE

By default, WebDriver playback is turned off so recording and playback will work as before. To experiment with the WebDriver playback, you need to explicitly turn it on through the WebDriver tab of the Options dialog. To turn on WebDriver playback, check the option Enable WebDriver Playback.
Then set the Browser to the one you want to use. The choices are android, chrome, firefox, htmlunit, internet explorer, iPhone, iPad and opera.
Finally restart the Selenium IDE. A restart is required to enable or disable WebDriver Playback. Changing the browser does not require a restart.

Set up in IDE:
Part 1:
1. Open selenium IDE
2. Go to Options -->Options
3. Select WebDriver Tab
4. Check the Enable WebDriver Play back check box
5. In text box type firefox or internetexplorer or chrome
6. Click OK
7. Record a test case in Selenium IDE or open a test case which is already recorded in Selenium IDE.

Part 2:
1. Start your selenium server
2. open comand prompt and navigate to folder where you kept your selenium server and use the below commad to start your selenium server by using below command

My selenium server jar file is kept in C\Naga\Jar...

C:\Naga\Jar>java -jar selenium-server-standalone-2.31.0.jar

Your selenium server will start.

Then, In Selenium IDE click the run button. Based on the syntax give in options--options---Webdriver your browser will open and will execute the selenium IDE script in that browser.

Its really awesome feature of Selenium IDE




For more and detailed description please go through Samit Badle's Blog.

Below is URL:


Below are the Limitations:

Limitations

This is merely the first step in providing full WebDriver playback. Bugs and limitations are to be expected. I am aware of the following limitations:-
  • Multiple browser windows will be opened and will remain open.
  • Test may not pause or exit on errors.
  • An alert message may pop up for conditions that I have not encountered in my testing.
  • Executing a single command is not yet supported.
  • Highlighting a locator using the Find button may not work.
  • The timeout settings are ignored.
  • Screenshots may not work.
  • User extensions and plugins may not work.
As you probably know by now, I do not use Selenium IDE myself, so I can only test it a tiny bit. Your help in reporting any issues is always most appreciated.



NOTE: 
IF you don't want to use this feature then you need to un check the check box(options--options---Webdriver ) and restart your selenium IDE




Monday, December 31, 2012

Switch between Frames using webdriver

Here is the simple example how to switch between frames.


There are three ways to switch between frames.

INDEX:
Frame(int index)
Select a frame by its (zero-based) index. That is, if a page has three frames, the first frame would be at index "0", the second at index "1" and the third at index "2". Once the frame has been selected, all subsequent calls on the WebDriver interface are made to that frame.

ID OR NAME:
 frame(java.lang.String nameOrId)
Select a frame by its name or ID. Frames located by matching name attributes are always given precedence over those matched by ID.
Frame(WebElement frameElement)
Select a frame using its previously located webelement
Parameters: frameElement - The frame element to switch to.
DEFAULTCONTENT()
Selects either the first frame on the page, or the main document when a page contains iframes.
Below example explain you how to switch between frames.
=============================================================
package testng; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class Frames { public WebDriver driver; @BeforeClass public void beforeClass() { driver=new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); } @Test public void testFrames() throws Exception { driver.navigate().to("http://jqueryui.com/"); driver.findElement(By.linkText("Autocomplete")).click(); //index // driver.switchTo().frame(0); //id or Name //in this example Frame is not having ID or Name so this is invalid here //driver.switchTo().frame("nameorid"); //frameElement driver.switchTo().frame(driver.findElement(By.className("demo-frame"))); //type in text box.. driver.findElement(By.id("tags")).sendKeys("java"); Thread.sleep(5000); //switch back to default content driver.switchTo().defaultContent(); driver.findElement(By.linkText("Accordion")).click(); Thread.sleep(5000); } @AfterClass public void afterClass() { driver.quit(); } }

Monday, December 17, 2012

Run Webdriver script in Google Chrome

This post explains you how to run your webdriver script in google chrome..

Firefox Browser:
driver=new FirefoxDriver();  --it will work and will launch your firefox browser,

Google Chrome:

driver= new Chromedriver() --- it will throw an error.

Error:


FAILED CONFIGURATION: @BeforeClass beforeClass
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list

To over come this we need to download the chrome driver.exe and we have to specify the apth of chrome driver in the script

Download path:
http://code.google.com/p/chromedriver/downloads/list

take the latest exe file. see the below image




save the chrome driver in a folder and you need to specify the path of driver in your webdriver script.

Below is the Sample code:


package testng;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class ChromedriverTest {

public WebDriver driver;
  @BeforeClass
  public void beforeClass() {
// Create chrome driver instance...
 System.setProperty("webdriver.chrome.driver", "C:\\xxx\\Jar\\chromedriver.exe");
 driver=new ChromeDriver();
  }


  @Test
  public void testChromedriverTest() throws Exception {
 driver.navigate().to("http://bing.com");
 Thread.sleep(5000);
  }

  @AfterClass
  public void afterClass() {
 driver.quit();
  }

}


Use the above code your script will run in google chrome.





Tuesday, May 22, 2012

Error while running webdriver tests in IE

While running tests in webdriver using internet explorer i got the following error org.openqa.selenium.WebDriverException: Unexpected error launching Internet Explorer. Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information) The reason for this is in Internet Explorer Protected Mode must be set to the same value (enabled or disabled) for all zones. See the below image to understand this line. Go to Tools----Options---Security Tab
Like this for all the zones...Local Intranet, Trusted sites and Restricted sites..we have to Update the security level to low. Than u can easily run tests using internet explorer..

Thursday, December 29, 2011

Handling HTTPS sites using Selenium

As all we know selenium is used for automating web application. We will not have any difficulty in automating HTTP site...We face some of the below issues while automating HTTPS sites..

HTTPS sites will show some security notifications below are some:

Firefox:



Internet Explorer:





To over come this issue we need to add certification

1. Need to add remote control configuration
RemoteControlConfiguration rcc = new RemoteControlConfiguration ();

2. Set TrustAllSSLCertificates flag to TRUE
rcc.setTrustAllSSLCertificates(true);


3. Pass the rcc Instance to Selenium Server
SeleniumServer server = new SeleniumServer(rcc);


If the above steps also doesnt work you need to install cyber villian certificate to automate HTTPS sites (Especially for IE)


1. Extract selenium-server.jar
2. In selenium server folder Open sslSupport folder
3. It contains cybervillainsCA.cer please install that certificate

Now you can run your selenium rc  scripts with out any problem for HTTPS sites.


Below is the code with out the Above steps:


====================================

package selenium;


import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestCase;

@SuppressWarnings("deprecation")
public class HTTPs extends SeleneseTestCase{

public SeleniumServer ss;
@Before
public void setUp() throws Exception
{
ss=new SeleniumServer();
ss.start();
selenium=new DefaultSelenium("localhost", 4444, "*firefox", "https://www.dibbs.bsm.dla.mil/");
selenium.start();
}

@Test
public void testSelenium() throws Exception
{
selenium.open("/");
selenium.windowMaximize();

Thread.sleep(5000);

}
@After
public void tearDown() throws Exception
{
selenium.stop();
ss.stop();
}

}
=============================================
If you run the above script it will give you an error..see the below image


To avoid that error please use below code:

================================================

package selenium;


import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestCase;

@SuppressWarnings("deprecation")
public class HTTPs extends SeleneseTestCase{

public SeleniumServer ss;
@Before
public void setUp() throws Exception 
{
RemoteControlConfiguration rcc=new RemoteControlConfiguration();
//trust all ssl certificates
rcc.setTrustAllSSLCertificates(true);

ss=new SeleniumServer(rcc);
ss.start();
selenium=new DefaultSelenium("localhost", 4444, "*firefox", "https://www.dibbs.bsm.dla.mil/");
selenium.start();
}

@Test
public void testSelenium() throws Exception
{
selenium.open("/");
selenium.windowMaximize();

Thread.sleep(5000);

}
@After
public void tearDown() throws Exception 
{
selenium.stop();
ss.stop();
}

}


========================================================
The three lines which are in blue will make your browser to trust all SSL certificates..

Hope this post will be useful..