I am unable to use synchronous functions and asynchronous functions of JavaScript in protractor-cucumber...











up vote
0
down vote

favorite












I am using JavaScript for my protractor cucumber framework.the synchronous code is executing first and asynchronous code is running background.

a glimpse of my code:



When(/^I select the required "(.*?)" collection "(.*?)" from Select Collection Modal Window "(.*?)","(.*?)","(.*?)","(.*?)","(.*?)","(.*?)"$/,(collection_type,collection_name,level,tag,level1,tag1,level2,tag2)=>{
bid_config.click_Tag_Assignment();

bid_config.click_Select_Collections();
expect(bid_config.select_Collection_modal_window.isDisplayed()).to.be.eventually.true;
bid_config.Select_Collection(collection_type,collection_name);
//bid_config.Select_Bid_Collection(collection_name);
bid_config.get_Entity_type_Drop_down_Text('H9 - Commodity/Entity');
bid_config.AssignTags_to_WBS_Levels(level,tag,level1,tag1,level2,tag2);


})


my problem is get_Entity_type_Drop_Down_text() is executing first and the select_Collections function() is processing in background
the code both the functions:



Select_Collection(collection_type,name){

var Collection_names = ;
var Collection_type_names = ;



(async()=>{

var get_collections_count = await this.get_collections_count();
for(var i=0;i<get_collections_count;i++){

Collection_names[i] = await this.Get_Collection_name(i);
console.log("the collection name is "+Collection_names[i]);
Collection_type_names[i] = await this.get_Collections_type(i);
console.log("the collection type is "+ Collection_type_names[i]);

if((collection_type === Collection_type_names[i]) && (Collection_names[i] === name)){

var click_Checkbox = element.all(by.xpath("//*[@class='ReactVirtualized__Table__rowColumn list-body-cell '][1]//*[@class='csc-checkbox-element']")).get(i);
click_Checkbox.click();
var click_add_collection_arrow = element.all(by.xpath("//*[@class='separator transfer-block']//button[@class='btn btn-success btn-sm']")).get(0);
//helper.waitForbuttonElement(click_add_collection_arrow);
browser.actions().click(click_add_collection_arrow).perform();
//click_add_collection_arrow.click();
var OK = element(by.xpath("//button[@class='btn btn-success' and @type = 'button']"));
browser.actions().click(OK).perform();
return browser.sleep(1000);

//return OK.click();
}

}

})();

}



get_Entity_type_Drop_down_Text(req_level){

element(by.xpath("//button[@class='btn btn-link dropdown-toggle']")).getText().then((text)=>{
console.log(text);

if(text === 'Commodities'){

let clickexpandDetails = element(by.xpath("//*[text()='Expand Details']"));
//helper.waitForbuttonElement(clickexpandDetails);
clickexpandDetails.click();
//H9 - Commodity/Entity']
let xpath_level = "//*[@class='dropdown-menu']//li[text()='"+req_level+"']";
let select_level = element(by.xpath(xpath_level));
//helper.waitForbuttonElement(select_level);
return browser.actions().click(select_level).perform();

}
})
}


please give me some suggestions to wait the synchronous code before the asynchronous code executes










share|improve this question






















  • My suggestion for you to rewrite everything you have to async functions. I've been struggling with this for a while, and had to redo to get rig of the problem and don't regret of time spent for this
    – Sergey Pleshakov
    5 hours ago















up vote
0
down vote

favorite












I am using JavaScript for my protractor cucumber framework.the synchronous code is executing first and asynchronous code is running background.

a glimpse of my code:



When(/^I select the required "(.*?)" collection "(.*?)" from Select Collection Modal Window "(.*?)","(.*?)","(.*?)","(.*?)","(.*?)","(.*?)"$/,(collection_type,collection_name,level,tag,level1,tag1,level2,tag2)=>{
bid_config.click_Tag_Assignment();

bid_config.click_Select_Collections();
expect(bid_config.select_Collection_modal_window.isDisplayed()).to.be.eventually.true;
bid_config.Select_Collection(collection_type,collection_name);
//bid_config.Select_Bid_Collection(collection_name);
bid_config.get_Entity_type_Drop_down_Text('H9 - Commodity/Entity');
bid_config.AssignTags_to_WBS_Levels(level,tag,level1,tag1,level2,tag2);


})


my problem is get_Entity_type_Drop_Down_text() is executing first and the select_Collections function() is processing in background
the code both the functions:



