How to clone Selenium Webdriver using Java language ? Is it Possible or not ?

814 views
Skip to first unread message

Poovaraj Thangamariappan

unread,
May 27, 2017, 12:28:40 AM5/27/17
to seleniu...@googlegroups.com
Hi Team,

I want to clone Selenium Webdriver using Java language. I have written below code. Can you please help me how to clone webdriver ?  Is it possible or not ? Please correct me if it is wrong ?

Code :-

package Selenium_Program;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class demo_WebDriver_Cloning implements Cloneable
{
public static WebDriver driver;
public static WebDriver driver1;

demo_WebDriver_Cloning(WebDriver driver)
{
this.driver=driver;
}
@Override
public Object clone() throws CloneNotSupportedException
{
return (demo_WebDriver_Cloning)super.clone();
}
public static void main(String[] args)
{
try
{
// TODO Auto-generated method stub
 demo_WebDriver_Cloning obj = new demo_WebDriver_Cloning(driver);
 System.setProperty("webdriver.gecko.driver", "D:\\Working\\Selenium\\geckodriver.exe");
 driver=new FirefoxDriver(); 
 driver.get("https://www.google.co.in/");  
 
 driver1 = (demo_WebDriver_Cloning)driver.clone();
 driver1.get("https://www.facebook.com/");
 
}catch(Exception e)
{
}
}

}

Thanks in Advance !

Regards,
Poovaraj

Krishnan Mahadevan

unread,
May 27, 2017, 12:38:18 AM5/27/17
to seleniu...@googlegroups.com

Can you please help elaborate your use case ? What exactly are you trying to do ?

 

Your cloning mechanism wont work, because you have merely invoked a super.clone() (here your super is basically the Cloneable interface and it doesn’t have any implementation).

You would need to write code such that the clone() implementation creates another WebDriver instance and returns it optionally doing the following :

 

  • Open the same URL as the original instance
  • Copy the cookies if applicable/relevant
  • Duplicate the window size etc.,

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAMu9-ZW2Kn7u5oFmdPdzRG5G1heF5m%2BeUtMSCB8OkkMZXiiZiw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Xiang Dong

unread,
May 27, 2017, 5:14:18 AM5/27/17
to seleniu...@googlegroups.com

Not sure what do your really want? WebDriver instance is just a Java object but the object itself bind a Web Browser instance. The driver instance is used to manipulate the browser instance for various test actions. Never try clone one because you are not able to clone one browser instance. If you want to two webdriver instances, you just need to create two. If you want to one browser open two tabs for different website. it is possible.


--david




From: seleniu...@googlegroups.com <seleniu...@googlegroups.com> on behalf of Poovaraj Thangamariappan <poovar...@gmail.com>
Sent: Saturday, May 27, 2017 12:28 PM

To: seleniu...@googlegroups.com
Subject: [selenium-users] How to clone Selenium Webdriver using Java language ? Is it Possible or not ?
Hi Team,

I want to clone Selenium Webdriver using Java language. I have written below code. Can you please help me how to clone webdriver ?  Is it possible or not ? Please correct me if it is wrong ?

Code :-

package Selenium_Program;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class demo_WebDriver_Cloning implements Cloneable
{
public static WebDriver driver;
public static WebDriver driver1;

demo_WebDriver_Cloning(WebDriver driver)
{
this.driver=driver;
}
@Override
public Object clone() throws CloneNotSupportedException
{
return (demo_WebDriver_Cloning)super.clone();
}
public static void main(String[] args)
{
try
{
// TODO Auto-generated method stub
 demo_WebDriver_Cloning obj = new demo_WebDriver_Cloning(driver);
 System.setProperty("webdriver.gecko.driver", "D:\\Working\\Selenium\\geckodriver.exe");
 driver=new FirefoxDriver(); 
 driver.get("https://www.google.co.in/");  
Account Options. Sign in; Search settings; Web History

 
 driver1 = (demo_WebDriver_Cloning)driver.clone();
 driver1.get("https://www.facebook.com/");
Create an account or log into Facebook. Connect with friends, family and other people you know. Share photos and videos, send messages and get updates.

 
}catch(Exception e)
{
}
}

}

Thanks in Advance !

Regards,
Poovaraj

--

Poovaraj Thangamariappan

unread,
May 27, 2017, 12:04:19 PM5/27/17
to seleniu...@googlegroups.com
Hi Krishnan Mahadevan,

Thanks for your reply.  I have to validate 2 application simultaneously using single driver.  

Scenarios :-

  • Login into application and Updated in Email ID in first application
  • I have to open second application and verify email id is updated or not
  • Again, I have to move first application and updated in account number
  • verify account number in second application 


* I cannot use SwitchToWindow and SwitchToFrame option in this scenarios 
  
  How to handle this scenario without using 2 webdriver instance ? 


Regards,
Poovaraj

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/D10D3CA6-10AF-46C7-ABEF-DB8890E4D8BD%40gmail.com.

