I have (I think) kind of unique problem with js. I'm writing tests using protractor stuff and Jasmine and I need to share data between js files. Is there any way to do that? All the solutions I've found are for webpages and I use just js files.
I look forward to your swift response, if there is any information missing, please let me know and I'll add it immediately.
I have not tested this myself, but maybe you can try to put stuff in the global scope using:
global.mySharedData = {someKey: 'some value'}
// in one of your test files
it('should do something', function() {
global.mySharedData = {someKey: 'some value'}
});
...
// This is in another test suite
it('should do something', function() {
var valueFromFirstTest = global.mySharedData.someKey;
});
http://nodejs.org/api/globals.html
Let me know if it works.
If you need to share dynamic data between files you can also do the following. Here's a working example. What I needed to do was take parts of the URL and use them across different files.
it('should click on one of the clickable profiles', function(){
//Get entity type and entity id before clicking the link
tableEls.get(1).all( by.xpath('./td') ).get(0).element( by.xpath('./a') ).getAttribute('href').then(function(text){
var hrefTokens = text.split('/');
var entityID = hrefTokens[ hrefTokens.length - 1 ];
var entityType = hrefTokens[ hrefTokens.length - 2 ];
browser.params.entityID = entityID;
browser.params.entityType = entityType;
});
tableEls.get(1).all( by.xpath('./td') ).get(0).element( by.xpath('./a') ).click();
browser.sleep(2000);
});
I simply assigned the values that I needed to use in other files to the browser.params
. So in my other files I can access them like this
it('Retrieving JSON Data ...', function(){
var entityID = browser.params.entityID;
var entityType = browser.params.entityType;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With