SpecRun.exe hangs for 60 seconds after test execution - selenium

posted this to google groups SpecFlow but there is little or no activity there so here we go.
I have a SpecFlow/Selenium/MSBuild project and I am running one simple scenario through
the command line, something like this:
SpecRun.exe run Default.srprofile "/filter:#%filter%"
The browser instance fires up, the assert is done, and the browser instance closes. This
takes about 5-10 seconds.
However: after this, I have to wait for 60 seconds until the SpecRun process closes and gives me the result like:
Discovered 1 tests
Thread#0:
0% completed
Thread#0: S
100% completed
Done.
Result: all tests passed
Total: 1
Succeeded: 1
Ignored: 0
Pending: 0
Skipped: 0
Failed: 0
Execution Time: 00:01:01.1724989
I am currently assuming this is because it is writing the test execution report to disk.. but I can not figure out how to turn this OFF... http://www.specflow.org/documentation/Reporting/
And, I can not figure out why this would take 60 seconds, or how to further debug this.
I have removed the AfterScenario and checked the selenium driver quit/close and verified that is not what is causing the problem.
Can anyone shed some light on this ?
Thank you

Jesus. There was something seriously wrong with the BaseStepDefinitions. Did some more debugging and found that the BeforeScenario was hit 25 times on one single test. 25 instances were launched and closed per 1 single scenario. Fixed by starting all over again with a clean file like:
[Binding]
public class BaseStepDefinitions
{
public static IWebDriver Driver;
private static void Setup()
{
Driver = new ChromeDriver();
}
[BeforeFeature]
public static void BeforeFeature()
{
Setup();
}
[AfterFeature]
public static void AfterFeature()
{
Driver.Dispose();
}
}
I will not post my original file because it is embarrassing.
This is a similar problem that helped me https://groups.google.com/forum/#!topic/specflow/LSt0PGv2DeY

Related

JMeter - Avoid threads abrupt shutdown

I have a testPlan that has several transacion controllers (that I called UserJourneys) and each one is composed by some samplers (JourneySteps).
The problem I'm facing is that once the test duration is over, Jmeter kills all the threads and does not take into consideration if they are in the middle of a UserJourney (transaction controller) or not.
On some of these UJs I do some important stuff that needs to be done before the user logs in again, otherwise the next iterations (new test run) will fail.
The question is: Is there a way to tell to JMeter that it needs to wait every thread reach the end of its flow/UJ/TransactionController before killing it?
Thanks in advance!
This is not possible as of version 5.1.1, you should request an enhancement at:
https://jmeter.apache.org/issues.html
The solution is to add as first child of Thread Group a Flow Control Action containing a JSR223 PreProcessor:
The JSR223 PreProcessor will contain this groovy code:
import org.apache.jorphan.util.JMeterStopTestException;
long startDate = vars["TESTSTART.MS"].toLong();
long now = System.currentTimeMillis();
String testDuration = Parameters;
if ((now - startDate) >= testDuration.toLong()) {
log.info("Test duration "+testDuration+" reached");
throw new JMeterStopTestException("Test duration "+testDuration+"reached ");
} else {
log.info("Test duration "+testDuration+" not reached yet");
}
And be configured like this:
Finally you can set the property testDuration in millis on command line using:
-JtestDuration=3600000
If you'd like to learn more about JMeter and performance testing this book can help you.

Optaplanner : View intermediate score

Is there a way keep track of the score from time to time while the solver is running?
I currently instantiate my solver as follow
SolverFactory solverFactory = SolverFactory.createFromXmlResource("solver/SolverConfig.xml");
Solver solver = solverFactory.buildSolver();
solver.addEventListener(new SolverEventListener() {
#Override
public void bestSolutionChanged(BestSolutionChangedEvent event) {
logger.info("New best score : " + event.getNewBestScore().toShortString());
}
});
solver.solve(planningSolution);
This way I am able to see the logs every time the best score changes.
However, I would like to view the score after every 100 steps or after every 10 seconds. Is that possible?
If you turn on DEBUG (or TRACE) logging, you'll see it.
If you want to listen to it in java, that's not supported in the public API, but there's PhaseLifecycleListener in the internal implementation that has no backward compatibility guarantees...

Time out for test cases in googletest

