Tuesday, 31 October 2017

Run Selenium Grid On Cloud (Browser Stack)

Exported from Notepad++
package com.SeleniumGridByCloud; import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class RunSeleniumGridOnCloud { public WebDriver driver; public static final String USERNAME= "USERNAME"; public static final String AUTOMATE_KEY= "ACCESS_KEY"; public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub"; @BeforeClass public void setUp() { try { DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("browser", "IE"); caps.setCapability("browser_version", "10.0"); caps.setCapability("os", "Windows"); caps.setCapability("os_version", "XP"); caps.setCapability("browserstack.debug", "true"); driver = new RemoteWebDriver(new URL(URL), caps); } catch (MalformedURLException e) { e.printStackTrace(); } } @Test public void testSeleniumGridOnFirefox() { try { driver.manage().deleteAllCookies(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(35, TimeUnit.SECONDS); driver.get("https://seleniumcodeexample.blogspot.in"); System.out.println("Title Name is : " + driver.getTitle()); } catch (Exception e) { e.printStackTrace(); } } @AfterClass public void tearDown() throws InterruptedException { Thread.sleep(2000); driver.quit(); } }

Run Selenium Grid On Internet Explorer Browser

Exported from Notepad++
package com.seleniumGrid; import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver; import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class RunSeleniumGridOnIE { WebDriver driver; String nodeUrl = "http://192.168.3.12:5555/wd/hub"; @BeforeClass public void setUp() { try { DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_
IGNORING_SECURITY_DOMAINS
, true); driver = new RemoteWebDriver(new URL(nodeUrl), capabilities); } catch (MalformedURLException e) { e.printStackTrace(); } } @Test public void testSeleniumGridOnIE() { try { driver.manage().deleteAllCookies(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES); driver.get("https://seleniumcodeexample.blogspot.in"); System.out.println("Title Name is : " + driver.getTitle()); } catch (Exception e) { e.printStackTrace(); } } @AfterClass public void tearDown() throws InterruptedException { Thread.sleep(2000); driver.quit(); } }

Run Selenium Grid On Firefox Browser

