C # + NUnit + Selenium Grid - parallel launch of several browsers on one node - selenium-webdriver

Use:
C# + WebDriver+NUnit + Grid,
Implementation using Page Object+Page Factory,
WebDriver 3.4.0,
Nunit 3.5.0,
Google Chrome Driver 2.36,
Mozilla Geckodrive 0.20.0,
last updated Chrome and FF browsers
I'm trying to learn how to implement parallel test runs. Now the task is next: running one TestFixture on node in two different browsers simultaneously. I'm doing like this:
[TestFixture("chrome")]
[TestFixture("firefox")]
[Parallelizable(ParallelScope.Fixtures)]
public class LoginTests : BaseObject
{
public LoginTests(string browser)
{
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability("browserName", browser);
driver = new RemoteWebDriver(new Uri("http://192.168.1.63:5555/wd/hub"), capability);
driver.Navigate().GoToUrl(baseUrl);
driver.Manage().Window.Maximize();
}
private static LoginPageHelper LoginPageHelper = new LoginPageHelper();
[Test]
public static void LoginOnMailru()
{
string email = "test.account.damir#mail.ru";
string password = "q123123a";
LoginPageHelper.
DoLogin(email, password);
}
}
After performing: run 2 browsers at the same time (chrome and FF). The test passed completely in the FF browser. Chrome executed only driver.Navigate().GoToUrl(baseUrl) and an error appears
Test name: SendingMailTestForLQ.Tests.LoginTests("chrome").LoginOnMailru
Result: OpenQA.Selenium.NoSuchElementException : Could not find element by: By.Id: mailbox:submit
What I'm doing wrong, why there is an error "Could not find element by: By.Id: mailbox:submit"? Thanks!
P.S. Sorry for my English.

Related

How to handle browser invocation in parallel tests using TestNG

