Integration of selenium grid with automation framework











up vote
0
down vote

favorite
2












Please Note:Kindly request the people not to mark this as duplicate or etc. Request everyone to read the question.



I have come across the task where I need to integrate the selenium grid in my automation framework:
I have the following classes:



DriverFactory
DriverManager


Apart from it, I have the drivers folder where I have defined the following things.



selenium standalone server jar
hub.json
node1.json
chromedriver.exe


DriverManager Class:



public class DriverManager {
public static ThreadLocal<WebDriver> driver = new ThreadLocal<>();

public static WebDriver getDriver() {
return driver.get();
}

public static void setDriver(WebDriver drive) {
driver.set(drive);
}

public static void removeDriver() {
if (driver.get() != null) {
driver.get().quit();
driver.remove();
}
}
}


Here I need to replace the WebDriver with RemoteWebDriver but when I do it I am facing an error.



DriverFactory Class:



public class DriverFactory {

public static WebDriver createInstance(String browser) {
if (browser.equals("chrome")) {

ChromeDriver driver = new ChromeDriver(getChromeOptions());

try {
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(100, TimeUnit.SECONDS);
}
catch (Exception e) {

}
return driver;
}
return null;
}

public static void killBrowserInstance(String browser) throws InterruptedException {
try {


if (browser.equals("chrome")) {

if (OsUtils.isWindows()) {
Runtime.getRuntime().exec("taskkill /F /IM chromedriver.exe");
}
else {
Runtime.getRuntime().exec("killall "chromedriver"");
Runtime.getRuntime().exec("killall "Google Chrome"");
}
}

Thread.sleep(1000);
}
catch (IOException e) {
e.printStackTrace();
}
}

public static ChromeOptions getChromeOptions() {
if (OsUtils.isWindows()) {
System.setProperty("webdriver.chrome.driver", "Drivers/chromedriver.exe");
}
else {
System.setProperty("webdriver.chrome.driver", "Drivers/chromedriver");
}

ChromeOptions options = new ChromeOptions();
return options;
}
}


Kindly ignore the imports statement.
Please let me know if you required any more information, even able for a remote solution to it will be available for screen share.



Sample Test-Case:



 @Test
public void LoginValid() throws Throwable {
try {
loginpage.login(prop.getProperty("username"), prop.getProperty("password"));
// Logout
} catch (Exception e) {
Logz.step(LogStatus.FAIL, "Unable to Login");
e.printStackTrace();
throw e;
}

}


When I trigger the testng,internally calls are happenning where the driver initialiation and instance is created.



 public synchronized void onTestStart(ITestResult iTestResult)
DriverManager.setDriver(DriverFactory.createInstance(iTestResult.getTestContext().getCurrentXmlTest().getLocalParameters().get("browser")));
}









share|improve this question




















  • 1




    Please also share the test-case ,let us understand the framework flow.
    – shaik
    Nov 9 at 17:59










  • @shaik yep added the test-case and the internal calls before executing the test-case.
    – khan
    Nov 9 at 18:07










  • @all Can someone please have a look into it.
    – khan
    Nov 10 at 5:27










  • I suggest to create external boolean parameter which sets the Grid to true or false. You can properties files to do that, by your explanation I see you want to change the webdriver to remotewebdriver after you created the instance, I don't think this is how you implement the grid.
    – Nael Abd eljawad
    Nov 11 at 6:26












  • Code snippet please and actually I want to replace the web driver with remote web driver,bcoz for implementation of gridnwe need to use the web driver
    – khan
    Nov 11 at 16:27















up vote
0
down vote

favorite
2












Please Note:Kindly request the people not to mark this as duplicate or etc. Request everyone to read the question.



I have come across the task where I need to integrate the selenium grid in my automation framework:
I have the following classes:



DriverFactory
DriverManager


Apart from it, I have the drivers folder where I have defined the following things.



selenium standalone server jar
hub.json
node1.json
chromedriver.exe


