我无法通过 Jasmine JS 在我的测试用例中创建“if 语句”。
错误是错误的定位器,但我很确定这是因为出了点问题
使用我的语法,而不是因为定位器错误。
** 测试用例,注意“screen 4”的代码块**
describe ('Onboarding - English registration', function() {
beforeEach(function(){
browser.ignoreSynchronization = true;
});
afterEach(function(){
browser.ignoreSynchronization = false;
});
it ('Enter to Home Page', function() {
homePage();
});
it ('Click on the start button onboarding - screen 1', function() {
browser.driver.sleep(2000);
element (by.id('START_BUTTON')).click();
browser.driver.sleep(2000);
expect (element(by.binding('industry[0]')).isPresent()).toBe(true);
browser.driver.sleep(2000);
captureScreen("onboarding-screen1");
browser.driver.sleep(3000);
});
it ('onboarding - screen 2', function() {
//TO-DO:
//element.all(by.css('.industry input[type="radio"]')).get(Math.floor(Math.random() * 11)).click()
//var randIndustry = "industry_" + Math.floor(Math.random() * (12 - 0 + 1));
//browser.driver.sleep(2000);
//$('.randIndustryr').click();
element (by.css ("li.ng-scope.icon-laptop > label.ng-binding")).click();
browser.driver.sleep(1000);
element (by.xpath("//div[1]/div/main/div[3]/section/div/form/div[1]/section[2]/div/ul/li[4]/label")).click();
browser.driver.sleep(2000);
element (by.css('input.btn')).click();
browser.driver.sleep(3000);
expect (element(by.css('form.ng-pristine.ng-valid')).isPresent()).toBe(true);
captureScreen("onboarding-screen2");
browser.driver.sleep(3000);
});
it ('onboarding - screen 3', function() {
element (by.xpath("//div[1]/div/main/div[3]/section/div/section/form/div[1]/div[2]/input")).click();
browser.driver.sleep(3000);
element (by.css("input.btn")).click();
browser.driver.sleep(3000);
expect (element(by.id('user_email')).isPresent()).toBe(true);
captureScreen("onboarding-screen3");
browser.driver.sleep(3000);
});
it ('onboarding - screen 4', function() {
var buttonNotPresent = expect (element (by.xpath("//div[@id='root_content']//button[.='Preview on your website']")).isPresent()).toBe(true)
element(by.id("user_email")).sendKeys("auto" + Math.floor(Math.random()*11111) + "@vcita.com");
element (by.id("business_name")).sendKeys("automation man");
browser.driver.sleep(3000);
element (by.className("input.btn btn-account-action btn-xl")).click().then(function (buttonNotPresent) {
browser.driver.sleep(3000);
if (buttonNotPresent === false) {
element(by.id("user_email")).click();
browser.driver.sleep(1000);
element(by.xpath("//div[@class='step-content']/section/form/fieldset/div[4]/input")).click();
captureScreen("onboarding-screen4");
browser.driver.sleep(3000);
};
});
// else {
browser.driver.sleep(3000);
expect (element(by.xpath("//div[@id='root_content']//button[.='Preview on your website']")).isPresent()).toBe(true)
captureScreen("onboarding-screen4");
// };
});
it ('onboarding - screen 5', function() {
browser.driver.sleep(10000);
element (by.xpath("//div[@id='root_content']//button[.='Preview on your website']")).click();
browser.driver.sleep(3000);
expect (element(by.css('.uber-form-inner-content')).isPresent()).toBe(true);
captureScreen("onboarding-screen5");
browser.driver.sleep(3000);
});
it ('onboarding - screen 6', function() {
element(by.name("url")).sendKeys("www.mysite.com");
browser.driver.sleep(1000);
element(by.xpath("//div[@class='row']/div[2]/input")).click();
browser.driver.sleep(5000);
expect (element(by.xpath("//div[@id='livesite_active_engage']/div/div/div[1]")).isPresent()).toBe(true);
captureScreen("onboarding-screen6");
browser.driver.sleep(3000);
});
it ('onboarding - screen 7', function() {
browser.driver.sleep(3000);
element (by.xpath("//div[@class='btns']//button[.='Done']")).click();
browser.driver.sleep(5000);
expect (browser.driver.getCurrentUrl()).toContain('vcita.com/my/dashboard');
browser.driver.sleep(3000);
captureScreen("onboarding-screen7");
browser.driver.sleep(3000);
});
});
** Protractor 的错误**
<failure type="expect" message="Expected false to be true.">
Error: Failed expectation at [object Object].<anonymous> (c:\automation\tests\onboarding.js:59:132) at C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd\index.js:94:14 at [object Object].promise.ControlFlow.runInFrame_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1877:20) at [object Object].promise.ControlFlow.runEventLoop_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1755:8) at [object Object].<anonymous> (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:2056:12) at goog.async.run.processWorkQueue (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:125:21)
</failure>
<failure type="expect" message="Expected false to be true.">
Error: Failed expectation at [object Object].<anonymous> (c:\automation\tests\onboarding.js:77:111) at C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd\index.js:94:14 at [object Object].promise.ControlFlow.runInFrame_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1877:20) at [object Object].promise.ControlFlow.runEventLoop_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1755:8) at [object Object].<anonymous> (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:2056:12) at goog.async.run.processWorkQueue (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:125:21)
最佳答案
您可以尝试的第一件事是检查您的代码。 我注意到您缺少一些分号并通过此在线工具运行您的代码:
http://www.javascriptlint.com/online_lint.php
它表明您缺少一些分号和一些额外的分号。亲自尝试一下,看看是否有帮助。
关于javascript - 无法在 Jasmine JS 的测试用例中创建 "if statement",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29963365/