I have been using browser invocation in #Beforeclass TestNG method using the parameter passed from testng.xml. Once the browser is invoked, I am using login test in a #BeforeMethod which is required for all the other #Tests to start. But with this setup, I am unable to run the tests in parallel. I am seeing one browser is open and login tests which is required by both tests are run in same browser and fails. All my tests are in single class file. Code structure is as below:
public class MainTest {
WebDriver driver;
BrowserFactory browser;
ReadData crmdatafile;
#BeforeClass(alwaysRun = true)
public void setup(ITestContext context) throws Exception{
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("datafile.txt").getFile());
crmdatafile = new ReadData(file.getAbsolutePath());
browser = new BrowserFactory(context.getCurrentXmlTest().getParameter("Selenium.browser"));
driver = browser.getNewBrowser();
driver.manage().deleteAllCookies();
driver.get(crmdatafile.data.get("enviornment", "url"));
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
}
#BeforeMethod()
public void login(){
System.out.println("contains the code for login which needs to be run before every test");
}
#AfterMethod
public void afterEachTest(ITestResult result) throws IOException {
driver.close();
}
#Test
public void Test1() {
System.out.println("Will run login and next steps");
}
#Test
public void Test2() {
System.out.println("Will run login and next steps");
}
public class BrowserFactory {
private WebDriver driver;
private String browser;
public BrowserFactory(String browser) {
String brow=browser.trim().toLowerCase();
if(!(brow.equals("firefox") || brow.equals("ff") || brow.equals("internetexplorer") || brow.equals("ie") || brow.equals("chrome") || brow.equals("gc"))) {
browser="ie";
}
this.browser = browser;
}
public WebDriver getNewBrowser() {
String brow = browser.trim().toLowerCase();
if(brow.equals("firefox") || brow.equals("ff")) {
System.setProperty("webdriver.gecko.driver", "drivers\\geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver(capabilities);
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
return driver;
}else if(brow.equals("internetexplorer") || brow.equals("ie")){
driver = new InternetExplorerDriver();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
return driver;
}else if(brow.equals("chrome") || brow.equals("gc")){
System.setProperty("webdriver.chrome.driver", "drivers\\chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
capabilities.setCapability("webdriver.chrome.binary","drivers\\chromedriver.exe");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
return driver;
}
return null;
}
How can I improve the above structure to run tests in parallel and using a different browser for each test?
Your test code has some issues.
You are instantiating a webdriver instance in your #BeforeClass annotated method and that is being shared by all your #Test annotated test methods. You are also invoking driver.close() in an #AfterMethod annotated method.This is a recipe for disaster because AFAIK driver.close() is equivalent to driver.quit() if you are having only one web browser instance. So what this means is that your second test method will not have a valid browser (if you are running sequentially).
If you are running in parallel, then all your test methods are going to be competing for the same browser, which is now going to cause race conditions and test failures.
You should ideally speaking move the logic of your setup() method into a listener which implements IInvokedMethodListener interface and then have this listener inject the webdriver instances into a ThreadLocal variable, which your #Test methods can then query.
You can refer to my blog post which talks in detail on how to do this.
Please check if that helps.
Here is the thing, as far as I can see you're not using annotations right and (probaly) testNG as well.
If you want to create browser instance before each test you may want to use #BeforeTest annotation. Also you may perform your test set up in this method as well. #BeforeClass annotation will be executed only once before this particular class will be executed.
It's a good idea to split tests that do different things into separate test files, case your tests do almost the same, but say params for tests are different - it's a good idea to use #DataProvider. Otherwise maybe you may want to extend your basic test with setup.
If you just want to re-execute same tests, but with different browser - consider relaunching your test job with different params or using #DataProvider as described above.
As far as I remember there are several ways to run testNG in parallel: Methods, Classes, Tests, Instances - figure out which one you need and which one works better with your setup.

When I run a test suite with ChromeDrive Chrome is opened at every test

I'm trying to use the same code with Appium driver and Java , TestNG but with ChromeDriver I changed the configuration by adding that code :
File file = new File("C:/QA/Emna/chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
WebDriver driver = new ChromeDriver();
The problem is that any test case the chrome window is opened a new one, even if my tests are in a correct order with Priority (by TestNG).
Is there a way to work in only one window?
WebDriver driver = new ChromeDriver(); is what opens a new browser each time. Move it to #BeforeClass section and use the same instance in all the tests.
You need to move you code snippet in any #Before type of TestNG methods. Lets say your all test cases are in a TestNG class then
Here is how it should look like:
#BeforeClass
public void deSetup(){
File file = new File("C:/QA/Emna/chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
WebDriver driver = new ChromeDriver();
}
But if this is not the case, what I mean by this, that your test cases are spread across the multiple TestNG classes then the best way is to have a Singleton class to load and initialize the ChromeDriver. Call method of the Singleton class to instantiate the ChromeDriver in any one of method annotated as #BeforeSuite #BeforeTest or #BeforeGroups. And have a reference variable of WebDriver type in evelry test class and assigne the previously initialized ChromeDriver to this reference variable in #BeforeClass method.
In such a way, ChromeDriver will be instantiated only once when any one of #BeforeSuite #BeforeTest or #BeforeGroups method runs and will be available in every TestNG class once #BeforeClass runs.
This way you can work in only one Chrome window.
I have fixed my problem by this way in #BeforeClass:
#BeforeClass
public static void before() {
// check active session
System.out.println("Becore Test Method");
File file = new File("C:/QA/Emna/chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
wd = new ChromeDriver();
}
I made an instance like that:
static WebDriver driver ;
Then in every test I put the following :
#Test
public static void run1() {
//my tests using wd
}
#Test
public static void run2() {
//my tests using wd
}

NUnit will not run consecutive Selenium Webdriver C# tests

Selenium Webdriver 2.48 , C#, NUnit 2.6.4, Chrome Driver
When I run my tests from the NUnit test runner, they all pass if run individually.
If I select a main heading node, and select "Run", the first test in the group will run, the rest will fail.
If I have the test fixture [TearDown] close the driver at the end of each test, the following error occurs:
"Invalid OPeration Exception: No such session"
If I have the test fixture [TearDown] quit the driver, the following error occurs:
"Unexpected error. System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:13806
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)"
Using either driver.Quit() or driver.Close() makes no difference to the result - only the first test in the group running.
I have searched but not been able to find a solution. It must be possible to run all tests by running from the top-most node, rather than having to select each test and run them individually. Any help would be appreciated. Thanks. Michael
Here is an example which has two tests in the one class. I have removed most of the methods from the tests as they are very long.
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium;
using NUnit.Framework;
using SiteCore.HousingRepairsLogic;
namespace SiteCore.HousingRepairsTests.DoorsAndWindowsTests
{
[TestFixture]
class DoorsTests
{
private IWebDriver driver = new ChromeDriver(#"C:\chromedriver_win32");
[SetUp]
public void setup()
{
HousingRepairsLogic.Utilities utilities = new Utilities(driver);
utilities.NavigateToLogin();
}
[TearDown]
public void teardown()
{
Utilities utilities = new Utilities(driver);
utilities.CloseDriver();
}
[Test]
public void LockRepair()
{
//Create Instance of the HomePage class
HomePage homepage = new HomePage(driver);
homepage.ClickHousingButton();
homepage.RequestRepairButton();
homepage.RequestRepairNowButton();
}
[Test]
public void ExternalWoodDoorFrameDamaged()
{
//Create Instance of the HomePage class
HomePage homepage = new HomePage(driver);
homepage.ClickHousingButton();
homepage.RequestRepairButton();
homepage.RequestRepairNowButton();
//Create instance of TenancyPage class
TenancyPage tenancy = new TenancyPage(driver);
//proceed with login
tenancy.ClickYesLoginButton();
//enter username
tenancy.EnterMyeAccountUserName();
//enter password
tenancy.EnterMyeAccountPassword();
//click the login button
tenancy.ClickLoginButton();
}
}
You initialize the driver once in the fixture, when it is declared:
private IWebDriver driver = new ChromeDriver(#"C:\chromedriver_win32");
Then your first test runs, uses the driver and the teardown closes it. The next test no longer has use of the driver.
You need to either: reinitialize the driver in the setup, or you need to close it in the fixture teardown.
If you chose to initialise and close in the setup/teardown you will see that the driver starts a new browsersession for every test. This will make sure that your tests are independant of eachother, but it will cost a lot more runtime.
If you want to re use the browsersession for all the tests: move the initialization and closure to TestFixture Setup and TestFixture Teardown methods.

No response from server for url - Selenium WebDriver (C#) [duplicate]

This question already has answers here:
Selenium error: No response from server for url http://localhost:7055
(3 answers)
Closed 9 years ago.
UPDATE:
I'm having the same issue after updated to 2.29 its like on and off its very inconsistency that's the frustration part.
UPDATE END:
Selenium WebDriver 2.25 version.
Browser: FF (17.0.1 version) & IE (8)
The one most single thing annoying/driving me crazy is about stale elements and I'm still not sure how can my test cases be run passed all the time; some times my test cases passed and some times failed and I'm using CSSSelector to find the element but still on/off my test cases failed....
here is what I'm using to find the element.
here is my code in C#
public class WebDriverUtil
{
public static IWebDriver driver = StartBrowser();
private static FirefoxProfile _ffp;
private static IWebDriver _driver;
private static IWebDriver StartBrowser()
{
switch (Common.BrowserSelected)
{
case "ff":
_ffp = new FirefoxProfile();
_ffp.AcceptUntrustedCertificates = true;
_driver = new FirefoxDriver(_ffp);
break;
case "ie":
var options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
_driver = new InternetExplorerDriver(options);
_driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(2));
break;
case "chrome":
//_driver = new ChromeDriver();
break;
}
return _driver;
}
public static IWebElement WaitForElement(By by)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
return wait.Until(drv => drv.FindElement(by));
}
}
public class TestCaseEmployee: WebDriverUtil
{
public static bool EmployeeCase()
{
//....
WaitForElement(By.LinkText("Select All Employee")).Click(); //<<< see error below
}
}
//error message:
Test 'M:TestCases.TestCaseEmployee' failed: No response from server for url http://localhost:7056/hub/session/79b742cf-e1dc-4016-bdbb-c2de93cd8fa4/element
OpenQA.Selenium.WebDriverException: No response from server for url http://localhost:7056/hub/session/79b742cf-e1dc-4016-bdbb-c2de93cd8fa4/element
at OpenQA.Selenium.Support.UI.DefaultWait`1.PropagateExceptionIfNotIgnored(Exception e)
at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
I had the same problem and solve in this way:
a) avoid methods like 'do wity retry' to manipulate IWebElements, because in this way the tests take to many time to run, is unnecessary and tests fails intermittently.
b) downgrade the Firefox version to 5 (maybe from FF 3.6 until 6 works fine, but the new versions of FF throws an intermittent exception like 'No response from hub/session...'
c) if you need to handle elements in your test that is loaded via Ajax on page, be sure to provide a js function that you can stop element load, so you should call this function from WebDdriver before FindElement and do what you want.

How to handle login pop up window using Selenium WebDriver?

How to handle the login pop up window using Selenium Webdriver? I have attached the sample screen here. How can I enter/input Username and Password to this login pop up/alert window?
Thanks & Regards,
Use the approach where you send username and password in URL Request:
http://username:password#the-site.com
So just to make it more clear. The username is username password is password and the rest is usual URL of your test web
Works for me without needing any tweaks.
Sample Java code:
public static final String TEST_ENVIRONMENT = "the-site.com";
private WebDriver driver;
public void login(String uname, String pwd){
String URL = "http://" + uname + ":" + pwd + "#" + TEST_ENVIRONMENT;
driver.get(URL);
}
#Test
public void testLogin(){
driver = new FirefoxDriver();
login("Pavel", "UltraSecretPassword");
//Assert...
}
This should works with windows server 2012 and IE.
var alert = driver.SwitchTo().Alert();
alert.SetAuthenticationCredentials("username", "password");
alert.Accept();
This is very simple in WebDriver 3.0(As of now it is in Beta).
Alert alert = driver.switchTo().alert() ;
alert.authenticateUsing(new UserAndPassword(_user_name,_password));
driver.switchTo().defaultContent() ;
Hopefully this helps.
Now in 2020 Selenium 4 supports authenticating using Basic and Digest auth . Its using the CDP and currently only supports chromium-derived browsers
Example :
Java Example :
Webdriver driver = new ChromeDriver();
((HasAuthentication) driver).register(UsernameAndPassword.of("username", "pass"));
driver.get("http://sitewithauth");
Note : In Alpha-7 there is bug where it send username for both user/password. Need to wait for next release of selenium version as fix is available in trunk https://github.com/SeleniumHQ/selenium/commit/4917444886ba16a033a81a2a9676c9267c472894
Solution: Windows active directory authentication using Thread and Robot
I used Java Thread and Robot with Selenium webdriver to automate windows active directory authentication process of our website.
This logic worked fine in Firefox and Chrome but it didn't work in IE. For some reason IE kills the webdriver when authentication window pops up whereas Chrome and Firefox prevents the web driver from getting killed. I didn't try in other web browser such as Safari.
//...
//Note: this logic works in Chrome and Firefox. It did not work in IE and I did not try Safari.
//...
//import relevant packages here
public class TestDemo {
static WebDriver driver;
public static void main(String[] args) {
//setup web driver
System.setProperty("webdriver.chrome.driver", "path to your chromedriver.exe");
driver = new ChromeDriver();
//create new thread for interaction with windows authentication window
(new Thread(new LoginWindow())).start();
//open your url. this will prompt you for windows authentication
driver.get("your url");
//add test scripts below ...
driver.findElement(By.linkText("Home")).click();
//.....
//.....
}
//inner class for Login thread
public class LoginWindow implements Runnable {
#Override
public void run() {
try {
login();
} catch (Exception ex) {
System.out.println("Error in Login Thread: " + ex.getMessage());
}
}
public void login() throws Exception {
//wait - increase this wait period if required
Thread.sleep(5000);
//create robot for keyboard operations
Robot rb = new Robot();
//Enter user name by ctrl-v
StringSelection username = new StringSelection("username");
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(username, null);
rb.keyPress(KeyEvent.VK_CONTROL);
rb.keyPress(KeyEvent.VK_V);
rb.keyRelease(KeyEvent.VK_V);
rb.keyRelease(KeyEvent.VK_CONTROL);
//tab to password entry field
rb.keyPress(KeyEvent.VK_TAB);
rb.keyRelease(KeyEvent.VK_TAB);
Thread.sleep(2000);
//Enter password by ctrl-v
StringSelection pwd = new StringSelection("password");
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(pwd, null);
rb.keyPress(KeyEvent.VK_CONTROL);
rb.keyPress(KeyEvent.VK_V);
rb.keyRelease(KeyEvent.VK_V);
rb.keyRelease(KeyEvent.VK_CONTROL);
//press enter
rb.keyPress(KeyEvent.VK_ENTER);
rb.keyRelease(KeyEvent.VK_ENTER);
//wait
Thread.sleep(5000);
}
}
}
The easiest way to handle the Authentication Pop up is to enter the Credentials in Url Itself. For Example, I have Credentials like Username: admin and Password: admin:
WebDriver driver = new ChromeDriver();
driver.get("https://admin:admin#your website url");
This is a solution for Python based selenium, after going through the source code (here).
I found this 3 steps as useful.
obj = driver.switch_to.alert
obj.send_keys(keysToSend="username\ue004password")
obj.accept()
Here \ue004 is the value for TAB which you can find in Keys class in the source code.
I guess the same approach can be used in JAVA as well but not sure.
My usecase is:
Navigate to webapp.
Webapp detects I am not logged in, and redirects to an SSO site - different server!
SSO site (maybe on Jenkins) detects I am not logged into AD, and shows a login popup.
After you enter credentials, you are redirected back to webapp.
I am on later versions of Selenium 3, and the login popup is not detected with driver.switchTo().alert(); - results in NoAlertPresentException.
Just providing username:password in the URL is not propagated from step 1 to 2 above.
My workaround:
import org.apache.http.client.utils.URIBuilder;
driver.get(...webapp_location...);
wait.until(ExpectedConditions.urlContains(...sso_server...));
URIBuilder uri = null;
try {
uri = new URIBuilder(driver.getCurrentUrl());
} catch (URISyntaxException ex) {
ex.printStackTrace();
}
uri.setUserInfo(username, password);
driver.navigate().to(uri.toString());
You can use this Autoit script to handle the login popup:
WinWaitActive("Authentication Required","","10")
If WinExists("Authentication Required") Then
Send("username{TAB}")
Send("Password{Enter}")
EndIf'
I was getting windows security alert whenever my application was opening. to resolve this issue i used following procedure
import org.openqa.selenium.security.UserAndPassword;
UserAndPassword UP = new UserAndPassword("userName","Password");
driver.switchTo().alert().authenticateUsing(UP);
this resolved my issue of logging into application. I hope this might help who are all looking for authenticating windows security alert.
Simply switch to alert and use authenticateUsing to set usename and password and then comeback to parent window
Alert Windowalert = driver.switchTo().alert() ;
Windowalert.authenticateUsing(new UserAndPassword(_user_name,_password));
driver.switchTo().defaultContent() ;
1 way to handle this you can provide login details with url. e.g. if your url is "http://localhost:4040" and it's asking "Username" and "Password" on alert prompt message then you can pass baseurl as "http://username:password#localhost:4040".
Hope it works
In C# Selenium Web Driver I have managed to get it working with the following code:
var alert = TestDriver.SwitchTo().Alert();
alert.SendKeys(CurrentTestingConfiguration.Configuration.BasicAuthUser + Keys.Tab + CurrentTestingConfiguration.Configuration.BasicAuthPassword);
alert.Accept();
Although it seems similar, the following did not work with Firefox (Keys.Tab resets all the form and the password will be written within the user field):
alert.SendKeys(CurrentTestingConfiguration.Configuration.BasicAuthUser);
alert.SendKeys(Keys.Tab);
alert.SendKeys(CurrentTestingConfiguration.Configuration.BasicAuthPassword);
Also, I have tried the following solution which resulted in exception:
var alert = TestDriver.SwitchTo().Alert();
alert.SetAuthenticationCredentials(
CurrentTestingConfiguration.Configuration.BasicAuthUser,
CurrentTestingConfiguration.Configuration.BasicAuthPassword);
System.NotImplementedException: 'POST
/session/38146c7c-cd1a-42d8-9aa7-1ac6837e64f6/alert/credentials did
not match a known command'
Types of popups are defined in webdriver alerts: https://www.selenium.dev/documentation/webdriver/browser/alerts/
Here it is another type - authentication popup - eg generated by Weblogic and not seen by Selenium.
Being HTTPS the user/pass can't be put directly in the URL.
The solution is to create a browser extension: packed or unpacked.
Here is the code for unpacked and the packing procedure: https://qatestautomation.com/2019/11/11/handle-authentication-popup-in-chrome-with-selenium-webdriver-using-java/
In manifest.json instead of “https://ReplaceYourCompanyUrl“ put “<all_urls>”.
Unpacked can be used directly in Selenium:
#python:
co=webdriver.ChromeOptions()
co.add_argument("load-extension=ExtensionFolder")
<all_urls> is a match pattern
The flow for requests is in https://developer.chrome.com/docs/extensions/reference/webRequest/
We can also update browser setting to consider logged in user -
Internet Options-> Security -> Security Settings-> Select Automatic login with current user name and password.
The following Selenium-Webdriver Java code should work well to handle the alert/pop up up window:
driver.switchTo().alert();
//Selenium-WebDriver Java Code for entering Username & Password as below:
driver.findElement(By.id("userID")).sendKeys("userName");
driver.findElement(By.id("password")).sendKeys("myPassword");
driver.switchTo().alert().accept();
driver.switchTo().defaultContent();
I used IE, then create code like that and works after modification several code:
public class TestIEBrowser {
public static void main(String[] args) throws Exception {
//Set path of IEDriverServer.exe.
// Note : IEDriverServer.exe should be In D: drive.
System.setProperty("webdriver.ie.driver", "path /IEDriverServer.exe");
// Initialize InternetExplorerDriver Instance.
WebDriver driver = new InternetExplorerDriver();
// Load sample calc test URL.
driver.get("http://... /");
//Code to handle Basic Browser Authentication in Selenium.
Alert aa = driver.switchTo().alert();
Robot a = new Robot();
aa.sendKeys("host"+"\\"+"user");
a.keyPress(KeyEvent.VK_TAB);
a.keyRelease(KeyEvent.VK_TAB);
a.keyRelease(KeyEvent.VK_ADD);
setClipboardData("password");
a.keyPress(KeyEvent.VK_CONTROL);
a.keyPress(KeyEvent.VK_V);
a.keyRelease(KeyEvent.VK_V);
a.keyRelease(KeyEvent.VK_CONTROL);
//Thread.sleep(5000);
aa.accept();
}
private static void setClipboardData(String string) {
// TODO Auto-generated method stub
StringSelection stringSelection = new StringSelection(string); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);
}
}

Resources