Migrating from Selenium RC to Webdriver

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Migrating from Selenium RC to Webdriver

Ashwin
Hi

In our project we are planning to migrate from Selenium RC to Webdriver.
Can u please suggest us or share any information on how to proceed with this activity.

In Selenium Documentation i have gone through about migrating from Selenium RC to Webdriver link  and WebdriverBackedSelenium API.

Can u please share if you have any example on this.

Thanks & Regards,
Ashwin
Reply | Threaded
Open this post in threaded view
|

Re: Migrating from Selenium RC to Webdriver

softwaretestingforum
Administrator
Hello Ashwin,

Migrating to Selenium2 depends on how well you have wrapped you selenium calls.
If you have selenium object scattered all over than it would be more laborious.
Could you share one your test method?
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: Migrating from Selenium RC to Webdriver

Ashwin
This post was updated on .
Hi Tarun,

Sorry for the late response.

Yes in our project selenium object is scattered all over the place.

Please find the below class example

public class abc
{
        private static Logger log = LoggerFactory.getLogger(abc.class);
        public DefaultSelenium selenium;

               
        @BeforeTest
    public void startTest() throws Exception
    {
                xyz obj = new xyz();
                obj.testLaunch();
                selenium = obj.selenium;
               
    }
       
        @Test
        public void testabc()
        {
               
                selenium.click("link=reset password");
                selenium.waitForPageToLoad("30000");
               
                //Enter Invalid Email Address
                selenium.type("email", "simply@invalid.com");
                selenium.click("Submit");
                selenium.waitForPageToLoad("30000");
               
                if(selenium.isTextPresent("Cannot reset password User is not registered"))
                {
                        log.info(" Enter a Registered Email-ID ");
                }
                               
                selenium.type("email", "abc@a.com");
                selenium.click("Submit");
                selenium.waitForPageToLoad("30000");
               
         }
       
        @AfterTest
        public void tearDown()
        {
                selenium.close();
                selenium.stop();
        }
}
Reply | Threaded
Open this post in threaded view
|

Re: Migrating from Selenium RC to Webdriver

softwaretestingforum
Administrator
Hi Ashwin,

You mat have to work a little extra for migration. But before that I suggest you to use Page Object pattern to write your tests so that operations like type, click are not scattered in your tests. These are the things which make migration easy.

Hence have a class which wraps the selenium operations -

public class Action() {
  Selenium selenium;
 
  public Action(Selenium selenium) {
     this.selenium = selenium;
  }

  public void type(String elementLocator, String testData) {
    selenium.typr(elementLocator, testData);
  }

  public void click(String elementLocator) {
    selenium.click(elementLocator);
  }

 // some more selenium operations

}

Now your page object class can extend action class and use these operation. While your test would use the page object class to use the needed operations like -

//Page object class

public class LoginPage() extends Action {
  Selenium selenium;

   public LoginPage(Selenium selenium) {
     super(selenium);
     this.selenium = selenium;
  }

  public LoginPage login(String username, String password) {
     type(elementLocator, username);
     type(elementLocator, password);
     click(elementLocator);
  }


// Test class
// SelTestCase creates the selenium object
public class TestClass extends SelTestCase {
   LoginPage loginPage = new LoginPage(selenium)
   loginPage.login(username, password);
   // assert some thing here
}

Once your tests have reached this level then you can just replace the wrapper methods in Action class to use WebDriver object instead of Selenium object. There is no change needed either in Page Object class or Test class it self.
You may also like to see PageFactory pattern once you have wrapped all your selenium calls how I described above.
Also this post of mine might help you - http://www.seleniumtests.com/2012/01/selenium-2-methods-are-no-more-weird.html
when migrating.

Let me know if you have any more questions.






   
~ seleniumtests.com