org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 21:09:54'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_29'
Driver info: driver.version: RemoteWebDriver
This is the error message which gets displayed when I am trying to run my scripts?
Scenario :My one java file has login function and second has creation of a new Account after login
Kindly advise.
Login.java:
public class LoginPage
{
public static WebDriver driver;
public static final LoginPage login = new LoginPage(new FirefoxDriver());
public LoginPage(WebDriver driver)
{
LoginPage.driver = driver;
}
public static void loginAs(String username, String password)
{
DesiredCapabilities ieCapabilities = DesiredCapabilities.firefox();
ieCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
Proxy proxy = new Proxy();
proxy.setProxyAutoconfigUrl("http://www.config.barclays.co.uk:9000/");
driver.close();
ieCapabilities. setCapability(CapabilityType.PROXY, proxy);
FirefoxDriver driver = new FirefoxDriver(ieCapabilities);
driver.get("https://login.salesforce.com");
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
//Login to Salesforce Application
try
{
driver.findElement(By.id("username")).sendKeys(username);
driver.findElement(By.id("password")).sendKeys(password);
driver.findElement(By.id("Login")).click();
driver.manage().timeouts().implicitlyWait(75, TimeUnit.SECONDS);
}
catch(Exception e1)
{
System.out.println(e1 +"Your login attempt has failed. The username or password may be incorrect, or your location or login time may be restricted. Please contact the administrator at your company for help.");
}
}
public static void main(String[] args)
{
login.loginAs("me#example.com", "Pa$$word");
}
}
Second File where I am trying to click on Opportunity tab of my Sales force application :
CreatOpportunity.java these lines are under my main argument
LoginPage.login.loginAs("username", "password");
LoginPage.login.driver.findElement(By.id("Opportunity_Tab")).click();
Running my second file allows me to launch my application but does not detect the click on the Opprtunity tab and throws me the error mentioned above
just give a try with by putting below line after login.
driver.switchTo.defaultContent();
try with below code.
public class LoginPage {
public static WebDriver driver;
public LoginPage()
{
DesiredCapabilities ieCapabilities = DesiredCapabilities.firefox();
ieCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
Proxy proxy = new Proxy();
proxy.setProxyAutoconfigUrl("http://www.config.barclays.co.uk:9000/");
ieCapabilities. setCapability(CapabilityType.PROXY, proxy);
LoginPage.driver = new FirefoxDriver(ieCapabilities);
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
}
public static void loginAs(String username, String password) {
driver.get("https://login.salesforce.com");
//Login to Salesforce Application
try
{
driver.findElement(By.id("username")).sendKeys(username);
driver.findElement(By.id("password")).sendKeys(password);
driver.findElement(By.id("Login")).click();
driver.manage().timeouts().implicitlyWait(75, TimeUnit.SECONDS);
}
catch(Exception e1) {
System.out.println(e1 +"Your login attempt has failed. The username or password may be incorrect, or your location or login time may be restricted. Please contact the administrator at your company for help.");
}
}
public static void main(String[] args)
{
LoginPage login = new LoginPage();
login.loginAs("me#example.com", "Pa$$word");
FileTwo.clickOpportunity(driver);
}
}
FileTwo
public class FileTwo
{
public static void clickOpportunity(WebDriver driver)
throws Exception
{
driver.findElement(By.id("Opportunity_Tab")).click();
}
}
Selenium throws this error if you call quit() method & try to launch browser again. Workaround is use close() method instead of quit()
Related
`
public class CucumberHooks {
public static void main(String[] args) {
}
protected static WebDriver driver;
#Before
public void setup() throws IOException {
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("extension_5_3_2_0.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
String browser = ReadPropertyFileSingleton.getInstance().getProp("browser");
driver = Util.setEnvironmentAndGetDriver(browser);
assert driver != null;
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
public static WebDriver getDriver() {
return driver;
}
#After
public void close() {
driver.quit();
}}
The code where I added adblock extensions via crx file
When I run tests through a feature file, a regular browser without a blocker is launched
the browser is also launched already with a blocker, but it does not see the steps
what could be the problem and is it possible to use adblock this way?
The following is my code. One browser opens blank and another opens google.
I am using the latest version of chrome driver. Thanks in advance.
public class Trials {
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver","C:\\Selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com");
Thread.sleep(3000);
driver.close();
}
}
I have 3 classes - one for page locator, one for page action and the other one as script to execute the function. am getting nullpointer exception in main scripts where the function is called. Can anyone help me out, please!!!!.
The following are the code :
HomePageLocator.page
public class HomePageLocator{
WebDriver driver;
public HomePageLocator(WebDriver driver)
{
this.driver= driver;
}
#FindBy(xpath="//*[#id='header']/div[2]/div/div/nav/div[1]/a")
public WebElement signIn;
}
HomePageAction.page
public class HomePageAction{
public WebDriver driver;
public HomePageLocator homepageor;
public HomePageAction() {
this.homepage = new HomePageLocator(driver);
PageFactory.initElements(driver, this.homepage);
}
public void login() {
homepageor.signIn.click();
}
BaseTestCase.java
public class BaseTestCase {
public static Logger log = Logger.getLogger("devpinoyLogger");
public static void main(String[] args) throws Throwable {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"\\src\\test\\resources\\Executables\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://automationpractice.com/index.php");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Home page validation
HomePageAction homepageaction= new HomePageAction();
homepageaction.login();
}
Note : Am getting exception in line (homepageaction.login();)
the following is the exception logs :
Exception in thread "main" java.lang.NullPointerException
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
at com.sun.proxy.$Proxy3.click(Unknown Source)
at com.way2.Pages.actions.HomePage.login(HomePageAction.java:31)
at com.way2.Testcases.BaseTestCase.main(BaseTestCase.java:35)
You are creating the driver in main class, but not passing it to homepageAction
public static void main(String[] args) throws Throwable {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"\\src\\test\\resources\\Executables\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
Try to pass driver as
HomePageAction homepageaction= new HomePageAction(driver);
this.driver =driver
I had tried to run below JUnit (Selenium WebDriver) test case to open Google in Chrome browser, but it is failing with error message as
"The path to the ChromeDriver executable must be set by the
webdriver.chrome.driver system property; for more information, see
http://code.google.com/p/selenium/wiki/ChromeDriver."
As specified in that website, I downloaded ChromeDriver.exe but don't know,
Which PATH should I place that? or
How to set ChromeDriver path in webdriver.chrome.driver?
Please Advise.
My JUnit test case (changed the Firefox Driver to Chrome Driver):
import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.*;
public class Chrome_Open_Google {
private WebDriver driver;
private String baseUrl;
#Test
public void Test_Google_Chrome() throws Exception {
driver = new ChromeDriver();
baseUrl = "http://www.google.co.uk/";
driver.get(baseUrl);
}
#After
public void tearDown() throws Exception {
driver.quit();
}
}
I believe you have several options:
Either specify the folder (in which your chromedriver binary is) in your PATH system variable - here's how
Or give you application webdriver.chrome.driver as a system property by calling it with -Dwebdriver.chrome.driver=the/path/to/it parameter.
Or the same programatically: System.setProperty("webdriver.chrome.driver", "your/path/to/it");
Or this:
private static ChromeDriverService service;
private WebDriver driver;
#BeforeClass
public static void createAndStartService() {
service = new ChromeDriverService.Builder()
.usingChromeDriverExecutable(new File("path/to/my/chromedriver"))
.usingAnyFreePort()
.build();
service.start();
}
#Before
public void createDriver() {
driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome());
}
#After
public void tearDown() throws Exception {
driver.quit();
}
#AfterClass
public static void createAndStopService() {
service.stop();
}
System.setProperty("webdriver.chrome.driver", "your\path\to\it");
For Eg :
System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\driver\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
The error i got is : java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: Error while launching browser
The code i used is:
package Gmail;
import com.thoughtworks.selenium.*;
import junit.framework.TestCase;
public class Login extends TestCase{
public static DefaultSelenium selenium =new DefaultSelenium("localhost", 4444, "*iexplore ", "http://");
public static void gmailLogin()
{
try
{
selenium.start();
selenium.open("http://www.gmail.com");
selenium.type("Email", "<EmailID>");
selenium.type("Passwd", "<Password>");
selenium.click("signIn");
selenium.setTimeout("50000");
selenium.focus("//input[#name='Sign out']");
selenium.click("//input[#name='Sign out']");
selenium.setTimeout("50000");
}
catch (Exception E){System.out.println(E);}
selenium.stop();
}
public static void main(String[] args) {
gmailLogin();
}
}
Seems like there is an extra space after *iexplore in your code. Try this:
public static DefaultSelenium selenium =new DefaultSelenium("localhost", 4444, "*iexplore", "http://");