I have to run some tests agains a live site.
I have to pretty much just make tasks to wait on a website to time out (15 minutes), then run another task, once that has passed.
the longest i got it to wait is 26.6 seconds (26600 ms) on firefox, and about 30 on chrome.
I get the following error :
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
so basically i need adjust the specified timeout from jasmine to run this:
browser.get('www.page.com');
browser.sleep(900000);
browser.doSomethingElse();
This is a jasmine timeout happening in your case. You need to tell Jasmine that it's okay it takes time. You can set the timeout globally in jasmineNodeOpts in your config:
jasmineNodeOpts: {
defaultTimeoutInterval: 200000,
}
Or, you can also set it on a spec level (example here).
beforeEach(function(){
browser.waitForAngular();
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000000;
});
Related
I will be gone for a weekend and I need a node.js file to run at a specific time and date. I have not found any way to do this through javascript, but apparently cron works (I am running linux).
I created an sh file that runs the nod.js file and had it run through cron, but it did not run at all. I don't know if this has anything to do with Puppeteer + Node.js, but no script ran...
I also tried using the at command but that did not work either
For cron, I added the line:
20 14 2 5 * ~/.../start.sh
The sh file was:
#!/bin/bash
cd Documents/node_bot/
node fog1.js
If you want a node application to run a particular piece of code at a particular time you can run a setTimeout() recursive "loop" that checks the time every few milliseconds. If the specific time hasn't passed, the setTimeout() callback calls itself and the process starts over. However, if the time is passed, execute a specific code block and stop the recursion loop.
const triggerTime = new Date(2019, 05, 05, 02, 30, 0, 0)
function otherCodeToRun() {
// do something...
}
function wait() {
setTimeout(function() {
const currentTime = new Date()
if (currentTime >= triggerTime) {
otherCodeToRun() // not calling wait ends the recursive loop
} else {
wait() // recursively call wait after the timeout completes
}
}, 1000) // wait 1 second
}
Theoretically, that otherCodeToRun() function could call another node process to run your other file, or it could load your other file as a module and run it that way.
Also worth noting is that you could perform this check inside a while loop, however, the application will block completely, meaning it will appear unresponsive and can take up a lot of CPU cycles. The setTimeout approach gives your application a chance to yield to other processes, allowing you to log output to the console, say, if you want to display a countdown.
It should probably look more like this (absolute paths just in case):
20 14 2 5 * cd /path/to/Documents/node_bot && /path/to/node fog1.js
This runs on May 2 at 14:20
I'm writing unit tests for a simple javascript...
Karma v1.5.0
Jasmine v2.5.3
PhantomJS v2.1.14
I'm trying to write a test to ensure that a cookie is getting the proper expiration date (30 days). Recent versions of Jasmine support faking the passage of time using jasmine.clock() but this doesn't appear to work on cookie expiration...
describe("cookies...", function () {
it("expire after 30 days", function () {
jasmine.clock().install();
set_a_cookie_to_expire_in_30_days();
jasmine.clock().tick(29 *24*60*60*1000); //fast forward 29 days
expect(check_cookie()).toBeTruthy();
jasmine.clock().tick(2 *24*60*60*1000); //fast forward another 2 days
expect(check_cookie()).toBeFalsy(); //THIS FAILS
jasmine.clock().uninstall();
});
});
The second expect() fails. What am I doing wrong?
The Jasmine clock tick won't actually affect time passing in the browser. It will only execute callbacks for setTimeouts or setIntervals.
From their docs:
The Jasmine Clock is available for a test suites that need the ability to use setTimeout or setInterval callbacks. It makes the timer callbacks synchronous, executing the registered functions only once the clock is ticked forward in time. This makes timer-related code much easier to test.
You should instead use mockDate.
jasmine.clock().mockDate(
new Date(2018, 5, 11)
);
Where you tick forward 29 days, you can simply mockDate again 29 days forward. Hope this helps!
I have this test code:
element(by.cssContainingText('a[ng-click="select()"]', 'Visual')).click()
browser.sleep(1000)
expect(element.all(by.tagName('angular-chart')).count()).toEqual(1);
But it hangs until timeout reach and then shows:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
I suppose I need to wait for the content to load somehow then run the test?
If I replace the expect construct with the one below, it passes:
expect(true).toEqual(true)
Try this:
element(by.cssContainingText('a[ng-click="select()"]', 'Visual')).click().then( function(){
expect(element.all(by.tagName('angular-chart')).count()).toEqual(1);
});
Most calls in protractor returns a promise.
http://www.protractortest.org/#/api?view=webdriver.WebElement.prototype.click
Let's try adding an explicit wait to wait for the angular-chart element to become present:
var EC = protractor.ExpectedConditions;
element(by.cssContainingText('a[ng-click="select()"]', 'Visual')).click()
var chart = element(by.tagName('angular-chart'));
browser.wait(EC.presenceOf(chart), 10000);
You might also look into increasing jasmine timeout intervals.
This is basically a follow-up to Remove timeout for single jasmine spec github issue.
The question:
Is it possible to make a single test never timeout?
The problem:
It is possible to set a timeout value globally via DEFAULT_TIMEOUT_INTERVAL or for every describe with beforeEach/afterEach or on a single it() block:
it('Has a custom timeout', function() {
expect(true).toBeTruthy();
}, value in msec)
I'm interested in having a single spec never timeout. I've tried to follow the advice proposed in the mentioned github issue and use Infinity:
it('Has a custom timeout', function() {
expect(true).toBeTruthy();
}, Infinity)
but, I've got the following error immediately after the tests got into the it() block:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL
I guess I cannot use Infinity as a timeout value, or I'm doing something wrong.
As a workaround, I can use a hardcoded large number instead, but I'd like to avoid that.
Jasmine internally uses setTimeout to wait for specs to finish for a defined period of time.
According to this Q/A - Why does setTimeout() "break" for large millisecond delay values?:
setTimeout using a 32 bit int to store the delay
...
Timeout values too big to fit into a signed 32-bit integer may cause
overflow in FF, Safari, and Chrome, resulting in the timeout being
scheduled immediately. It makes more sense simply not to schedule
these timeouts, since 24.8 days is beyond a reasonable expectation for
the browser to stay open.
As soon as Infinity is greater than any other number the overflow occurs.
The max safe integer in this case is 231-1 = 2147483647. This value is finite, so the test won't actually run infinitely long, but as said I think 24.8 days is long enough.
You can define a constant to store this value:
jasmine.DEFAULT_TIMEOUT_INTERVAL = 2000;
var MAX_SAFE_TIMEOUT = Math.pow(2, 31) - 1;
describe('suite', function () {
it('should work infinitely long', function (done) {
setTimeout(function () {
expect(true).toBe(true);
done();
}, 3000)
}, MAX_SAFE_TIMEOUT);
});
See working sample here
I'm using angular-growl-v2 notifications in my app.
They work ok, the problem comes on my protractor tests. I have to use a TTL (around 6 seconds) as it is a requirement. Then I have the following test:
it('should send a request and notify the user about the result',function(){
detailPage.verifyEmailtButton.click().then(function(){
var expectedDiv = element(by.css('.alert-success'));
expect(expectedDiv).toBeDefined();
});
});
But it is always throwing an error:
NoSuchElementError: No element found using locator: By.cssSelector(".alert-success")
This does not happens when the TLL is -1.
Someone can help here? Thanks in advance.
angular-growl-2 uses $timeout, which doesn't play nicely with protractor: protractor waits for the timeout to end before it completes its sync with angular process.
So by the time it reaches your expect call, the timeout has elapsed and the alert is no longer there. Check out the Waiting for page synchronization section of this doc:
https://github.com/angular/protractor/blob/master/docs/timeouts.md
(This page relates to timeouts, which you don't appear to be experiencing, but since the default timeout is 11 seconds, it could well be that the entire process, including your 6 second TTL, takes place before a timeout happens)
There's a PR to angular-growl-v2 to use $interval instead of $timeout, but its currently waiting for tests:
https://github.com/JanStevens/angular-growl-2/pull/85
Explicitly wait for the alert to be present after clicking the button:
detailPage.verifyEmailtButton.click();
var EC = protractor.ExpectedConditions;
var expectedDiv = element(by.css('.alert-success'));
browser.wait(EC.presenceOf(expectedDiv), 10000, "No alert present");