DriverManager Class:



public class DriverManager {
public static ThreadLocal<WebDriver> driver = new ThreadLocal<>();

public static WebDriver getDriver() {
return driver.get();
}

public static void setDriver(WebDriver drive) {
driver.set(drive);
}

public static void removeDriver() {
if (driver.get() != null) {
driver.get().quit();
driver.remove();
}
}
}


Here I need to replace the WebDriver with RemoteWebDriver but when I do it I am facing an error.



DriverFactory Class:



public class DriverFactory {

public static WebDriver createInstance(String browser) {
if (browser.equals("chrome")) {

ChromeDriver driver = new ChromeDriver(getChromeOptions());

try {
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(100, TimeUnit.SECONDS);
}
catch (Exception e) {

}
return driver;
}
return null;
}

public static void killBrowserInstance(String browser) throws InterruptedException {
try {


if (browser.equals("chrome")) {

if (OsUtils.isWindows()) {
Runtime.getRuntime().exec("taskkill /F /IM chromedriver.exe");
}
else {
Runtime.getRuntime().exec("killall "chromedriver"");
Runtime.getRuntime().exec("killall "Google Chrome"");
}
}

Thread.sleep(1000);
}
catch (IOException e) {
e.printStackTrace();
}
}

public static ChromeOptions getChromeOptions() {
if (OsUtils.isWindows()) {
System.setProperty("webdriver.chrome.driver", "Drivers/chromedriver.exe");
}
else {
System.setProperty("webdriver.chrome.driver", "Drivers/chromedriver");
}

ChromeOptions options = new ChromeOptions();
return options;
}
}


Kindly ignore the imports statement.
Please let me know if you required any more information, even able for a remote solution to it will be available for screen share.



Sample Test-Case:



 @Test
public void LoginValid() throws Throwable {
try {
loginpage.login(prop.getProperty("username"), prop.getProperty("password"));
// Logout
} catch (Exception e) {
Logz.step(LogStatus.FAIL, "Unable to Login");
e.printStackTrace();
throw e;
}

}


When I trigger the testng,internally calls are happenning where the driver initialiation and instance is created.



 public synchronized void onTestStart(ITestResult iTestResult)
DriverManager.setDriver(DriverFactory.createInstance(iTestResult.getTestContext().getCurrentXmlTest().getLocalParameters().get("browser")));
}









share|improve this question




















  • 1




    Please also share the test-case ,let us understand the framework flow.
    – shaik
    Nov 9 at 17:59










  • @shaik yep added the test-case and the internal calls before executing the test-case.
    – khan
    Nov 9 at 18:07










  • @all Can someone please have a look into it.
    – khan
    Nov 10 at 5:27










  • I suggest to create external boolean parameter which sets the Grid to true or false. You can properties files to do that, by your explanation I see you want to change the webdriver to remotewebdriver after you created the instance, I don't think this is how you implement the grid.
    – Nael Abd eljawad
    Nov 11 at 6:26












  • Code snippet please and actually I want to replace the web driver with remote web driver,bcoz for implementation of gridnwe need to use the web driver
    – khan
    Nov 11 at 16:27













up vote
0
down vote

favorite
2









up vote
0
down vote

favorite
2






2





Please Note:Kindly request the people not to mark this as duplicate or etc. Request everyone to read the question.



I have come across the task where I need to integrate the selenium grid in my automation framework:
I have the following classes:



DriverFactory
DriverManager


Apart from it, I have the drivers folder where I have defined the following things.



selenium standalone server jar
hub.json
node1.json
chromedriver.exe


DriverManager Class:



public class DriverManager {
public static ThreadLocal<WebDriver> driver = new ThreadLocal<>();

public static WebDriver getDriver() {
return driver.get();
}

public static void setDriver(WebDriver drive) {
driver.set(drive);
}

public static void removeDriver() {
if (driver.get() != null) {
driver.get().quit();
driver.remove();
}
}
}