⇜Krishnan Mahadevan⇝

unread,
May 27, 2017, 12:09:03 PM5/27/17
to seleniu...@googlegroups.com

Why not just work with two WebDriver instances ? Wouldn't that be a lot more simpler and easier to manage rather than resorting to clone ?

Your test case would just create two WebDriver instances wherein, in the first instance you would have opened your web application #1 and in the second instance you would have opened the second web application.

You don't need clone here. You just need your test to create and work with two WebDriver instances rather than one (which is what most tests would usually work with ).


To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAMu9-ZXohDu3fn2fZ%2B6SUpq54NKU7qcd7wZqUYgrW6exvYMK%3Dg%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.
--

Poovaraj Thangamariappan

unread,
May 27, 2017, 12:23:16 PM5/27/17
to seleniu...@googlegroups.com

It was working fine this scenario if i have created 2 web driver instance but Currently, the Framework is not supporting to create 2 webdriver instance simultaneously. so, I have cloned web driver instance.  

Is anyother way to achieve this scenario using single webdriver instance ? 


On Sat, May 27, 2017 at 9:38 PM, ⇜Krishnan Mahadevan⇝ <krishnan.ma...@gmail.com> wrote:

Why not just work with two WebDriver instances ? Wouldn't that be a lot more simpler and easier to manage rather than resorting to clone ?

Your test case would just create two WebDriver instances wherein, in the first instance you would have opened your web application #1 and in the second instance you would have opened the second web application.

You don't need clone here. You just need your test to create and work with two WebDriver instances rather than one (which is what most tests would usually work with ).


On Sat, May 27, 2017, 21:34 Poovaraj Thangamariappan <poovar...@gmail.com> wrote:
Hi Krishnan Mahadevan,

Thanks for your reply.  I have to validate 2 application simultaneously using single driver.  

Scenarios :-

  • Login into application and Updated in Email ID in first application
  • I have to open second application and verify email id is updated or not
  • Again, I have to move first application and updated in account number
  • verify account number in second application 


* I cannot use SwitchToWindow and SwitchToFrame option in this scenarios 
  
  How to handle this scenario without using 2 webdriver instance ? 


Regards,
Poovaraj

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CANikZLmor%2BCH1AxGikVnhU9%3Dz6Ka0DFy0OU7Uhpbg12_k7hQqA%40mail.gmail.com.

⇜Krishnan Mahadevan⇝

unread,
May 27, 2017, 12:28:38 PM5/27/17
to seleniu...@googlegroups.com

Even then you can have one WebDriver managed by your framework and the other one managed by your test case no ? You can extend the concept of cloning but not in the literal sense but by having your test introspect the WebDriver instance provided by your framework, take a look at it's capabilities and then create a "similar" webdriver instance which your test can manage.

At the end, before your test runs to completion it can clean up the WebDriver instance it created.

The other option would be to inject a hyperlink in runtime using JavaScript via your webdriver. This hyper link when clicked would trigger a new window to be opened. From there on your test can merely switch to the other window and have it open up a new url ( your second web app ) and take it up from there.


On Sat, May 27, 2017, 21:53 Poovaraj Thangamariappan <poovar...@gmail.com> wrote:

It was working fine this scenario if i have created 2 web driver instance but Currently, the Framework is not supporting to create 2 webdriver instance simultaneously. so, I have cloned web driver instance.  

Is anyother way to achieve this scenario using single webdriver instance ? 


On Sat, May 27, 2017 at 9:38 PM, ⇜Krishnan Mahadevan⇝ <krishnan.ma...@gmail.com> wrote:

Why not just work with two WebDriver instances ? Wouldn't that be a lot more simpler and easier to manage rather than resorting to clone ?

Your test case would just create two WebDriver instances wherein, in the first instance you would have opened your web application #1 and in the second instance you would have opened the second web application.

You don't need clone here. You just need your test to create and work with two WebDriver instances rather than one (which is what most tests would usually work with ).


On Sat, May 27, 2017, 21:34 Poovaraj Thangamariappan <poovar...@gmail.com> wrote:
Hi Krishnan Mahadevan,

Thanks for your reply.  I have to validate 2 application simultaneously using single driver.  

Scenarios :-

  • Login into application and Updated in Email ID in first application
  • I have to open second application and verify email id is updated or not
  • Again, I have to move first application and updated in account number
  • verify account number in second application 


* I cannot use SwitchToWindow and SwitchToFrame option in this scenarios 
  
  How to handle this scenario without using 2 webdriver instance ? 


Regards,
Poovaraj

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAMu9-ZUf%2BRboQVWQ6b8sHCqk0Y%3DW8iKtKrJTZJUK4Lu9Ni0WHw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Poovaraj Thangamariappan

unread,
May 27, 2017, 12:35:21 PM5/27/17
to seleniu...@googlegroups.com

Thank you. Let me try this option !


To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CANikZL%3Dq7s8PoEAXacJf4CRCcocb5fR0f7awP_RKv3itGBaBFw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages