Continue loop after getting alert test from browser in protractor jasmine test
up vote
0
down vote
favorite
I am implementing Protrator framework with jasmine runner in my angular app. I click on each element with expected result. Now I have a list of companies in my app. each company has two or three machines is side bar. I implemented two for loops that with loop throug the company and machines as well. Now in one machine list there is an error and as a result is shows alert from localhost. For this reason the loop breaks and fails. I want to implement a condition there so that it can detect the condition and continue from the loop. But I could not get it how can I implement that.
My test code
for (let company = 0; company < await companyOption.count(); company++) {
await companyOption.get(company);
for (let machine = 0; machine < await machineList.count(); machine++) {
await click.onto(machineList.get(machine));
if (window.alert()) {
//here i want to implement if browser.switchto.alert() is appear then test should be continue to next loop
} else {
await expect(machineList.get(machine).isSelected());
}
.................... other code
}
Alert code in typescript
ngOnInit() {
this.route.paramMap.switchMap((params: ParamMap, index) => this.machineService.load(parseInt(params.get("machineId")))).subscribe(machine => {
this.machine = machine;
if (this.machine.type === null)
window.alert("No machine type assigned for " + this.machine.name + "nAssign a type to view the details.");
});
}
javascript angular protractor jasmin
New contributor
add a comment |
up vote
0
down vote
favorite
I am implementing Protrator framework with jasmine runner in my angular app. I click on each element with expected result. Now I have a list of companies in my app. each company has two or three machines is side bar. I implemented two for loops that with loop throug the company and machines as well. Now in one machine list there is an error and as a result is shows alert from localhost. For this reason the loop breaks and fails. I want to implement a condition there so that it can detect the condition and continue from the loop. But I could not get it how can I implement that.
My test code
for (let company = 0; company < await companyOption.count(); company++) {
await companyOption.get(company);
for (let machine = 0; machine < await machineList.count(); machine++) {
await click.onto(machineList.get(machine));
if (window.alert()) {
//here i want to implement if browser.switchto.alert() is appear then test should be continue to next loop
} else {
await expect(machineList.get(machine).isSelected());
}
.................... other code
}
Alert code in typescript
ngOnInit() {
this.route.paramMap.switchMap((params: ParamMap, index) => this.machineService.load(parseInt(params.get("machineId")))).subscribe(machine => {
this.machine = machine;
if (this.machine.type === null)
window.alert("No machine type assigned for " + this.machine.name + "nAssign a type to view the details.");
});
}
javascript angular protractor jasmin
New contributor
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am implementing Protrator framework with jasmine runner in my angular app. I click on each element with expected result. Now I have a list of companies in my app. each company has two or three machines is side bar. I implemented two for loops that with loop throug the company and machines as well. Now in one machine list there is an error and as a result is shows alert from localhost. For this reason the loop breaks and fails. I want to implement a condition there so that it can detect the condition and continue from the loop. But I could not get it how can I implement that.
My test code
for (let company = 0; company < await companyOption.count(); company++) {
await companyOption.get(company);
for (let machine = 0; machine < await machineList.count(); machine++) {
await click.onto(machineList.get(machine));
if (window.alert()) {
//here i want to implement if browser.switchto.alert() is appear then test should be continue to next loop
} else {
await expect(machineList.get(machine).isSelected());
}
.................... other code
}
Alert code in typescript
ngOnInit() {
this.route.paramMap.switchMap((params: ParamMap, index) => this.machineService.load(parseInt(params.get("machineId")))).subscribe(machine => {
this.machine = machine;
if (this.machine.type === null)
window.alert("No machine type assigned for " + this.machine.name + "nAssign a type to view the details.");
});
}
javascript angular protractor jasmin
New contributor
I am implementing Protrator framework with jasmine runner in my angular app. I click on each element with expected result. Now I have a list of companies in my app. each company has two or three machines is side bar. I implemented two for loops that with loop throug the company and machines as well. Now in one machine list there is an error and as a result is shows alert from localhost. For this reason the loop breaks and fails. I want to implement a condition there so that it can detect the condition and continue from the loop. But I could not get it how can I implement that.
My test code
for (let company = 0; company < await companyOption.count(); company++) {
await companyOption.get(company);
for (let machine = 0; machine < await machineList.count(); machine++) {
await click.onto(machineList.get(machine));
if (window.alert()) {
//here i want to implement if browser.switchto.alert() is appear then test should be continue to next loop
} else {
await expect(machineList.get(machine).isSelected());
}
.................... other code
}
Alert code in typescript
ngOnInit() {
this.route.paramMap.switchMap((params: ParamMap, index) => this.machineService.load(parseInt(params.get("machineId")))).subscribe(machine => {
this.machine = machine;
if (this.machine.type === null)
window.alert("No machine type assigned for " + this.machine.name + "nAssign a type to view the details.");
});
}
javascript angular protractor jasmin
javascript angular protractor jasmin
New contributor
New contributor
edited 2 days ago
New contributor
asked 2 days ago
nick_tec
12
12
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Try this
for (let company = 0; company < await companyOption.count(); company++) {
await companyOption.get(company);
for (let machine = 0; machine < await machineList.count(); machine++) {
await click.onto(machineList.get(machine));
// solution! //
let errorMessage; // define a variable, which is currently undefined
try {
// try run this code, if alert is not present it'll throw an error
// if alert is present it skips is
await browser.switchTo().alert().accept();
} catch (e) {
// if there was no alert and an error was thrown than assign error to variable
// if there was alert this block will be skipped and errorMessage will stay undefined
errorMessage = e.message;
}
// this block will be executed if alert was present!
// otherwise do nothing
if (errorMessage !== undefined) {
// ... your code here ...
}
// end of solution //
}
I checked my code and it is working, if still doesn't work, look for mistakes in YOUR part of the code
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Try this
for (let company = 0; company < await companyOption.count(); company++) {
await companyOption.get(company);
for (let machine = 0; machine < await machineList.count(); machine++) {
await click.onto(machineList.get(machine));
// solution! //
let errorMessage; // define a variable, which is currently undefined
try {
// try run this code, if alert is not present it'll throw an error
// if alert is present it skips is
await browser.switchTo().alert().accept();
} catch (e) {
// if there was no alert and an error was thrown than assign error to variable
// if there was alert this block will be skipped and errorMessage will stay undefined
errorMessage = e.message;
}
// this block will be executed if alert was present!
// otherwise do nothing
if (errorMessage !== undefined) {
// ... your code here ...
}
// end of solution //
}
I checked my code and it is working, if still doesn't work, look for mistakes in YOUR part of the code
add a comment |
up vote
0
down vote
Try this
for (let company = 0; company < await companyOption.count(); company++) {
await companyOption.get(company);
for (let machine = 0; machine < await machineList.count(); machine++) {
await click.onto(machineList.get(machine));
// solution! //
let errorMessage; // define a variable, which is currently undefined
try {
// try run this code, if alert is not present it'll throw an error
// if alert is present it skips is
await browser.switchTo().alert().accept();
} catch (e) {
// if there was no alert and an error was thrown than assign error to variable
// if there was alert this block will be skipped and errorMessage will stay undefined
errorMessage = e.message;
}
// this block will be executed if alert was present!
// otherwise do nothing
if (errorMessage !== undefined) {
// ... your code here ...
}
// end of solution //
}
I checked my code and it is working, if still doesn't work, look for mistakes in YOUR part of the code
add a comment |
up vote
0
down vote
up vote
0
down vote
Try this
for (let company = 0; company < await companyOption.count(); company++) {
await companyOption.get(company);
for (let machine = 0; machine < await machineList.count(); machine++) {
await click.onto(machineList.get(machine));
// solution! //
let errorMessage; // define a variable, which is currently undefined
try {
// try run this code, if alert is not present it'll throw an error
// if alert is present it skips is
await browser.switchTo().alert().accept();
} catch (e) {
// if there was no alert and an error was thrown than assign error to variable
// if there was alert this block will be skipped and errorMessage will stay undefined
errorMessage = e.message;
}
// this block will be executed if alert was present!
// otherwise do nothing
if (errorMessage !== undefined) {
// ... your code here ...
}
// end of solution //
}
I checked my code and it is working, if still doesn't work, look for mistakes in YOUR part of the code
Try this
for (let company = 0; company < await companyOption.count(); company++) {
await companyOption.get(company);
for (let machine = 0; machine < await machineList.count(); machine++) {
await click.onto(machineList.get(machine));
// solution! //
let errorMessage; // define a variable, which is currently undefined
try {
// try run this code, if alert is not present it'll throw an error
// if alert is present it skips is
await browser.switchTo().alert().accept();
} catch (e) {
// if there was no alert and an error was thrown than assign error to variable
// if there was alert this block will be skipped and errorMessage will stay undefined
errorMessage = e.message;
}
// this block will be executed if alert was present!
// otherwise do nothing
if (errorMessage !== undefined) {
// ... your code here ...
}
// end of solution //
}
I checked my code and it is working, if still doesn't work, look for mistakes in YOUR part of the code
answered 20 hours ago
Sergey Pleshakov
1218
1218
add a comment |
add a comment |
nick_tec is a new contributor. Be nice, and check out our Code of Conduct.
nick_tec is a new contributor. Be nice, and check out our Code of Conduct.
nick_tec is a new contributor. Be nice, and check out our Code of Conduct.
nick_tec is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373159%2fcontinue-loop-after-getting-alert-test-from-browser-in-protractor-jasmine-test%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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