Here I need to replace the WebDriver with RemoteWebDriver but when I do it I am facing an error.



DriverFactory Class:



public class DriverFactory {

public static WebDriver createInstance(String browser) {
if (browser.equals("chrome")) {

ChromeDriver driver = new ChromeDriver(getChromeOptions());

try {
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(100, TimeUnit.SECONDS);
}
catch (Exception e) {

}
return driver;
}
return null;
}

public static void killBrowserInstance(String browser) throws InterruptedException {
try {


if (browser.equals("chrome")) {

if (OsUtils.isWindows()) {
Runtime.getRuntime().exec("taskkill /F /IM chromedriver.exe");
}
else {
Runtime.getRuntime().exec("killall "chromedriver"");
Runtime.getRuntime().exec("killall "Google Chrome"");
}
}

Thread.sleep(1000);
}
catch (IOException e) {
e.printStackTrace();
}
}

public static ChromeOptions getChromeOptions() {
if (OsUtils.isWindows()) {
System.setProperty("webdriver.chrome.driver", "Drivers/chromedriver.exe");
}
else {
System.setProperty("webdriver.chrome.driver", "Drivers/chromedriver");
}

ChromeOptions options = new ChromeOptions();
return options;
}
}


Kindly ignore the imports statement.
Please let me know if you required any more information, even able for a remote solution to it will be available for screen share.



Sample Test-Case:



 @Test
public void LoginValid() throws Throwable {
try {
loginpage.login(prop.getProperty("username"), prop.getProperty("password"));
// Logout
} catch (Exception e) {
Logz.step(LogStatus.FAIL, "Unable to Login");
e.printStackTrace();
throw e;
}

}


When I trigger the testng,internally calls are happenning where the driver initialiation and instance is created.



 public synchronized void onTestStart(ITestResult iTestResult)
DriverManager.setDriver(DriverFactory.createInstance(iTestResult.getTestContext().getCurrentXmlTest().getLocalParameters().get("browser")));
}









share|improve this question















Please Note:Kindly request the people not to mark this as duplicate or etc. Request everyone to read the question.



I have come across the task where I need to integrate the selenium grid in my automation framework:
I have the following classes:



DriverFactory
DriverManager


Apart from it, I have the drivers folder where I have defined the following things.



selenium standalone server jar
hub.json
node1.json
chromedriver.exe


DriverManager Class:



public class DriverManager {
public static ThreadLocal<WebDriver> driver = new ThreadLocal<>();

public static WebDriver getDriver() {
return driver.get();
}

public static void setDriver(WebDriver drive) {
driver.set(drive);
}

public static void removeDriver() {
if (driver.get() != null) {
driver.get().quit();
driver.remove();
}
}
}


Here I need to replace the WebDriver with RemoteWebDriver but when I do it I am facing an error.



DriverFactory Class:



public class DriverFactory {

public static WebDriver createInstance(String browser) {
if (browser.equals("chrome")) {

ChromeDriver driver = new ChromeDriver(getChromeOptions());

try {
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(100, TimeUnit.SECONDS);
}
catch (Exception e) {

}
return driver;
}
return null;
}

public static void killBrowserInstance(String browser) throws InterruptedException {
try {


if (browser.equals("chrome")) {

if (OsUtils.isWindows()) {
Runtime.getRuntime().exec("taskkill /F /IM chromedriver.exe");
}
else {
Runtime.getRuntime().exec("killall "chromedriver"");
Runtime.getRuntime().exec("killall "Google Chrome"");
}
}

Thread.sleep(1000);
}
catch (IOException e) {
e.printStackTrace();
}
}

public static ChromeOptions getChromeOptions() {
if (OsUtils.isWindows()) {
System.setProperty("webdriver.chrome.driver", "Drivers/chromedriver.exe");
}
else {
System.setProperty("webdriver.chrome.driver", "Drivers/chromedriver");
}

ChromeOptions options = new ChromeOptions();
return options;
}
}