Exported from Notepad++
package com.seleniumGrid; import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.TimeUnit; import org.openqa.selenium.Platform; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class RunSeleniumGridOnFirefox { WebDriver driver; String nodeUrl = "http://192.168.3.12:1712/wd/hub"; @BeforeClass public void setUp() { try { DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setBrowserName("firefox"); capabilities.setPlatform(Platform.WINDOWS); driver = new RemoteWebDriver(new URL(nodeUrl), capabilities); } catch (MalformedURLException e) { e.printStackTrace(); } } @Test public void testSeleniumGridOnFirefox() { try { driver.manage().deleteAllCookies(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(35, TimeUnit.SECONDS); driver.get("https://seleniumcodeexample.blogspot.in"); System.out.println("Title Name is : " + driver.getTitle()); } catch (Exception e) { e.printStackTrace(); } } @AfterClass public void tearDown() throws InterruptedException { Thread.sleep(2000); driver.quit(); } }

Run Selenium Grid On Chrome Browser

Exported from Notepad++
package com.seleniumGrid; import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.TimeUnit; import org.openqa.selenium.Platform; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class RunSeleniumGridOnChrome { WebDriver driver; String nodeUrl = "http://192.168.3.12:1719/wd/hub"; @BeforeClass public void setUp() { try { DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setBrowserName("chrome"); capabilities.setPlatform(Platform.WINDOWS); driver = new RemoteWebDriver(new URL(nodeUrl), capabilities); } catch (MalformedURLException e) { e.printStackTrace(); } } @Test public void testSeleniumGridOnChrome() { try { driver.manage().deleteAllCookies(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(35, TimeUnit.SECONDS); driver.get("https://seleniumcodeexample.blogspot.in"); System.out.println("Title Name is : " + driver.getTitle()); } catch (Exception e) { e.printStackTrace(); } } @AfterClass public void tearDown() throws InterruptedException { Thread.sleep(2000); driver.quit(); } }

Steps to Run Selenium Grid Hub and Node (Window7 OS)

There are some steps to start the Hub(Server) and then register the Node(OS) with Hub.

 Step: 1


Step: 2




@@@@@@@@@@@@@@     Run this Command for Hub @@@@@@@@@@@@@@
java -jar selenium-server-standalone-3.6.0.jar -role hub

========================================================================

@@@@  Run this Command for Node Configure with Chrome Browser in Window OS @@@@

java -Dwebdriver.chrome.driver=D:\SeleniumGrid\drivers\chromedriver.exe -jar selenium-server-standalone-3.6.0.jar -role node -hub http://192.168.3.12:4444/grid/register -browser browserName=chrome -port 5555

========================================================================

@@@@  Run this Command for Node Configure with Firefox Browser in Window OS @@@@

java -Dwebdriver.geckodriver.driver=D:\SeleniumGrid\drivers\geckodriver.exe -jar selenium-server-standalone-3.6.0.jar -role node -hub http://192.168.3.12:4444/grid/register -browser browserName=firefox -port 5555

========================================================================

@@@@@ Run this Command for Node Configure with IE Browser in Window OS @@@@@

java -Dwebdriver.ie.driver=D:\SeleniumGrid\drivers\IEDriverServer.exe -jar selenium-server-standalone-3.6.0.jar -role node -hub http://192.168.3.12:4444/grid/register -browser browserName=ie -port 5555

========================================================================

 Run this Command for Node Configure with both firfox,ie and Chrome Browser in Window OS 

java -Dwebdriver.chrome.driver=D:\SeleniumGrid\drivers\chromedriver.exe -Dwebdriver.gecko.driver=D:\SeleniumGrid\drivers\geckodriver.exe -Dwebdriver.ie.driver=D:\SeleniumGrid\drivers\IEDriverServer.exe 
-jar selenium-server-standalone-3.6.0.jar -role node -hub http://192.168.3.12:4444/grid/register



Tuesday, 17 October 2017

Code Example - Disable Save Password Extension In Chrome Browser

Exported from Notepad++
package com.practiceCode; import java.util.HashMap; import java.util.Map; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; /** * @Blog Name: Selenium Code Example * @author Deepak Gupta * @Created Date 17-10-2017 * */ public class DisableSavePasswordExtensionInChromeBrowser { WebDriver driver; @BeforeTest public void setUp() { try { System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") +
"/drivers/chromedriver.exe"); // Handle - disable the save password Extension ChromeOptions options = new ChromeOptions(); Map<String, Object> prefs = new HashMap<String, Object>(); prefs.put("credentials_enable_service", false); prefs.put("profile.password_manager_enabled", false); options.setExperimentalOption("prefs", prefs); driver = new ChromeDriver(options); } catch (Exception e) { e.printStackTrace(); } } @Test public void testDisableSavePasswordExtensionInChromeBrowser() { driver.get("https://www.google.co.in"); } @AfterTest public void tearDown() throws InterruptedException { driver.quit(); } }

Monday, 16 October 2017

Code Example - Disable SSL Certificate In Chrome Browser

Exported from Notepad++
package com.practiceCode; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; /** * @Blog Name: Selenium Code Example * @author Deepak Gupta * @Created Date 17-10-2017 * */ public class DisableSSLCertificateInChromeBrowser { WebDriver driver; @BeforeTest public void setUp() { try { // Handle https - Your connection is not private DesiredCapabilities dc = DesiredCapabilities.chrome(); dc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") +
"/drivers/chromedriver.exe"); driver = new ChromeDriver(); } catch (Exception e) { e.printStackTrace(); } } @Test public void testDisableSSLCertificateInChromeBrowser() { driver.get("https://www.google.co.in"); } @AfterTest public void tearDown() throws InterruptedException { driver.quit(); } }

Code Example - Disable Invalid Extension in Chrome Browser

Exported from Notepad++
package com.practiceCode; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; /** * @Blog Name: Selenium Code Example * @author Deepak Gupta * @Created Date 17-10-2017 * */ public class DisableInvalidExtensionInChromeBrowser { WebDriver driver; @BeforeTest public void setUp() { try { System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") +
"/drivers/chromedriver.exe"); // Handle - disable the invalid Extension ChromeOptions options = new ChromeOptions(); options.addArguments("disable-infobars"); driver = new ChromeDriver(options); } catch (Exception e) { e.printStackTrace(); } } @Test public void testDisableInvalidExtensionInChromeBrowser() { driver.get("https://www.google.co.in"); } @AfterTest public void tearDown() throws InterruptedException { driver.quit(); } }

Code Example - File Download By Robot Class In Firefox Browser

Exported from Notepad++ package com . practiceCode ; import java . awt . AWTException ; import java . awt . Robot ; import j...