How to close the newly created instance of webdriver in geb - spock

I've been looking into some webdriver automation scripts using geb and spock. In few specs, I want another instance of webdriver with different capabilities so I'd not be using driver instance created by Geb by default. But when I use driver.close() in cleanup of test, GebReporting fails satating, NoSuchSessionException. I'm facing this issue after upgrading to firefox 74. Below is the script i've now.
Spec
Test
-- reset browser
-- clearchacheAndShutdownDriver
-- browser.driver = create new driver with new capabilities
cleanup : driver.close
Now after cleanup the driver is closed and GebReporting uses the driver instance which fails with NoSuchSessionException. Is there anyway to handle it in Geb way? instead of doing only clearcache, store the instance in other variable, restore it to browser.driver after closing the newly created driver instance.
I did found a post with similar question but it didn't help me.
Thanks in advance.

You need to call resetBrowser() on your spec instance before calling driver.close() to ensure that the Browser instance which is holding a reference to the WebDriver instance you are closing is detached from the spec and therefore no reporting is attempted at the end of the spec.

Related

Running BeforeTestRun/AfterTestRun once on Specflow Runner

Does anyone have successfully setup a beforetestrun/aftertestrun hook when using Specflow runner on multithread using AppDomain
I saw some answer from this thread - Run BeforeTestRun and AfterTestRun only once using specflow with Selenium
Unfortunately, I'm having difficulty to set this up as we need it to configure our TestRail integration.
It is possible - you have to use a kernel-based lock (the following constructor is the one to use):
https://learn.microsoft.com/en-us/dotnet/api/system.threading.semaphore.-ctor?view=net-5.0#System_Threading_Semaphore__ctor_System_Int32_System_Int32_System_String_System_Boolean__
The flow:
Create a named instance of Semaphore
The thread where createdNew == true is the first thread that entered the code - execute test run init code here
For other threads use method 'WaitOne' with a proper timeout
Best regards,
PM

SDN 4.1 - Multithreading Neo4j TestServer for parallel execution of test cases

I'm using org.neo4j.ogm.testutil.TestServer and the http driver for integration testing instead of the Embedded driver because I like how the TestServer provides a browser based interface to see what is happening with each test.
However - my tests take ages! The build is getting up to around 30 minutes on a reasonably quick machine.
What I'd like to do is use the maven surefire plugin to execute my test cases in parallel.
To do this I imagine I'll need to be able to startup several neo4j TestServer instances, each on a different port.
Where is the best place to do this using neo4j 4.1? I assume #Before and #After (for shutdown) methods of my test cases? (possibly extracted into a super class?)
Also, how would I get the current port for the current test context into each unit test?
Any suggestions of how to go about this would be greatly appreciated :)
Have a look at org.neo4j.ogm.testutil.MultiDriverTestClass which sets up the Driver using the TestServer.
The TestServer should pick an available port anyway which should solve your problem of setting these up in parallel. In fact, you can just have your test class extend org.neo4j.ogm.testutil.MultiDriverTestClass (most of the tests in org.neo4j.ogm.persistence.examples do this) and provide an ogm.properties file that specifies that the driver to be used is the HTTP Driver
driver=org.neo4j.ogm.drivers.http.driver.HttpDriver

Running Geb + spock tests headless

I have a number of geb functional tests for a grails application.
The tests are working as expected when executed from terminal or IDE.
Although the tests need to be executed by hudson, so they are run in headless mode using Xvfb.
The problem is that the tests keep failing, or behaving unexpectedly, returning errors like RequiredPageContentNotPresent and Stale Element Reference Exception in places that doesn't make sense.
For example:
(at LicencePage is verified above, and page isn't changed)
when:
addDocument(Data.Test_Doc_name,Data.Test_Doc_file)
sometimes throws
Failure: Add Actual Licence (HomePageSpec)
| geb.error.RequiredPageContentNotPresent: The required page content 'addDocument - SimplePageContent (owner: LicencePage, args: [Functional Test Doc, /var/lib/hudson/jobs/KB-Functional_Tests/workspace/app/../manual_test_data/so_v3/os_test_1], value: null)' is not present
at geb.content.TemplateDerivedPageContent.require(TemplateDerivedPageContent.groovy:61)
at geb.content.PageContentTemplate.create_closure1(PageContentTemplate.groovy:63)
at geb.content.PageContentTemplate.create(PageContentTemplate.groovy:82)
at geb.content.PageContentTemplate.get(PageContentTemplate.groovy:54)
at geb.content.NavigableSupport.getContent(NavigableSupport.groovy:45)
at geb.content.NavigableSupport.methodMissing(NavigableSupport.groovy:121)
at geb.Browser.methodMissing(Browser.groovy:194)
at geb.spock.GebSpec.methodMissing(GebSpec.groovy:51)
at HomePageSpec.Add Actual Licence (HomePageSpec.groovy:228)
The method addDocument() is defined on an 'abstract' page, which LicencePage is extending. In most cases like this, if I copy the method code directly into my Spec, it is going to work, although its ruining all the structure I have on my test pages.
Anyone has experience running geb tests with Xvfb? Have you faced these issues?
All tests are passing when executed locally, and this not a data issue as the DB is always cleared
Also, without making any changes, the tests are behaving non-deterministic (on hudson) so the above exception is not always thrown. Without any changes at all, tests are sometimes successful and sometimes fail.
The description you gave seems to be the symptom of a flackey test-suite. we were facing this problem as well some time ago. A good starting point for this is this presentation (around min. 35) and the documentation about the wait stuff in geb.
If you think, it could have something to do with xvfb (where i have no experiences with), you could try to use phantomjs as the test-runner and check if it works correctly.

JSFUnit inconsistently getting JSFServerSession

We are trying to run JSFUnit with Arquillian on a WebLogic 12c container and are running into a few problems.
First, when we try to use the #InitialPage annotation to inject in the JSFServerSession and JSFClientSession, the JSFServerSession is always returned as null.
Second, we have tried working around the problem by going the legacy route of creating a new JSFSession and then getting the JSFServerSession and JSFClientSession from it. Once we run a second test we get "java.lang.IllegalStateException: Can not find HttpSession. Make sure JSFUnitFilter has run and your test extends org.apache.cactus.ServletTestCase."
It seems very arbitrary because there are times where we will run a test and it passes. Sometimes the very next time it fails. Or adding a line that doesn't seem like it should be related, will thrown the "Can not find HttpSession" error.
It seems like it can't handle creating the JSFSession multiple times or there is some timeout on the server that even though the test war is getting undeployed something needs to timeout. Any thoughts?
I am not sure if this applies to your problem as well, but I had similar issue with JBoss 7. Usually the issues can be solved by:
Using Servlet 3.0 protocol which should include relevant filters to web.xml
If that doesn't help (like in my case), use this solution: https://stackoverflow.com/a/17036005/1667977
In any case, try to avoid creating the session yourself

Activator.CreateInstance timeout

I'm trying to debug an unmanaged EXE through an ActiveX interface. The problem is that I'm using Activator.CreateInstance(Type) to create the ActiveX object of my application. The behavior I'm debugging is in the loading of this application.
As a result, my debug session prematurely terminates when the timeout for this method expires (CO_E_SERVER_EXEC_FAILURE). Is there a way to manually extend the timeout for this function? The ActiveX object is being created in a C# application.
CoCreateInstance() timeout after 120 secondes. That's it. I'm not aware of a way to extend it.
Is there any way to execute the code you are trying to debug at a later stage rather than directly at component creation? That way you will be able to debug the code separately and since the component would already have been created, it won't timeout on the CreateInstance().

Resources