Cypress test does not terminate - testing

I did write the following e2e test visiting this page for cypress yesterday:
it('Download test: Verify download file', () => {
// check that button is correct
cy.get("#whitepaper-download-button")
.should("be.visible")
.should('have.attr', 'href', 'https://troodi.de/download/358489/');
// check that button has correct file download
cy.request({
url: 'https://troodi.de/download/358489/',
encoding: 'binary',
}).then((response) => {
cy.readFile("cypress/fixtures/whitepaper.pdf", "binary").should("eq", response.body);
})
})
I first check that the button has the correct download and afterwards that the file is the same as the one in the fixtures folder.
Some of the hourly runs overnight on GitHub actions just did not terminate in that test and used the 6hs available for a single step. The output of the cypress run command always looks like that:
Running: test.cy.js (2 of 3)
Whitepaper
√ Section has proper title (7191ms)
The testing does not continue after that. The tests works on my machine when I run it in chrome with cypress open but not always with cypress run.

Related

Fixture.page doesn't change when the second file is starting in testcafe

I have multiple testcafe files , each have a starting page , While running all files together , Fixture.Page doesn't change for the second file , it still taking the first file page url
//////// First fixture in the first file.
fixture('create-TestFixture1').disablePageReloads.page(PageObject.createNavigateUrl + '/TestFixture1')
.beforeEach(async t => {
await t
.maximizeWindow();
});
//////// First fixture in the second file.
fixture('create-TestFixture2').disablePageReloads.page(PageObject.createNavigateUrl + '/TestFixture2')
.beforeEach(async t => {
await t
.maximizeWindow();
});
*Both files are in the same folder, so when running testcafe for this folder, when the first file finished succesfully and the second file start , the fixture for second file doesn't update the page url, it redirects to " 'PageObject.createNavigateUrl + '/TestFixture1' " , not "'PageObject.createNavigateUrl + '/TestFixture2' ".
The disablePageReloads feature is undocumented and experimental. It's subject to change. At the moment, I see no workaround for this multiple fixtures case. You can only split your two disablePageReloads fixtures into two TestCafe runs: testcafe fixture-1.js and testcafe fixture-2.js.

Cypress - run test in iframe

I'm trying to find elements in iframe but it doesn't work.
Is there anyone who have some system to run tests with Cypress in iframe? Some way to get in iframe and work in there.
It's a known issue mentioned here. You can create your own custom cypress command which mocks the iframe feature. Add following function to your cypress/support/commands.js
Cypress.Commands.add('iframe', { prevSubject: 'element' }, ($iframe, selector) => {
Cypress.log({
name: 'iframe',
consoleProps() {
return {
iframe: $iframe,
};
},
});
return new Cypress.Promise(resolve => {
resolve($iframe.contents().find(selector));
});
});
Then you can use it like this:
cy.get('#iframe-id')
.iframe('body #elementToFind')
.should('exist')
Also, because of CORS/same-origin policy reasons, you might have to set chromeWebSecurity to false in cypress.json (Setting chromeWebSecurity to false allows you to access cross-origin iframes that are embedded in your application and also navigate to any superdomain without cross-origin errors).
This is a workaround though, it worked for me locally but not during CI runs.
This works for me locally and via CI. Credit: Gleb Bahmutov iframes blog post
export const getIframeBody = (locator) => {
// get the iframe > document > body
// and retry until the body element is not empty
return cy
.get(locator)
.its('0.contentDocument.body').should('not.be.empty')
// wraps "body" DOM element to allow
// chaining more Cypress commands, like ".find(...)"
// https://on.cypress.io/wrap
.then(cy.wrap)
}
spec file:
let iframeStripe = 'iframe[name="stripe_checkout_app"]'
getIframeBody(iframeStripe).find('button[type="submit"] .Button-content > span').should('have.text', `Buy me`)
that is correct. Cypress doesn't support Iframes. It is simple not possible at the moment. You can follow (and upvote) this ticket: https://github.com/cypress-io/cypress/issues/136

Trying with Nightwatch + Browserstack to set up a simple login test, failing