Is there a way in gtest to have a timeout for inline/test cases or even tests.
For example I would like to do something like:
EXPECT_TIMEOUT(5 seconds, myFunction());
I found this issue googletest issues as 'Type:Enhancement' from Dec 09 2010.
https://code.google.com/p/googletest/issues/detail?id=348
Looks like there is no gtest way from this post.
I am probably not the first to trying to figure out a way for this.
The only way I can think is to make a child thread run the function, and if it does not return by the
time limit the parent thread will kill it and show timeout error.
Is there any way where you don't have to use threads?
Or any other ways?
I just came across this situation.
I wanted to add a failing test for my reactor. The reactor never finishes. (it has to fail first). But I don't want the test to run forever.
I followed your link but still not joy there. So I decided to use some of the C++14 features and it makes it relatively simple.
But I implemented the timeout like this:
TEST(Init, run)
{
// Step 1 Set up my code to run.
ThorsAnvil::Async::Reactor reactor;
std::unique_ptr<ThorsAnvil::Async::Handler> handler(new TestHandler("test/data/input"));
ThorsAnvil::Async::HandlerId id = reactor.registerHandler(std::move(handler));
// Step 2
// Run the code async.
auto asyncFuture = std::async(
std::launch::async, [&reactor]() {
reactor.run(); // The TestHandler
// should call reactor.shutDown()
// when it is finished.
// if it does not then
// the test failed.
});
// Step 3
// DO your timeout test.
EXPECT_TRUE(asyncFuture.wait_for(std::chrono::milliseconds(5000)) != std::future_status::timeout);
// Step 4
// Clean up your resources.
reactor.shutDown(); // this will allow run() to exit.
// and the thread to die.
}
Now that I have my failing test I can write the code that fixes the test.

Firefox WebDriver hangs waiting for page to load

sometimes in my test done with Selenium 2.41 and tested with Firefox 28 the execution hangs waiting for page to load.
This is the wait condition:
int time = 30;
WebDriverWait wait = new WebDriverWait(webDriver, time);
ExpectedCondition<Boolean> pageLoadCondition = new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");
}
};
wait.until(pageLoadCondition);
It's supposed that after 30 seconds this method will throw a TimeoutException, but it's not, sometimes hangs forever.
This is the stacktrace produced in these situations:
java.lang.Thread.State: RUNNABLE at
java.net.SocketInputStream.socketRead0(Native Method) at
java.net.SocketInputStream.read(Unknown Source) at
org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:160)
at
org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:84)
at
org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:273)
at
org.apache.http.impl.conn.LoggingSessionInputBuffer.readLine(LoggingSessionInputBuffer.java:116)
at
org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)
at
org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at
org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:260)
at
org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:283)
at
org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:251)
at
org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:223)
at
org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:271)
at
org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
at
org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:682)
at
org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:486)
at
org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)
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.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:322)
at
org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:301)
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:568)
at
org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:504)
at
es.tao.commonservices.selenium.tests.TAORobotWebDriver$1.apply(TAORobotWebDriver.java:6227)
at
es.tao.commonservices.selenium.tests.TAORobotWebDriver$1.apply(TAORobotWebDriver.java:1)
at
org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
at
es.tao.commonservices.selenium.tests.TAORobotWebDriver.waitToLoad(TAORobotWebDriver.java:6230)
at
es.tao.commonservices.selenium.tests.TAORobotWebDriver.handleWaitToLoad(TAORobotWebDriver.java:6110)
I have set this preference for firefox profile, but it's still not working:
ffProfile = new FirefoxProfile();
ffProfile.setPreference("webdriver.load.strategy", "unstable");
Also have this properties set:
webDriver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
webDriver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
You may want to try Firefox 27.01. I upgraded to Firefox 28.0 and it seemed to break some tests I was doing using watir-webdriver. I went back to 27.01 and the tests ran again(if you go back download the whole install package as the setup only, does not seem to let you turn off auto-update so it updates itself to 28.0).
The fails were using hover and find_element.
Found an unresolved bug: https://code.google.com/p/selenium/issues/detail?id=6955 - if you can, please provide a test case, primarily a reduced host page with minimal scripts where the problem still occurs so it can be repeated reliably and traced down.
Sometimes I question myself if Google uses their own tools at all.... they should have run into that bug ages ago considering how huge that company is.

Wait is not working in selenium webdriver

I need help on wait function in Selenium webdriver.
I have the following code to wait for "Progressing Pop up" to disappear.
It seems it waits only for some seconds and terminates the script. Please let me know what are the other option?
public static void ProcessingData() throws Exception {
WebDriverWait wait1 = new WebDriverWait( driver , 180 );
wait1.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//div[#class='dijitDialogPaneContent']/div/p/b[contains(text()='Processing ...']")));
}
You placed your timeout on 180, which is 180 milliseconds. You probably mean 180 seconds? So use 180000.
I'd take a closer look at your xpath selector... you are providing
...b[contains(text()='Processing ...']
If you know that the text is equal to processing, then you should use
...b[text()='Processing ...'].
If you know that the text CONTAINS Processing ... then you should use,
...b[contains(text(), 'Processing ...']