javascript - 无法在 Jasmine JS 的测试用例中创建 "if statement"

标签 javascript node.js selenium-webdriver jasmine protractor

我无法通过 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].&lt;anonymous&gt; (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].&lt;anonymous&gt; (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].&lt;anonymous&gt; (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].&lt;anonymous&gt; (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/

相关文章:

java - 当有多个发送键时,Selenium sendkeys 清除值

javascript - 网格使用太多绘制调用

javascript - Angular : variable which is returned by a function in controller is "undefined"

javascript - 从返回的查询数组中获取对象的值 (Parse.com + Node.js)

java - 无法在 selenium webdriver 中选择 Iframe

python - 放大后无法获取任何元素的屏幕截图

javascript - Nodejs Google Drive API 可共享链接

javascript - Node.js:在调用的脚本中访问数据库

node.js - 有没有办法使用 node.js 覆盖 yaml 文件中的基本设置?

node.js - 下载图像并使用 multipart/form-data 将其发送到 API