Selenium hanging with xvfb - selenium

I am attempting to run automated selenium headless tests, and I'm running into the issue where the tests hang for some inexplicable reason. The full snippet is on pastebin, but the relevant portion of the code is reproduced below:
# stress testing
i = 0
while True:
print i
d = webdriver.Remote(
service.service_url,
desired_capabilities=DesiredCapabilities.CHROME
)
print i, "started driver"
d.get("http://www.facebook.com")
print i, "got fb"
d.quit()
print i, "quit"
i += 1
Sample output is
0
0 started driver
0 got fb
0 quit
...
11 <hang>
Which indicates that webdriver.Remote is refusing to properly initiate the driver. This also occurs when the driver instance is constructed directly with webdriver.Chrome (instead of running the ChromeDriver as a service).
After sending SIGINT to the hanging program, I get a stacktrace (pastebin) indicating a blocking socket read somewhere in the constructor.
ChromeDriver's log (dropcanvas) doesn't seem to indicate anything amiss, and I'm quite puzzled as to what is happening here.
Similar questions have been asked previously, the most relevant being Selenium Chromedriver Hangs?; however, I cannot reproduce the accepted solution (starting Xvfb anew for each instantiation of webdriver...). Here, the equivalent would be calling Xvfb.start immediately preceding d = webdriver.Remote... and calling Xvfb.stop at the end of the loop; I have tried this to no success.
Any help would be greatly appreciated.
Edit: As indicated by the stacktrace, webdriver.Remote was hanging on some socket read function; I traced the request to be
POST 'http://127.0.0.1:<chromedriver_port>/session'
with body
'{"desiredCapabilities": {"platform": "ANY", "browserName": "chrome", "version": "", "javascriptEnabled": true}}'
So it seems like ChromeDriver isn't responding for some reason. Will continue debugging.

Related

Flutter SIGINT error on run all tests on VSCODE

When trying to "Run All Tests" from flutter/dart on VSCODE, I'm getting a SIGINT error and the test finish with "loading"on file, only the first one goes ok. The problem is that the same thing does not happen if I run the tests one by one.
loading /Users/marciomontenegro/Documents/Projects/mel/test/domain/usecases/sign_in_test.dart:
ERROR: Failed to load "/Users/marciomontenegro/Documents/Projects/mel/test/domain/usecases/sign_in_test.dart":
Shell subprocess terminated by ^C (SIGINT, -2) before connecting to test harness.
Test: /Users/marciomontenegro/Documents/Projects/mel/test/domain/usecases/sign_in_test.dart
Shell: /Users/marciomontenegro/flutter/bin/cache/artifacts/engine/darwin-x64/flutter_tester
dart:async/stream_controller.dart 595:43 _StreamController.addError
dart:async/stream_controller.dart 862:13 _StreamSinkWrapper.addError
package:stream_channel/src/guarantee_channel.dart 144:14 _GuaranteeSink._addError
package:stream_channel/src/guarantee_channel.dart 135:5 _GuaranteeSink.addError
package:flutter_tools/src/test/flutter_platform.dart 566:27 FlutterPlatform._startTest
===== asynchronous gap ===========================
dart:async/zone.dart 1053:19 _CustomZone.registerUnaryCallback
dart:async-patch/async_patch.dart 71:23 _asyncThenWrapperHelper
package:flutter_tools/src/test/flutter_platform.dart FlutterPlatform._startTest
package:flutter_tools/src/test/flutter_platform.dart 368:36 FlutterPlatform.loadChannel
package:flutter_tools/src/test/flutter_platform.dart 321:46 FlutterPlatform.load
===== asynchronous gap ===========================
dart:async/zone.dart 1053:19 _CustomZone.registerUnaryCallback
dart:async-patch/async_patch.dart 71:23 _asyncThenWrapperHelper
package:test_core/src/runner/loader.dart Loader.loadFile.<fn>
package:test_core/src/runner/load_suite.dart 98:31 new LoadSuite.<fn>.<fn>
===== asynchronous gap ===========================
dart:async/zone.dart 1045:19 _CustomZone.registerCallback
dart:async/zone.dart 962:22 _CustomZone.bindCallbackGuarded
dart:async/timer.dart 52:45 new Timer
dart:async/timer.dart 89:9 Timer.run
dart:async/future.dart 172:11 new Future
package:test_api/src/backend/invoker.dart 399:21 Invoker._onRun.<fn>.<fn>.<fn>
Just found some info about this issue.
From https://github.com/Dart-Code/Dart-Code/issues/2082 :
Ok, I can only repro this using launch.json and not with the Run All Tests command. The reason for this is that Run All Tests runs without the debugger, but setting up launch.json as as described at #1673 (comment) will run in debug mode, but in a single debug session (and that fails due to multiple VM services).
I don't think there's going to be an easy way to handle this.
As a workaround, if you add "noDebug": true to the launch.json, it should fix it (albeit at the expense of debugging, and a warning from VS Code that it's not a valid option).

WebSphere wsadmin testConnection error message

I'm trying to write a script to test all DataSources of a WebSphere Cell/Node/Cluster. While this is possible from the Admin Console a script is better for certain audiences.
So I found the following article from IBM https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/txml_testconnection.html which looks promising as it describles exactly what I need.
After having a basic script like:
ds_ids = AdminConfig.list("DataSource").splitlines()
for ds_id in ds_ids:
AdminControl.testConnection(ds_id)
I experienced some undocumented behavior. Contrary to the article above the testConnection function does not always return a String, but may also throw a exception.
So I simply use a try-catch block:
try:
AdminControl.testConnection(ds_id)
except: # it actually is a com.ibm.ws.scripting.ScriptingException
exc_type, exc_value, exc_traceback = sys.exc_info()
now when I print the exc_value this is what one gets:
com.ibm.ws.scripting.ScriptingException: com.ibm.websphere.management.exception.AdminException: javax.management.MBeanException: Exception thrown in RequiredModelMBean while trying to invoke operation testConnection
Now this error message is always the same no matter what's wrong. I tested authentication errors, missing WebSphere Variables and missing driver classes.
While the Admin Console prints reasonable messages, the script keeps printing the same meaningless message.
The very weird thing is, as long as I don't catch the exception and the script just exits by error, a descriptive error message is shown.
Accessing the Java-Exceptions cause exc_value.getCause() gives None.
I've also had a look at the DataSource MBeans, but as they only exist if the servers are started, I quickly gave up on them.
I hope someone knows how to access the error messages I see when not catching the Exception.
thanks in advance
After all the research and testing AdminControl seems to be nothing more than a convinience facade to some of the commonly used MBeans.
So I tried issuing the Test Connection Service (like in the java example here https://www.ibm.com/support/knowledgecenter/en/SSEQTP_8.5.5/com.ibm.websphere.base.doc/ae/cdat_testcon.html
) directly:
ds_id = AdminConfig.list("DataSource").splitlines()[0]
# other queries may be 'process=server1' or 'process=dmgr'
ds_cfg_helpers = __wat.AdminControl.queryNames("WebSphere:process=nodeagent,type=DataSourceCfgHelper,*").splitlines()
try:
# invoke MBean method directly
warning_cnt = __wat.AdminControl.invoke(ds_cfg_helpers[0], "testConnection", ds_id)
if warning_cnt == "0":
print = "success"
else:
print "%s warning(s)" % warning_cnt
except ScriptingException as exc:
# get to the root of all evil ignoring exception wrappers
exc_cause = exc
while exc_cause.getCause():
exc_cause = exc_cause.getCause()
print exc_cause
This works the way I hoped for. The downside is that the code gets much more complicated if one needs to test DataSources that are defined on all kinds of scopes (Cell/Node/Cluster/Server/Application).
I don't need this so I left it out, but I still hope the example is useful to others too.

Elasticsearch throws 'ElasticsearchIllegalStateException' part way through tests

I've got a large Groovy application with a lot of JUnit integration tests (256), most of which use 'com.github.tlrx.elasticsearch-test', version: '1.2.1' to run elasticsearch locally.
part way through running all of the test classes all the test that use elasticsearch start throwing a 'ElasticsearchIllegalStateException' with message 'Failed to obtain node lock, is the following location writable?: [./target/elasticsearch-test/data/cluster-test-kiml42s-MacBook-Pro.local]'.
If I run any of these classes alone, it works fine.
This is my initialising code run in all #Befores:
esSetup = new EsSetup();
CreateIndex createIndex = createIndex(index)
for(int i = 0; i < types.size(); i++){
createIndex.withMapping(types[i], fromClassPath(mappings[i]))
}
esSetup.execute(deleteAll(), createIndex)
client = esSetup.client()
And this if my teardown code run in the #Afters:
client.admin().indices().prepareDelete(index).get()
This problem doesn't seem to happen on our build server, so it's only annoying and inconvinient, not a serious problem, but any help would be most appreciated. Thanks.
This problem seems to have been cause by leaving the test nodes active while jUnit ran through all the tests - eventually it stopped being able to create new nodes. The solution is to use esSetup.terminate() in the after to destroy the nodes at the end of each test.
Here's an example of it being used correctly: https://gist.github.com/tlrx/4117854

Selenium 2/WebDriver and Selenium Server - switching windows gives same HTML

I've been using Selenium 2/WebDriver through Ruby 1.9.2, and directly through FireFox it works fine. I wanted to use HtmlUnit so it's faster and headless, so I'm trying selenium-server-standalone-2.17.0 as it should in theory require no code changes, and also I want to start using Java/groovy with HtmlUnit.
The problem is that half the time or more, a test fails because when I click a button and switch windows, the HTML (and title) in the new window is the same as the old one.
I added lots of debugging output to my function to try to narrow it down:
def switch_to_newest_window()
assert(#driver.window_handles.size > 1, "only one window")
print "switch to newest window, handles=#{#driver.window_handles}...\n"
print "current handle: #{#driver.window_handle}\n"
print "#{#driver.window_handles[0]}\n"
print "#{#driver.window_handles[-1]}\n"
print "title: #{#driver.title}\n"
save_file("first.html", #driver.page_source)
#driver.switch_to.window(#driver.window_handles[-1])
print "new handle: #{#driver.window_handle}\n"
print "new window title: #{#driver.title}\n"
save_file("second.html", #driver.page_source)
end
And the relevant output is:
switch to newest window, handles=["36543124", "1755893858"]...
current handle: 1755893858
36543124
1755893858
title: Create FlowSet
new handle: 1755893858
new window title: Create FlowSet
So it's correctly switching windows, but the HTML is the same! If you diff first.html and second.html, there is no output.
I'm also a ruby noob so I may well be doing things the hard/slow way or incorrectly.
Other details:
running on Windows 7.
Selenium Server server-standalone-2.17.0
Server output when starting HtmlUnit session:
13:03:12.292 INFO - Executing: [new session: {platform=ANY, javascriptEnabled=true, cssSelectorsEnabled=false, browserName=htmlunit, nativeEvents=false, rotatable=false, takesScreenshot=false, version=}] at URL: /session)
Thanks very much in advance for any help.
Joel

Selenium test in Internet Explorer always times out?

I'm trying to run a basic test in Internet Explorer via Selenium-RC/PHPUnit, and it always returns with
# phpunit c:\googletest.php
PHPUnit 3.4.15 by Sebastian Bergmann.
E
Time: 35 seconds, Memory: 4.75Mb
There was 1 error:
1) Example::testMyTestCase
PHPUnit_Framework_Exception: Response from Selenium RC server for testComplete()
.
Timed out after 30000ms.
C:\googletest.php:17
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
Paul#PAUL-TS-LAPTOP C:\xampp
#
The last command in command history is waitForPageToLoad(30000). The same test runs fine and completes in firefox. How can I get this test to run and complete in internet explorer?
Thanks
There's an open bug in selenium that causes waitForPageToLoad to sometimes timeout on IE.
http://jira.openqa.org/browse/SRC-552
It's marked as occurring on IE6, but I'm experiencing the same error in at least IE9.
A workaround is to wait for e.g. a specific DOM-element on the page that is loading instead of using waitForPageToLoad. For example: waitForVisible('css=#header')
Try going into Internet Options and turn off Protected mode under the security tab. You may also want to decrease the security level for the Internet zone.
I've turned off protected mode and looks like it helped.
If it is acceptable to customize the client driver, here is the Python implementation for your refernece:
def open(self):
timeout = self.get_eval('this.defaultTimeout')
self.set_timeout(0)
self.do_command("open", [url,ignoreResponseCode])
self.set_timeout(timeout)
self.wait_for_page_to_load(timeout)
def wait_for_page_to_load(self,timeout):
# self.do_command("waitForPageToLoad", [timeout,])
import time
end = time.time() + int(float(timeout) / 1000)
while time.time() < end:
if self.get_eval('window.document.readyState') == 'complete': return
time.sleep(2)
raise Exception('Time out after %sms' % timeout)
I just use DOM attribute document.readyState to determine if the page is fully loaded.
IE 9+ intermittently throws a timeout error even the page is fully loaded, for more details.