Avinash Pandey Avinash Pandey - 1 year ago 56
Java Question

org.openqa.selenium.remote.UnreachableBrowserException: - Error selenium Java TestNG

Below is the script which i am trying to use to add a new user -

package pages;

import static org.testng.AssertJUnit.assertEquals;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.openqa.selenium.support.ui.Select;
import appSetup_Maven.test.BaseClass;
import appSetup_Maven.test.GenerateData;

public class AddCustomer extends BaseClass {

@BeforeMethod
public void before() {
new GenerateData();
}

@Test(priority = 0)

public void addCustomerPageNavigation() throws IOException, InterruptedException {
Login();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[@id='sidebar-menu']/ul/li[3]/a/span[1]")).click();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[@id='sidebar-menu']/ul/li[3]/ul/li[1]/a")).click();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(
By.xpath(".//*[@id='wrapper']/div[3]/div/div[2]/div/div/div/div[1]/div/div[1]/div/div/button")).click();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(
By.xpath(".//*[@id='wrapper']/div[3]/div/div[2]/div/div/div/div[1]/div/div[1]/div/div/ul/li/a"))
.click();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id='Organization_org_name']"))
.sendKeys(GenerateData.generateRandomAlphaNumeric(30));
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[@id='Organization_org_trading_name']"))
.sendKeys(GenerateData.generateRandomString(20));
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[@id='Organization_org_number']"))
.sendKeys(GenerateData.generateRandomNumber(10));
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[@id='Organization_phone_number']"))
.sendKeys(GenerateData.generateRandomString(20));
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

//WebElement ListCountry = driver.findElement(By.xpath(".//*[@id='Organization_fk_country_codes_id']"));
//Select country = new Select(ListCountry);
//country.deselectByVisibleText("India");

//WebElement ListState = driver.findElement(By.xpath(".//*[@id='Organization_fk_country_codes_id']"));
//Select state = new Select(ListState);
//country.deselectByVisibleText("Assam");

driver.findElement(By.xpath(".//*[@id='Organization_address_street']']"))
.sendKeys(GenerateData.generateRandomString(20));
driver.findElement(By.xpath(".//*[@id='Organization_address_line2']"))
.sendKeys(GenerateData.generateRandomString(20));
driver.findElement(By.xpath(".//*[@id='Organization_address_suburb']"))
.sendKeys(GenerateData.generateRandomString(20));
driver.findElement(By.xpath(".//*[@id='Organization_address_postalcode']"))
.sendKeys(GenerateData.generateRandomString(20));

//WebElement NumEmp = driver.findElement(By.xpath(".//*[@id='Organization_numberOfEmployees']"));
//Select Emp = new Select(NumEmp);
//country.deselectByVisibleText("5-10");

//WebElement NumUsr = driver.findElement(By.xpath(".//*[@id='Organization_totalUserSize']"));
//Select Usr = new Select(NumUsr);
//country.deselectByVisibleText("5-10");

driver.findElement(By.xpath(".//*.//*[@id='Organization_domain_name']"))
.sendKeys(GenerateData.generateRandomString(20));
driver.findElement(By.xpath(".//*[@id='Users_first_name']")).sendKeys(GenerateData.generateRandomString(20));
driver.findElement(By.xpath(".//*[@id='Users_last_name']")).sendKeys(GenerateData.generateRandomString(20));

WebElement Role = driver.findElement(By.xpath(".//*[@id='Users_fk_business_role_id']"));
Select Usrrole = new Select(Role);
//country.deselectByVisibleText("Other");

driver.findElement(By.xpath(".//*[@id='Users_username']")).sendKeys(GenerateData.generateRandomString(20));
driver.findElement(By.xpath(".//*[@id='confirm-username']")).sendKeys(GenerateData.generateRandomString(20));
driver.findElement(By.xpath(".//*[@id='Users_password']"))
.sendKeys(GenerateData.generateRandomAlphaNumeric(30));
driver.findElement(By.xpath(".//*[@id='re-password']")).sendKeys(GenerateData.generateRandomAlphaNumeric(30)); // fail

WebElement rListCountry = driver.findElement(By.xpath(".//*[@id='Organization_fk_country_codes_id']"));
Select ccountry = new Select(rListCountry);
//country.deselectByVisibleText("India");

WebElement TimeZone = driver.findElement(By.xpath(".//*[@id='Organization_fk_country_codes_id']"));
Select Time = new Select(TimeZone);
//country.deselectByVisibleText("Asia/Kolkata");
driver.findElement(By.xpath(".//*[@id='OrganizationBillingDetails_first_name']"))
.sendKeys(GenerateData.generateRandomAlphaNumeric(30));
driver.findElement(By.xpath(".//*[@id='OrganizationBillingDetails_last_name']"))
.sendKeys(GenerateData.generateRandomAlphaNumeric(30));
driver.findElement(By.xpath(".//*[@id='OrganizationBillingDetails_email']"))
.sendKeys(GenerateData.generateEmail(10));
driver.findElement(By.xpath(".//*[@id='users-form']/div/div/div[5]/div/h2/div/ins"))
.sendKeys(GenerateData.generateEmail(10));

