Integration of selenium grid with automation framework
up vote
0
down vote
favorite
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
|
show 1 more comment
up vote
0
down vote
favorite
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
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
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
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
selenium selenium-webdriver selenium-chromedriver selenium-grid selenium-grid2
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
|
show 1 more comment
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
|
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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