Select_Collection(collection_type,name){

var Collection_names = ;
var Collection_type_names = ;



(async()=>{

var get_collections_count = await this.get_collections_count();
for(var i=0;i<get_collections_count;i++){

Collection_names[i] = await this.Get_Collection_name(i);
console.log("the collection name is "+Collection_names[i]);
Collection_type_names[i] = await this.get_Collections_type(i);
console.log("the collection type is "+ Collection_type_names[i]);

if((collection_type === Collection_type_names[i]) && (Collection_names[i] === name)){

var click_Checkbox = element.all(by.xpath("//*[@class='ReactVirtualized__Table__rowColumn list-body-cell '][1]//*[@class='csc-checkbox-element']")).get(i);
click_Checkbox.click();
var click_add_collection_arrow = element.all(by.xpath("//*[@class='separator transfer-block']//button[@class='btn btn-success btn-sm']")).get(0);
//helper.waitForbuttonElement(click_add_collection_arrow);
browser.actions().click(click_add_collection_arrow).perform();
//click_add_collection_arrow.click();
var OK = element(by.xpath("//button[@class='btn btn-success' and @type = 'button']"));
browser.actions().click(OK).perform();
return browser.sleep(1000);

//return OK.click();
}

}

})();

}



get_Entity_type_Drop_down_Text(req_level){

element(by.xpath("//button[@class='btn btn-link dropdown-toggle']")).getText().then((text)=>{
console.log(text);

if(text === 'Commodities'){

let clickexpandDetails = element(by.xpath("//*[text()='Expand Details']"));
//helper.waitForbuttonElement(clickexpandDetails);
clickexpandDetails.click();
//H9 - Commodity/Entity']
let xpath_level = "//*[@class='dropdown-menu']//li[text()='"+req_level+"']";
let select_level = element(by.xpath(xpath_level));
//helper.waitForbuttonElement(select_level);
return browser.actions().click(select_level).perform();

}
})
}


please give me some suggestions to wait the synchronous code before the asynchronous code executes










share|improve this question






















  • My suggestion for you to rewrite everything you have to async functions. I've been struggling with this for a while, and had to redo to get rig of the problem and don't regret of time spent for this
    – Sergey Pleshakov
    5 hours ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am using JavaScript for my protractor cucumber framework.the synchronous code is executing first and asynchronous code is running background.

a glimpse of my code:



When(/^I select the required "(.*?)" collection "(.*?)" from Select Collection Modal Window "(.*?)","(.*?)","(.*?)","(.*?)","(.*?)","(.*?)"$/,(collection_type,collection_name,level,tag,level1,tag1,level2,tag2)=>{
bid_config.click_Tag_Assignment();

bid_config.click_Select_Collections();
expect(bid_config.select_Collection_modal_window.isDisplayed()).to.be.eventually.true;
bid_config.Select_Collection(collection_type,collection_name);
//bid_config.Select_Bid_Collection(collection_name);
bid_config.get_Entity_type_Drop_down_Text('H9 - Commodity/Entity');
bid_config.AssignTags_to_WBS_Levels(level,tag,level1,tag1,level2,tag2);


})


my problem is get_Entity_type_Drop_Down_text() is executing first and the select_Collections function() is processing in background
the code both the functions:



Select_Collection(collection_type,name){

var Collection_names = ;
var Collection_type_names = ;



(async()=>{

var get_collections_count = await this.get_collections_count();
for(var i=0;i<get_collections_count;i++){

Collection_names[i] = await this.Get_Collection_name(i);
console.log("the collection name is "+Collection_names[i]);
Collection_type_names[i] = await this.get_Collections_type(i);
console.log("the collection type is "+ Collection_type_names[i]);

if((collection_type === Collection_type_names[i]) && (Collection_names[i] === name)){

var click_Checkbox = element.all(by.xpath("//*[@class='ReactVirtualized__Table__rowColumn list-body-cell '][1]//*[@class='csc-checkbox-element']")).get(i);
click_Checkbox.click();
var click_add_collection_arrow = element.all(by.xpath("//*[@class='separator transfer-block']//button[@class='btn btn-success btn-sm']")).get(0);
//helper.waitForbuttonElement(click_add_collection_arrow);
browser.actions().click(click_add_collection_arrow).perform();
//click_add_collection_arrow.click();
var OK = element(by.xpath("//button[@class='btn btn-success' and @type = 'button']"));
browser.actions().click(OK).perform();
return browser.sleep(1000);

//return OK.click();
}

}

})();

}