WebElement dListCountry = driver
.findElement(By.xpath(".//*[@id='OrganizationBillingDetails_fk_country_codes_id']"));
Select acountry = new Select(dListCountry);
//country.deselectByVisibleText("India");

WebElement aListState = driver
.findElement(By.xpath(".//*[@id='OrganizationBillingDetails_fk_country_subdivisions_id']"));
Select astate = new Select(aListState);
//country.deselectByVisibleText("Assam");

driver.findElement(By.xpath(".//*[@id='OrganizationBillingDetails_street']"))
.sendKeys(GenerateData.generateRandomAlphaNumeric(30));
driver.findElement(By.xpath(".//*[@id='OrganizationBillingDetails_address_line2']"))
.sendKeys(GenerateData.generateRandomAlphaNumeric(30));
driver.findElement(By.xpath(".//*[@id='OrganizationBillingDetails_city']"))
.sendKeys(GenerateData.generateRandomAlphaNumeric(30));
driver.findElement(By.xpath(".//*[@id='OrganizationBillingDetails_postal_code']"))
.sendKeys(GenerateData.generateRandomAlphaNumeric(30));
driver.findElement(By.xpath(".//*[@id='users-form']/div/div/div[7]/div[2]/div[2]/input[1]")).click();
assertEquals("Success", driver.getTitle());

}

}


Below is the class that I am using for generating random data -

package appSetup_Maven.test;

import org.apache.commons.lang3.RandomStringUtils;

public class GenerateData {

public static String generateRandomString(int length) {
return RandomStringUtils.randomAlphabetic(length);
}

public static String generateRandomNumber(int length) {
return RandomStringUtils.randomNumeric(length);
}

public static String generateRandomAlphaNumeric(int length) {
return RandomStringUtils.randomAlphanumeric(length);
}

public static String generateStringWithAllobedSplChars(int length, String allowdSplChrs) {
String allowedChars = "abcdefghijklmnopqrstuvwxyz" + // alphabets
"1234567890" + // numbers
allowdSplChrs;
return RandomStringUtils.random(length, allowedChars);
}

public static String generateEmail(int length) {
String allowedChars = "abcdefghijklmnopqrstuvwxyz" + // alphabets
"1234567890" + // numbers
"_-."; // special characters
String email = "";
String temp = RandomStringUtils.random(length, allowedChars);
email = temp.substring(0, temp.length() - 9) + "@test.org";
return email;
}

public String generateUrl(int length) {
String allowedChars = "abcdefghijklmnopqrstuvwxyz" + // alphabets
"1234567890" + // numbers
"_-."; // special characters
String url = "";
String temp = RandomStringUtils.random(length, allowedChars);
url = temp.substring(0, 3) + "." + temp.substring(4, temp.length() - 4) + "."
+ temp.substring(temp.length() - 3);
return url;
}
}


Error message that I am getting same as the title but below are the exact stack trace -


Tests run: 15, Failures: 1, Errors: 0, Skipped: 0, Time elapsed:
115.588 sec <<< FAILURE! - in TestSuite
addCustomerPageNavigation(pages.AddCustomer) Time elapsed: 4.641 sec <<< FAILURE!
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.45.0', revision: '5017cb8e7ca8e37638dc3091b2440b90a1d8686f', time: '2015-02-27
09:10:26'
System info: host: 'DESKTOP-1AKPPH7', ip: '192.168.56.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version:
'1.8.0_111'
Driver info: driver.version: FirefoxDriver
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:72)
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:125)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:319)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:126)
at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:72)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:133)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:165)
at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:362)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:572)
at org.openqa.selenium.firefox.FirefoxDriver.access$100(FirefoxDriver.java:73)
at org.openqa.selenium.firefox.FirefoxDriver$1$1.implicitlyWait(FirefoxDriver.java:219)
at pages.AddCustomer.addCustomerPageNavigation(AddCustomer.java:28)

Results :

Failed tests:
AddCustomer.addCustomerPageNavigation:28 ยป UnreachableBrowser Error communicat...

Tests run: 15, Failures: 1, Errors: 0, Skipped: 0



Questions -

1. How do I fix the above error and why and in which case do we get this error.

2. There are issues in this script, such as the randomly generated e-mails don't match, How can I do fix this ?

Answer Source

You didn't provide the code for Login() but I'm guessing you have driver.close() or driver.quit() there or in other place between the driver initialization and

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download