0
處理任何形式的錯誤/斷言錯誤的正確方法是什麼,以便當一個測試用例失敗時,後續測試仍然運行?或者在1個JavaScript文件中只有1個測試用例對我更好些?正確的方法來處理斷言錯誤,以便後續測試可以運行
describe('SMP Service Login Page', function() {
describe('Loggin in', function() {
// Unhappy flow always first
var assert = require('assert');
var useridField;
var passwordField;
var loginButton;
it('should not allow user to login with wrong userid', function(done) {
throw new Error("haha");
});
it('should fail because of assertion', function(done) {
useridField = browser.element('android=new UiSelector().text("User Name").className("android.widget.EditText")');
useridField.setValue('FIRST');
console.log(useridField);
passwordField = browser.element('android=new UiSelector().className("android.widget.EditText").instance(1)');
passwordField.setValue('FIRST');
loginButton = browser.element('android=new UiSelector().resourceId("android:id/button1")');
var text = loginButton.getText(); //text = 'LOG IN'
assert.equal(text,'LOG'); //this should fail , throws an error
loginButton.click(done);
});
//this test doesn't get run cause of assertion error thrown
it('should pass but it fails because it could not locate the useridField', function(done) {
console.log(useridField);
useridField.setValue('userid');
passwordField = browser.element('android=new UiSelector().className("android.widget.EditText").instance(1)');
passwordField.setValue('passsword');
loginButton = browser.element('android=new UiSelector().resourceId("android:id/button1")');
loginButton.click(done);
});
});
});
yeap。我意識到失敗的斷言會拋出。目前的測試跑步者不會報告錯誤並繼續測試。 – user1166085