Using "nightwatch": "^1.0.11" and "browserstack-local": "^1.3.4"
I have tried this many ways, but I cannot get the examples in the documentation to run.
I have a simple login page with a page object
module.exports = {
url: function() {
return this.api.launchUrl + '/login';
},
elements: {
email: {
selector: '#user_login_email'
},
password: {
selector: '#user_login_password'
},
button: {
selector: '#login-btn'
}
}
};
I then want to run a test to login into the site (NOTE: The first screenshot is fine)
module.exports = {
before(client) {
client.maximizeWindow();
},
'Login' : function (client) {
var login = client.page.login();
login.navigate();
client.waitForElementPresent('body', 500)
.saveScreenshot('tests_output/login.png');
login.setValue('#email', 'test#user.email')
.setValue('#password', 'Pa55w0rd')
.click('#button');
client.pause(1000)
.saveScreenshot('tests_output/login-complete.png');
},
after(client) {
client.end();
}
};
I get the following errors when trying to run the test through browserstack (with the local URL)
✖ login.test
– Login (5.196s)
An error occurred while running .setValue() command on <Element [name=#email]>: Error: First argument passed to .elementIdValue() should be a web element ID string. Received object.
at Function.validateElementId (node_modules/nightwatch/lib/api/protocol.js:36:19)
at ProtocolActions.elementIdValue (node_modules/nightwatch/lib/api/protocol.js:951:25)
at transport.locateElement.then.result (node_modules/nightwatch/lib/api-loader/element-command.js:106:54)
at process._tickCallback (internal/process/next_tick.js:68:7)
at process._tickCallback (internal/process/next_tick.js:68:7)
at process._tickCallback (internal/process/next_tick.js:68:7)
An error occurred while running .setValue() command on <Element [name=#password]>: Error: First argument passed to .elementIdValue() should be a web element ID string. Received object.
[...]
An error occurred while running .click() command on <Element [name=#button]>: Error: First argument passed to .elementIdClick() should be a web element ID string. Received object.
[...]
I have gotten successful tests to run; just not using the documented examples.
For example, the below code works fine to close a cookie message
client
.waitForElementPresent('.cookie-message__button', 5, true, function(result) {
client.elementIdClick(result.value[0].ELEMENT);
})
.saveScreenshot('tests_output/cookie-closed.png');
But obviously it's really long winded.
Any help for what I'm doing wrong would be awesome.
Using the following as an example for the Nightwatch config: https://github.com/browserstack/nightwatch-browserstack/blob/master/conf/local.conf.js with the local runner and running tests in parallel in 3 browsers: https://github.com/browserstack/nightwatch-browserstack/blob/master/scripts/local.runner.js
TL;DR: Documentation examples don't work with version 1.0.11; but Nightwatch and Browserstack are configured correctly as can get a suite to run (in Travis and locally), just with very long-winded code, which I hacked together.
I have created sample project for page objects model here. Also, sample login test is added using page_objects_path.
The compatibility for latest nightwatch version is also added. The latest version of nightwatch seems to have changes which are in compliant with w3c. So we need to use 'browserName' as capability instead of 'browser'

Concern regarding automation using Protractor

Am new to protractor. I found some errors while automating the URL using protractor. And I can access the URL manually and does not find any issues. Please find the code mentioned below and kindly clarify my concern.
Screenshot of cmd while executing the code
exports.config={
specs: ['try.js'],
//seleniumArgs: ['-browserTimeout=60']
capabilities:{
'browserName':'chrome',
},
baseUrl:'',
allScriptsTimeout:3000,
//getPageTimeout:5000,
framework:'jasmine2',
jasmineNodeOpts: {
defaultTimeoutInterval:56000,
isVerbose: true,
}
}
spec: try.js
===========
describe('first try',function(){
var EW=protractor.ExpectedConditions;
beforeEach(function(done){
ignoreSynchronization=true;
browser.get('');
});
it('open PO',function(){
//clicking login button
var login=element(by.linkText('Login'));
browser.wait(EW.presenceOf(login),10000);
login.click();
//clicking open Po dashboard icon/link
var po=element(by.linkText('Open PO'));
browser.wait(EW.presenceOf(po),20000);
po.click();
//entering value 100 in the fiter field
var e=element.all(by.repeater('colFilter in col.filters')).get(00).element(by.tagName('input'));
browser.wait(EW.presenceOf(e),10000);
e.sendKeys(100);
//selecting the filterd values and printing it in console
element.all(by.repeater('col in colContainer.renderedColumns track by col.uid').column('Entity')).getText().then(console.log);
});
});
Make sure you have ng-app defined on all of your pages. Protractor requires it to run. If the page has redirects or just takes some time before it loads, try something like this:
browser.get(websiteUrl);
browser.wait(function () {
return browser.executeScript('return !!window.angular');
}, 10000, 'Error: Angular was not found on the page within ten seconds');
This will wait up to ten seconds for angular to load up, and fail if it is not there.

AngularJS : Running e2e tests using Karma

I want to run my Jasmine e2e tests using KarmaJS (0.9.2). I use Google Closure with AngularJS (1.0.7) on Windows 7. When I start karma using karma start config\karma-e2e.js everything works fine (browser navigates to correct page) but it doesn't execute my tests (stops on 'browser navigate to').
The config\karma-e2e.js file:
basePath = '../';
frameworks = ['ng-scenario'];
files = [
'tests/e2e/**/*.js'
];
autoWatch = true;
singleRun = false;
browsers = ['Chrome'];
urlRoot = '/__karma/';
proxies = {
'/': 'http://localhost:8080/'
}
plugins = [
'karma-ng-scenario'
'karma-chrome-launcher'
]
Test source (tests\e2e\scenarios.coffee) is:
describe 'Intro page view', ->
it 'has hello world message', ->
browser().navigateTo '/app/client/'
expect(element('#text').text()).toBe 'Hello World'
I'm using html5Mode routes, angular is bootstraped manualy using angular.bootstrap, all my coffee scripts are compiled by IDE and I see no errors in browser console or command line. So how should I do it? Am I doing something wrong?
Thanks!
I solved this problem. Seems angular scenario needs ng-app directive which is at least weird (or it's a bug). So I added ng-app attribute to body after calling App.bootstrap() on index page. Everything works fine now.
<script type="text/javascript">
App.bootstrap();
document.body.setAttribute('ng-app', 'App');
</script>