get_Entity_type_Drop_down_Text(req_level){

element(by.xpath("//button[@class='btn btn-link dropdown-toggle']")).getText().then((text)=>{
console.log(text);

if(text === 'Commodities'){

let clickexpandDetails = element(by.xpath("//*[text()='Expand Details']"));
//helper.waitForbuttonElement(clickexpandDetails);
clickexpandDetails.click();
//H9 - Commodity/Entity']
let xpath_level = "//*[@class='dropdown-menu']//li[text()='"+req_level+"']";
let select_level = element(by.xpath(xpath_level));
//helper.waitForbuttonElement(select_level);
return browser.actions().click(select_level).perform();

}
})
}


please give me some suggestions to wait the synchronous code before the asynchronous code executes










share|improve this question













I am using JavaScript for my protractor cucumber framework.the synchronous code is executing first and asynchronous code is running background.

a glimpse of my code:



When(/^I select the required "(.*?)" collection "(.*?)" from Select Collection Modal Window "(.*?)","(.*?)","(.*?)","(.*?)","(.*?)","(.*?)"$/,(collection_type,collection_name,level,tag,level1,tag1,level2,tag2)=>{
bid_config.click_Tag_Assignment();

bid_config.click_Select_Collections();
expect(bid_config.select_Collection_modal_window.isDisplayed()).to.be.eventually.true;
bid_config.Select_Collection(collection_type,collection_name);
//bid_config.Select_Bid_Collection(collection_name);
bid_config.get_Entity_type_Drop_down_Text('H9 - Commodity/Entity');
bid_config.AssignTags_to_WBS_Levels(level,tag,level1,tag1,level2,tag2);


})


my problem is get_Entity_type_Drop_Down_text() is executing first and the select_Collections function() is processing in background
the code both the functions:



Select_Collection(collection_type,name){

var Collection_names = ;
var Collection_type_names = ;



(async()=>{

var get_collections_count = await this.get_collections_count();
for(var i=0;i<get_collections_count;i++){

Collection_names[i] = await this.Get_Collection_name(i);
console.log("the collection name is "+Collection_names[i]);
Collection_type_names[i] = await this.get_Collections_type(i);
console.log("the collection type is "+ Collection_type_names[i]);

if((collection_type === Collection_type_names[i]) && (Collection_names[i] === name)){

var click_Checkbox = element.all(by.xpath("//*[@class='ReactVirtualized__Table__rowColumn list-body-cell '][1]//*[@class='csc-checkbox-element']")).get(i);
click_Checkbox.click();
var click_add_collection_arrow = element.all(by.xpath("//*[@class='separator transfer-block']//button[@class='btn btn-success btn-sm']")).get(0);
//helper.waitForbuttonElement(click_add_collection_arrow);
browser.actions().click(click_add_collection_arrow).perform();
//click_add_collection_arrow.click();
var OK = element(by.xpath("//button[@class='btn btn-success' and @type = 'button']"));
browser.actions().click(OK).perform();
return browser.sleep(1000);

//return OK.click();
}

}

})();

}



get_Entity_type_Drop_down_Text(req_level){

element(by.xpath("//button[@class='btn btn-link dropdown-toggle']")).getText().then((text)=>{
console.log(text);

if(text === 'Commodities'){

let clickexpandDetails = element(by.xpath("//*[text()='Expand Details']"));
//helper.waitForbuttonElement(clickexpandDetails);
clickexpandDetails.click();
//H9 - Commodity/Entity']
let xpath_level = "//*[@class='dropdown-menu']//li[text()='"+req_level+"']";
let select_level = element(by.xpath(xpath_level));
//helper.waitForbuttonElement(select_level);
return browser.actions().click(select_level).perform();

}
})
}


please give me some suggestions to wait the synchronous code before the asynchronous code executes







javascript protractor cucumber






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 15 hours ago









vuppuluri atchyutha rama dixit

92




92












  • My suggestion for you to rewrite everything you have to async functions. I've been struggling with this for a while, and had to redo to get rig of the problem and don't regret of time spent for this
    – Sergey Pleshakov
    5 hours ago


















  • My suggestion for you to rewrite everything you have to async functions. I've been struggling with this for a while, and had to redo to get rig of the problem and don't regret of time spent for this
    – Sergey Pleshakov
    5 hours ago
















My suggestion for you to rewrite everything you have to async functions. I've been struggling with this for a while, and had to redo to get rig of the problem and don't regret of time spent for this
– Sergey Pleshakov
5 hours ago




My suggestion for you to rewrite everything you have to async functions. I've been struggling with this for a while, and had to redo to get rig of the problem and don't regret of time spent for this
– Sergey Pleshakov
5 hours ago

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371924%2fi-am-unable-to-use-synchronous-functions-and-asynchronous-functions-of-javascrip%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371924%2fi-am-unable-to-use-synchronous-functions-and-asynchronous-functions-of-javascrip%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]