I am getting this error:
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.45.0', revision: '32a636c', time: '2015-03-05 22:01:35'
System info: host: 'HOME', ip: '10.1.11.121', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_31'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:593)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByName(RemoteWebDriver.java:425)
at org.openqa.selenium.By$ByName.findElement(By.java:299)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344)
at com.tests.TestClass2.test2(TestClass2.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:7055 [/127.0.0.1] failed: Connection refused: connect
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:140)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318)
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)
... 29 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
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:123)
... 44 more
My Environment:
OS: Windows 7
JDK: javac 1.8.0_31
FireFox: ESR 31.4.0
Eclipse: 4.4.2.20150219-0708
Selenium: selenium-2.45.0
Testng: 6.8.6.20141201_2240
I am using a Testing suite file to run 2 classes (TestClass1 & TestClass 2). It throws above error when invoking browser for 2nd class. Here is my complete Project
Base Class:
public class BaseClass {
public static WebDriver driver = new FirefoxDriver();
public static boolean implicitwait(long time) {
try {
driver.manage().timeouts().implicitlyWait(time, TimeUnit.SECONDS);
} catch (Exception e) {
return false;
}
return true;
}
#BeforeClass
public static boolean LaunchBrowser() throws InterruptedException {
implicitwait(50000);
try {
System.setProperty("webdriver.firefox.bin",
"C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
driver.navigate().to("https:google.com");
driver.manage().window().maximize();
implicitwait(5000);
} catch (Exception e) {
return false;
}
System.out.println("Launching Browser & Navigating To Page");
return true;
}
#AfterClass
public void CloseBrowser() {
driver.close();
System.out.println("Closing Browser");
}
}
Test Class:
#Test
public class TestClass extends BaseClass {
public void test1(){
System.out.println("TEST 1");
driver.findElement(By.name("q")).sendKeys("ABC");
driver.findElement(By.name("btnG")).click();
}
}
Test Class2
#Test
public class TestClass2 extends BaseClass {
public void test2(){
System.out.println("TEST 2");
driver.findElement(By.name("q")).sendKeys("DEF");
driver.findElement(By.name("btnG")).click();
}
}
I would super appreciate if someone can let me know what I am doing wrong
My Testng.xml:
<test name="Run Test Class In Firefox">
<classes>
<class name="com.tests.TestClass" />
<class name="com.tests.TestClass2" />
</classes>
</test>
Use #BeforeSuite and #AfterSuite instead of #BeforeClass and #AfterClass
#AfterClass
public void CloseBrowser() {
driver.close();
System.out.println("Closing Browser");
}
Basically closing the current browser instance after the first class and thus, the driver instance is not valid to run the tests for next class. You can test this by commenting out the #AfterClass
Reference
EDIT
Video
Gist
Related
I'm trying to run a test using Opera browser as a node, hub and node connections are succesful.
Below is for hub and node connections:
Hub > java -jar selenium-server-standalone-3.9.1.jar -role hub
Node > java -Dwebdriver.opera.driver=C:\zip\exe\operadriver_win64\operadriver_win64\operadriver.exe -jar selenium-server-standalone-3.9.1.jar -role node -hub http://192.168.1.10:4444/grid/register -port 5566
When trying to executing the program two Opera browser loads but only blank white pages shown with Not secure data:; on URL and I am also getting this kind of exception.
org.openqa.selenium.SessionNotCreatedException: Unable to create session from org.openqa.selenium.remote.NewSessionPayload#6153fbda
Opera driver and Opera Browser I'm using:
Opera Version: 82.0.4227.58
Opera Driver Version : 96.0.4664.45
Below is the code used:
package Grid;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
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.*;
public class OperaNode {
static WebDriver driver;
String nodeUrl;
#SuppressWarnings("deprecation")
#BeforeTest
public void OpenBrowser() throws InterruptedException {
try {
nodeUrl = "http://192.168.1.10:5566/wd/hub";
DesiredCapabilities capabilities = DesiredCapabilities.opera();
capabilities.setBrowserName("opera");
capabilities.setPlatform(Platform.WINDOWS);
driver = new RemoteWebDriver(new URL(nodeUrl), capabilities);
driver.manage();
driver.get("http://www.yahoo.com");
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Thread.sleep(2000);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
#Test
public void SigninButton() throws InterruptedException {
try {
driver.findElement(By.xpath("//a[#class='_yb_duqkn']")).click();
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
#AfterTest
public void CloseBrowser() {
driver.quit();
}
}
Below is the console Message:
FAILED CONFIGURATION: #BeforeTest OpenBrowser
org.openqa.selenium.SessionNotCreatedException: Unable to create session from org.openqa.selenium.remote.NewSessionPayload#6153fbda
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:28.403Z'
System info: host: 'DESKTOP-KML9RV5', ip: '192.168.1.10', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '16.0.2'
Driver info: driver.version: unknown
Command duration or timeout: 1.94 seconds
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129)
at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:138)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:155)
at Grid.OperaNode.OpenBrowser(OperaNode.java:36)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:385)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:321)
at org.testng.TestRunner.invokeTestConfigurations(TestRunner.java:637)
at org.testng.TestRunner.beforeRun(TestRunner.java:627)
at org.testng.TestRunner.run(TestRunner.java:589)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
at org.testng.SuiteRunner.run(SuiteRunner.java:276)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
at org.testng.TestNG.runSuites(TestNG.java:1063)
at org.testng.TestNG.run(TestNG.java:1031)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create session from org.openqa.selenium.remote.NewSessionPayload#6153fbda
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:28.403Z'
System info: host: 'DESKTOP-KML9RV5', ip: '192.168.1.10', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '16.0.2'
Driver info: driver.version: unknown
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:28.403Z'
System info: host: 'DESKTOP-KML9RV5', ip: '192.168.1.10', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '16.0.2'
Driver info: driver.version: unknown
at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$null$4(NewSessionPipeline.java:75)
at java.util.Optional.orElseThrow(Optional.java:403)
at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$createNewSession$5(NewSessionPipeline.java:74)
at java.util.Optional.orElseGet(Optional.java:364)
at org.openqa.selenium.remote.server.NewSessionPipeline.createNewSession(NewSessionPipeline.java:72)
at org.openqa.selenium.remote.server.commandhandler.BeginSession.execute(BeginSession.java:65)
at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0(WebDriverServlet.java:242)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.lang.Thread.run(Thread.java:831)
The RemoteWebDriver url configuration should always be routed to the hub, if using the Selenium Grid setup as your browser stack. The hub will then check for a node which matches your browser request and forward onto that node.
nodeUrl = "http://<hub ip address>:4444/wd/hub";
DesiredCapabilities capabilities = DesiredCapabilities.opera();
capabilities.setBrowserName("opera");
capabilities.setPlatform(Platform.WINDOWS);
driver = new RemoteWebDriver(new URL(nodeUrl), capabilities);
I am trying to perform basic selenium operations using page object pattern. However, when I run the test, I see browser being opened along with given url, but fails the test by complaining it couldn't initialise the declared web element. Can some one please help me to understand what I'm missing here. Below are my base class, page object class and test class.
BasePage
public class Basepage {
public static WebDriver driver;
public Basepage(){}
public Basepage(WebDriver driver){
this.driver = driver;
PageFactory.initElements(driver,this);
}
public void OpenBrowser(){
System.setProperty("webdriver.chrome.driver",
"C:\\SeleniumWork\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.navigate().to("https://www.google.com");
}
Page object class
public class SecurityMainPage extends Basepage{
public SecurityMainPage(WebDriver driver){
this.driver = driver;
PageFactory.initElements(driver,this);
}
#FindBy( xpath = "//a[text()='What We Do']")
WebElement dropdown;
public void selectOption(String option){
Actions actions = new Actions(driver);
actions.moveToElement(dropdown).click().build().perform(); //dropdown element is returning null
}
TestClass
public class SecurityMainPageTests extends Basepage {
protected static SecurityMainPage sec = new SecurityMainPage(driver);
public SecurityMainPageTests(){}
#BeforeTest
public void setup(){
OpenBrowser();
}
#Test
public void selectOptionTest(){
sec.selectOption("Networking");
}
#AfterTest
public void tearDown(){
closeBrowser();
}
Log
org.openqa.selenium.json.JsonException: java.lang.reflect.InvocationTargetException
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z'
System info: host: 'LAPTOP-5J2KPMM3', ip: '192.168.0.36', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.7'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.json.JsonOutput.convertUsingMethod(JsonOutput.java:302)
at org.openqa.selenium.json.JsonOutput.lambda$new$13(JsonOutput.java:139)
at org.openqa.selenium.json.JsonOutput$SafeBiConsumer.accept(JsonOutput.java:394)
at org.openqa.selenium.json.JsonOutput.write(JsonOutput.java:248)
at org.openqa.selenium.json.JsonOutput.lambda$null$18(JsonOutput.java:152)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.openqa.selenium.json.JsonOutput.lambda$new$19(JsonOutput.java:152)
at org.openqa.selenium.json.JsonOutput$SafeBiConsumer.accept(JsonOutput.java:394)
at org.openqa.selenium.json.JsonOutput.write(JsonOutput.java:248)
at org.openqa.selenium.json.JsonOutput.lambda$null$20(JsonOutput.java:161)
at com.google.common.collect.SingletonImmutableBiMap.forEach(SingletonImmutableBiMap.java:65)
at org.openqa.selenium.json.JsonOutput.lambda$new$21(JsonOutput.java:160)
at org.openqa.selenium.json.JsonOutput$SafeBiConsumer.accept(JsonOutput.java:394)
at org.openqa.selenium.json.JsonOutput.write(JsonOutput.java:248)
at org.openqa.selenium.json.JsonOutput.write(JsonOutput.java:239)
at org.openqa.selenium.json.Json.toJson(Json.java:42)
at org.openqa.selenium.remote.http.AbstractHttpCommandCodec.encode(AbstractHttpCommandCodec.java:227)
at org.openqa.selenium.remote.http.AbstractHttpCommandCodec.encode(AbstractHttpCommandCodec.java:117)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:152)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.perform(RemoteWebDriver.java:614)
at org.openqa.selenium.interactions.Actions$BuiltAction.perform(Actions.java:638)
at test.java.SecurityMainPage.selectOption(SecurityMainPage.java:37)
at test.java.SecurityMainPageTests.selectOptionTest(SecurityMainPageTests.java:28)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1191)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1116)
at org.testng.TestNG.run(TestNG.java:1024)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:110)
Suppressed: org.openqa.selenium.json.JsonException: Attempting to close incomplete json stream
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.json.JsonOutput.close(JsonOutput.java:263)
at org.openqa.selenium.json.Json.toJson(Json.java:44)
... 32 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.openqa.selenium.json.JsonOutput.convertUsingMethod(JsonOutput.java:298)
... 47 more
Caused by: 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.$Proxy9.getWrappedElement(Unknown Source)
at org.openqa.selenium.interactions.PointerInput$Origin.asArg(PointerInput.java:203)
at org.openqa.selenium.interactions.PointerInput$Move.encode(PointerInput.java:154)
at org.openqa.selenium.interactions.Sequence.encode(Sequence.java:75)
at org.openqa.selenium.interactions.Sequence.toJson(Sequence.java:84)
... 52 more
For easy understanding, I split the driver initiation and navigation to url to two methods in Basepage. And you haven't declared the closeBrowser() method.
Base Class
public class Basepage {
public static WebDriver driver;
public Basepage(){}
public Basepage(WebDriver driver){
this.driver = driver;
PageFactory.initElements(driver,this);
}
public WebDriver initiateDriver(){
System.setProperty("webdriver.chrome.driver",
"C:\\SeleniumWork\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
return driver;
}
public void openBrowser(String url){
driver.navigate().to(url);
}
}
Test Class
public class SecurityMainPageTests extends Basepage {
WebDriver driver = null;
protected static SecurityMainPage sec = null;
String url = "https://www.google.com";
public SecurityMainPageTests(){}
#BeforeTest
public void setup(){
driver = initiateDriver();
openBrowser(String url);
sec = new SecurityMainPage(driver);
}
#Test
public void selectOptionTest(){
sec.selectOption("Networking");
}
#AfterTest
public void tearDown(){
closeBrowser();
}
}
Hi Everyone I was trying to make a Selenium Script to verify the validations on Username and Password Text Box by fetching the data from Excel file (.xlt format) but whenever i am running my code it is getting the following error after successful loop run . The code is as follows :
package com.selenium.com.selenium.practise;
import org.testng.annotations.Test;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import org.testng.annotations.BeforeMethod;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
public class MultipleCasesUsingExcel {
public static WebDriver driver = null;
#Test
public void Test() throws BiffException, IOException, InterruptedException {
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
// Clicking on My Account Link
driver.findElement(By.xpath("//*[#id='top']/body/div/div/div[3]/div/div[4]/ul/li[1]/a")).click();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
WebElement emailTextBox = driver.findElement(By.xpath("//input[#id='email']"));
WebElement pwdTextBox = driver.findElement(By.xpath("//input[#id='pass']"));
WebElement loginBtn = driver.findElement(By.xpath("//button[#id='send2']"));
Workbook book = Workbook.getWorkbook(new File("C:\\Users\\Umang Bhatia\\Documents\\data.xlt"));
Sheet sheet = book.getSheet(0);
for (int i = 0; i < sheet.getRows(); i++) {
for (String handle : driver.getWindowHandles()) {
driver.switchTo().window(handle);
}
for (int j = 0; j < sheet.getColumns() - 1; j++) {
emailTextBox.sendKeys(sheet.getCell(j, i).getContents());
pwdTextBox.sendKeys(sheet.getCell(j + 1, i).getContents());
loginBtn.click();
emailTextBox.clear();
pwdTextBox.clear();
}
Thread.sleep(3000);
}
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
#BeforeMethod
public void beforeMethod() {
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\Umang Bhatia\\Documents\\Selenium Drivers\\chrome driver\\chromedriver.exe");
driver = new ChromeDriver();
driver.navigate().to("http://live.guru99.com/index.php/");
}
#AfterMethod
public void afterMethod() {
driver.quit();
}
}
And I am getting the following error after first successful loop run :
[RemoteTestNG] detected TestNG version 6.13.1
Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 36887
Only local connections are allowed.
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
FAILED: Test
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
(Session info: chrome=63.0.3239.132)
(Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.10586 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 31 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52'
System info: host: 'DESKTOP-59DNS54', ip: '192.168.2.5', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f), userDataDir=C:\Users\UMANGB~1\AppData\Local\Temp\scoped_dir13984_1984}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=63.0.3239.132, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=}]
Session ID: eb78d1ac176166bdaa86da5dc12e09c0
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:326)
at org.openqa.selenium.remote.RemoteWebElement.clear(RemoteWebElement.java:139)
at com.selenium.com.selenium.practise.MultipleCasesUsingExcel.Test(MultipleCasesUsingExcel.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:571)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:707)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:979)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1187)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1116)
at org.testng.TestNG.runSuites(TestNG.java:1028)
at org.testng.TestNG.run(TestNG.java:996)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
Could any one Explain why I am getting this error and how it can be fixed
That's because you change page in your test, thus your element references break. Have a look at WebDriverExtensions. This framework provides method on opening your links in new windows without invalidating references of WebElements, and enables dynamic lookup of your elements.
Alternatively, if you don't want to use this framework, you could re-search for your elements in your loop like this:
//...
for (int j = 0; j < sheet.getColumns() - 1; j++) {
// add these lines
emailTextBox = driver.findElement(By.xpath("//input[#id='email']"));
pwdTextBox = driver.findElement(By.xpath("//input[#id='pass']"));
loginBtn = driver.findElement(By.xpath("//button[#id='send2']"));
// clear inputs before login. After you click loginBtn, the page
// changes, and references of WebElements are invalidated,
// thus your emailTextBox.clear(); methods threw anexception
emailTextBox.clear();
pwdTextBox.clear();
emailTextBox.sendKeys(sheet.getCell(j, i).getContents());
pwdTextBox.sendKeys(sheet.getCell(j + 1, i).getContents());
loginBtn.click();
}
I use TestNG + Selenium + Appium.
Problem which i have is:
If the 1st #Test fails, all rest got failed automatically and execution will be stopped.
I tried to use #BecoreClass setUp instead of setting up at #Test still after first failure fails everything.
I thought that it skipping all the rest of the test because of it does not finish the process in the right way ( quitting an application ) that`s why i added #Aftermethod with driver.quit that it will execute it after failed method.
But still after 1st failure it automatically Fails all the tests.
I need to have multiple #Test with a test methods, which will be individual with separate configurations. And if 1st one fails, it will continue execute the rest of #Test ( even if they are from the same class) and after will give me a result .
package foundation;
import com.pageobjects.HeaderMenu;
import config.AppConfiguration;
import config.LogIn;
import config.DesiredCapabilitiesSetup;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.*;
import org.testng.asserts.SoftAssert;
import java.io.IOException;
public class AppiumTestTest {
private AndroidDriver<AndroidElement> driver;
private AOWebClient aoWeb;
#SuppressWarnings("unused")
public AppiumTestTest(AndroidDriver<AndroidElement> driver, AOWebClient aoWeb) {
this.driver = driver;
this.aoWeb = aoWeb;
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
}
#SuppressWarnings("unused")
public AppiumTestTest() {
}
private SoftAssert softAssert = new SoftAssert();
/*
#BeforeClass
public void setUp() throws Exception {
}
*/
#Test
public void checkInTest() throws Exception {
driver = DesiredCapabilitiesSetup.startAppiumServer(
AppConfiguration.newBuilder()
.setTimeSelection(false)
.setBirthday(true)
.build());
AOWebClient aoWebClient = DesiredCapabilitiesSetup.getAOWeb();
LogIn logIn = new LogIn(driver, aoWebClient);
logIn.logIn();
}
#Test
public void timeSelectionTest() throws Exception {
driver = DesiredCapabilitiesSetup.startAppiumServer(
AppConfiguration.newBuilder()
.setTimeSelection(true)
.setBirthday(true)
.build());
AOWebClient aoWebClient = DesiredCapabilitiesSetup.getAOWeb();
LogIn logIn = new LogIn(driver, aoWebClient);
logIn.logIn();
}
#AfterMethod
public void afterM(){
driver.close();
driver.quit();
}
}
My Desired Capabilities are:
package config;
import com.pageobjects.LaunchProgress;
import com.sun.javafx.tools.ant.DeployFXTask;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
import org.json.simple.JSONObject;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeClass;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
public class DesiredCapabilitiesSetup {
//Name of Android Device
//public static String deviceName = "TestDevice";
// Emulator
//public static String deviceName = "One";
//Path of App folder
// public static String appLink = "/Users/af185125/FoundationApp/";
//The name of Android application with format. (.apk).
//public static String appName = "app331.apk";
private static final String KEY_USE_TIME_SELECTION = "useTimeSelection";
private static final String KEY_DISABLE_BIRTHDAY = "disableBirthday";
#BeforeClass
public static AndroidDriver<AndroidElement> startAppiumServer(AppConfiguration appConfiguration) throws IOException {
// Taking App/Device/Link path from *txt file located in the project //
/*
String appLink = FileUtils.readFileToString(new File("appConfigurations/appLink.txt"));
String deviceName = FileUtils.readFileToString(new File("appConfigurations/deviceName.txt"));
String appName = FileUtils.readFileToString(new File("appConfigurations/appName.txt"));
*/
String appLink = FileUtils.readFileToString(new File("appConfigurations/appLink.txt"));
String deviceName = FileUtils.readFileToString(new File("appConfigurations/deviceName.txt"));
String appName = FileUtils.readFileToString(new File("appConfigurations/appName.txt"));
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
cap.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);
cap.setCapability(MobileCapabilityType.VERSION, "6.0");
cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "4000");
String configurationString = getConfigurationString(appConfiguration);
cap.setCapability(AndroidMobileCapabilityType.OPTIONAL_INTENT_ARGUMENTS,"--es appium_config \"" + configurationString + "\"");
//cap.setCapability("avd","nexus");
File appSource = new File(appLink);
File app = new File(appSource, appName);
cap.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
AndroidDriver<AndroidElement> driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
LaunchProgress launch = new LaunchProgress(driver);
launch.waitForLaunchScreenToLoad();
return driver;
}
#SuppressWarnings("unchecked")
private static String getConfigurationString(AppConfiguration appConfiguration) {
JSONObject configuration = new JSONObject();
configuration.put(KEY_USE_TIME_SELECTION, appConfiguration.timeSelection);
configuration.put(KEY_DISABLE_BIRTHDAY, appConfiguration.birthday);
return configuration.toJSONString();
}
}
Stacktrace:
objc[20683]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
Connected to the target VM, address: '127.0.0.1:58385', transport: 'socket'
[TestNG] Running:
/Users/af185125/Library/Caches/IdeaIC2016.2/temp-testng-customsuite.xml
org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 80.28 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'WUSAF185125-G3D', ip: '153.86.242.30', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_91'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{app=/Users/af185125/android-ui-test/currentApp/appiumT.apk, appPackage=com.ao.demo.beta, networkConnectionEnabled=true, warnings={}, appWaitPackage=com.ao.demo.beta, appWaitActivity=com.ao.core.ui.launch.LaunchActivity, databaseEnabled=false, deviceName=ad071603280ea0c18d, version=6.0, fullReset=true, platform=LINUX, deviceUDID=ad071603280ea0c18d, appActivity=com.ao.core.ui.launch.LaunchActivity, desired={app=/Users/af185125/android-ui-test/currentApp/appiumT.apk, newCommandTimeout=4000, platformVersion=6.0, automationName=Appium, platformName=Android, deviceName=Automation, version=6.0, optionalIntentArguments=--es appium_config "{"useTimeSelection":false,"disableBirthday":true}", fullReset=true}, newCommandTimeout=4000, platformVersion=6.0.1, webStorageEnabled=false, locationContextEnabled=false, automationName=Appium, takesScreenshot=true, javascriptEnabled=true, platformName=Android, optionalIntentArguments=--es appium_config "{"useTimeSelection":false,"disableBirthday":true}"}]
Session ID: 30270d0f-8594-4ead-b5b6-56dfeee37f44
*** Element info: {Using=id, value=fasf.com}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:51)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:67)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:413)
at io.appium.java_client.DefaultGenericMobileDriver.findElementById(DefaultGenericMobileDriver.java:75)
at io.appium.java_client.AppiumDriver.findElementById(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElementById(AndroidDriver.java:1)
at org.openqa.selenium.By$ById.findElement(By.java:218)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:63)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at foundation.AppiumTestTest.checkInTest(AppiumTestTest.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:646)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:811)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1129)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:746)
at org.testng.TestRunner.run(TestRunner.java:600)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1264)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1189)
at org.testng.TestNG.runSuites(TestNG.java:1104)
at org.testng.TestNG.run(TestNG.java:1076)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:124)
org.openqa.selenium.WebDriverException: Method has not yet been implemented (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 7 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'WUSAF185125-G3D', ip: '153.86.242.30', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_91'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{app=/Users/af185125/android-ui-test/currentApp/appiumT.apk, appPackage=com.ao.demo.beta, networkConnectionEnabled=true, warnings={}, appWaitPackage=com.ao.demo.beta, appWaitActivity=com.ao.core.ui.launch.LaunchActivity, databaseEnabled=false, deviceName=ad071603280ea0c18d, version=6.0, fullReset=true, platform=LINUX, deviceUDID=ad071603280ea0c18d, appActivity=com.ao.core.ui.launch.LaunchActivity, desired={app=/Users/af185125/android-ui-test/currentApp/appiumT.apk, newCommandTimeout=4000, platformVersion=6.0, automationName=Appium, platformName=Android, deviceName=Automation, version=6.0, optionalIntentArguments=--es appium_config "{"useTimeSelection":false,"disableBirthday":true}", fullReset=true}, newCommandTimeout=4000, platformVersion=6.0.1, webStorageEnabled=false, locationContextEnabled=false, automationName=Appium, takesScreenshot=true, javascriptEnabled=true, platformName=Android, optionalIntentArguments=--es appium_config "{"useTimeSelection":false,"disableBirthday":true}"}]
Session ID: 30270d0f-8594-4ead-b5b6-56dfeee37f44
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:51)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:268)
at org.openqa.selenium.remote.RemoteWebDriver.close(RemoteWebDriver.java:521)
at foundation.AppiumTestTest.afterM(AppiumTestTest.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:216)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:712)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:811)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1129)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:746)
at org.testng.TestRunner.run(TestRunner.java:600)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1264)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1189)
at org.testng.TestNG.runSuites(TestNG.java:1104)
at org.testng.TestNG.run(TestNG.java:1076)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:124)
Test ignored.
org.openqa.selenium.WebDriverException: Method has not yet been implemented (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 5 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'WUSAF185125-G3D', ip: '153.86.242.30', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_91'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{app=/Users/af185125/android-ui-test/currentApp/appiumT.apk, appPackage=com.ao.demo.beta, networkConnectionEnabled=true, warnings={}, appWaitPackage=com.ao.demo.beta, appWaitActivity=com.ao.core.ui.launch.LaunchActivity, databaseEnabled=false, deviceName=ad071603280ea0c18d, version=6.0, fullReset=true, platform=LINUX, deviceUDID=ad071603280ea0c18d, appActivity=com.ao.core.ui.launch.LaunchActivity, desired={app=/Users/af185125/android-ui-test/currentApp/appiumT.apk, newCommandTimeout=4000, platformVersion=6.0, automationName=Appium, platformName=Android, deviceName=Automation, version=6.0, optionalIntentArguments=--es appium_config "{"useTimeSelection":false,"disableBirthday":true}", fullReset=true}, newCommandTimeout=4000, platformVersion=6.0.1, webStorageEnabled=false, locationContextEnabled=false, automationName=Appium, takesScreenshot=true, javascriptEnabled=true, platformName=Android, optionalIntentArguments=--es appium_config "{"useTimeSelection":false,"disableBirthday":true}"}]
Session ID: 30270d0f-8594-4ead-b5b6-56dfeee37f44
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:51)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:268)
at org.openqa.selenium.remote.RemoteWebDriver.close(RemoteWebDriver.java:521)
at foundation.AppiumTestTest.afterM(AppiumTestTest.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:216)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:712)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:811)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1129)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:746)
at org.testng.TestRunner.run(TestRunner.java:600)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1264)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1189)
at org.testng.TestNG.runSuites(TestNG.java:1104)
at org.testng.TestNG.run(TestNG.java:1076)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:124)
Move driver = DesiredCapabilitiesSetup.startAppiumServer... to #BeforeMethod. Also if you want to use different drivers for tests you will have to add parametrization (e.g. #BeforeMethod for group, #DataProvider or #Facotry).
I am randomly getting an org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died. error, i.e., it doesn't always happen with the same input in the same code. The code:
public class PortalListingCallable implements Callable<Listing> {
private WebDriver driver;
private WebElement event;
public PortalListingCallable(WebElement event) {
driver = new HtmlUnitDriver();
this.event = event;
}
public Listing call() {
//System.out.println("in PortalLisingCallable");
Listing newListing = ListingFactory.createListing(
new PortalScheduleEventsEvent(driver, event.findElements(By.tagName("td"))).parse());
driver.close();
return newListing;
}
}
I have also tried the line Listing newListing = ListingFactory.createListing(new PortalScheduleEventsEvent(new HtmlUnitDriver(), event.findElements(By.tagName("td"))).parse());
This class implements Callable, so it's being called by multiple threads, but the data is independent. That code:
while (webElementsQueue.peek() != null) {
Callable<Listing> callable = new
PortalListingCallable(webElementsQueue.poll());
//Future<Listing> future = executor.submit(callable);
Future<Listing> future = executor.submit(new Callable<Listing>() {
#Override
public Listing call() throws Exception {
try {
return callable.call();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
});
listingQueue.offer(future);
}
I suspect that this has something to do with this being called in multiple threads, but since each instance of HtmlUnitDriver is isolated, I'm not sure how.
Below is the exception:
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.46.0', revision: '61506a4624b13675f24581e453592342b7485d71', time: '2015-06-04 10:22:50'
System info: host: '955PC', ip: 'x.x.x.x', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_40'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:269)
at org.openqa.selenium.remote.RemoteWebElement.findElements(RemoteWebElement.java:188)
at org.openqa.selenium.remote.RemoteWebElement.findElementsByTagName(RemoteWebElement.java:265)
at org.openqa.selenium.By$ByTagName.findElements(By.java:324)
at org.openqa.selenium.remote.RemoteWebElement.findElements(RemoteWebElement.java:164)
at autoschedtwo.portal.PortalListingCallable.call(PortalListingCallable.java:31)
at autoschedtwo.portal.PortalListingCallable.call(PortalListingCallable.java:17)
at autoschedtwo.portal.PortalDriver$1.call(PortalDriver.java:40)
at autoschedtwo.portal.PortalDriver$1.call(PortalDriver.java:36)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:26014 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
Build info: version: '2.46.0', revision: '61506a4624b13675f24581e453592342b7485d71', time: '2015-06-04 10:22:50'
System info: host: '955PC', ip: 'x.x.x.x', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_40'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:76)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:578)
... 13 more
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:26014 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:151)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:143)
at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:89)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:134)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:67)
... 14 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
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:74)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
... 27 more