Kindly ignore the imports statement.
Please let me know if you required any more information, even able for a remote solution to it will be available for screen share.



Sample Test-Case:



 @Test
public void LoginValid() throws Throwable {
try {
loginpage.login(prop.getProperty("username"), prop.getProperty("password"));
// Logout
} catch (Exception e) {
Logz.step(LogStatus.FAIL, "Unable to Login");
e.printStackTrace();
throw e;
}

}


When I trigger the testng,internally calls are happenning where the driver initialiation and instance is created.



 public synchronized void onTestStart(ITestResult iTestResult)
DriverManager.setDriver(DriverFactory.createInstance(iTestResult.getTestContext().getCurrentXmlTest().getLocalParameters().get("browser")));
}






selenium selenium-webdriver selenium-chromedriver selenium-grid selenium-grid2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 18:25

























asked Nov 9 at 17:56









khan

352215




352215








  • 1




    Please also share the test-case ,let us understand the framework flow.
    – shaik
    Nov 9 at 17:59










  • @shaik yep added the test-case and the internal calls before executing the test-case.
    – khan
    Nov 9 at 18:07










  • @all Can someone please have a look into it.
    – khan
    Nov 10 at 5:27










  • I suggest to create external boolean parameter which sets the Grid to true or false. You can properties files to do that, by your explanation I see you want to change the webdriver to remotewebdriver after you created the instance, I don't think this is how you implement the grid.
    – Nael Abd eljawad
    Nov 11 at 6:26












  • Code snippet please and actually I want to replace the web driver with remote web driver,bcoz for implementation of gridnwe need to use the web driver
    – khan
    Nov 11 at 16:27














  • 1




    Please also share the test-case ,let us understand the framework flow.
    – shaik
    Nov 9 at 17:59










  • @shaik yep added the test-case and the internal calls before executing the test-case.
    – khan
    Nov 9 at 18:07










  • @all Can someone please have a look into it.
    – khan
    Nov 10 at 5:27










  • I suggest to create external boolean parameter which sets the Grid to true or false. You can properties files to do that, by your explanation I see you want to change the webdriver to remotewebdriver after you created the instance, I don't think this is how you implement the grid.
    – Nael Abd eljawad
    Nov 11 at 6:26












  • Code snippet please and actually I want to replace the web driver with remote web driver,bcoz for implementation of gridnwe need to use the web driver
    – khan
    Nov 11 at 16:27








1




1




Please also share the test-case ,let us understand the framework flow.
– shaik
Nov 9 at 17:59




Please also share the test-case ,let us understand the framework flow.
– shaik
Nov 9 at 17:59












@shaik yep added the test-case and the internal calls before executing the test-case.
– khan
Nov 9 at 18:07




@shaik yep added the test-case and the internal calls before executing the test-case.
– khan
Nov 9 at 18:07












@all Can someone please have a look into it.
– khan
Nov 10 at 5:27




@all Can someone please have a look into it.
– khan
Nov 10 at 5:27












I suggest to create external boolean parameter which sets the Grid to true or false. You can properties files to do that, by your explanation I see you want to change the webdriver to remotewebdriver after you created the instance, I don't think this is how you implement the grid.
– Nael Abd eljawad
Nov 11 at 6:26






I suggest to create external boolean parameter which sets the Grid to true or false. You can properties files to do that, by your explanation I see you want to change the webdriver to remotewebdriver after you created the instance, I don't think this is how you implement the grid.
– Nael Abd eljawad
Nov 11 at 6:26














Code snippet please and actually I want to replace the web driver with remote web driver,bcoz for implementation of gridnwe need to use the web driver
– khan
Nov 11 at 16:27




Code snippet please and actually I want to replace the web driver with remote web driver,bcoz for implementation of gridnwe need to use the web driver
– khan
Nov 11 at 16:27

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231016%2fintegration-of-selenium-grid-with-automation-framework%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231016%2fintegration-of-selenium-grid-with-automation-framework%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff