Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript “如何解决”的错误;无效选择器";当使用;“如果声明”;在量角器JS中?_Javascript_Angularjs_Node.js_Jasmine_Protractor - Fatal编程技术网

Javascript “如何解决”的错误;无效选择器";当使用;“如果声明”;在量角器JS中?

Javascript “如何解决”的错误;无效选择器";当使用;“如果声明”;在量角器JS中?,javascript,angularjs,node.js,jasmine,protractor,Javascript,Angularjs,Node.js,Jasmine,Protractor,我想使用一个不可见的元素作为条件,如果它表示do X,否则表示do Y 我已经尝试使用该元素的类作为定位器和ng模型,并绑定他,但没有一个成功:/ 请您协助解决这个问题,非常感谢 这是我的问题测试用例: describe('LiveSite Portal - Existing client send new message', function() { var msgBox = expect(element(by.css(".final-container")).isPresent()

我想使用一个不可见的元素作为条件,如果它表示do X,否则表示do Y

我已经尝试使用该元素的类作为定位器和ng模型,并绑定他,但没有一个成功:/

请您协助解决这个问题,非常感谢

这是我的问题测试用例:

describe('LiveSite Portal - Existing client send new message', function() {

    var msgBox = expect(element(by.css(".final-container")).isPresent()).toBe(true);
    //var msgBox = element.all(by.css('#main_container > main > div > div > section > div.row.cz-content.inner-content.full-height > div > div.action.ng-scope > footer > form > div.row.form-control.textarea-holder.ng-isolate-scope.ng-hide > textarea'));
    var EC = protractor.ExpectedConditions;

    it('LiveSite - Home Page', function() {
       liveSiteHome();
    });

    if (msgBox === false) {

        it('LiveSite Portal - Existing client send new message - Message form', function() {
          browser.wait(EC.visibilityOf(element(by.xpath("//div[@class='actions-row']//a[.='Leave Your Details']"))), 10000);
          element(by.xpath("//div[@class='actions-row']//a[.='Leave Your Details']")).click();
          waitPageToLoad(); 
          expect(element(by.id("new_client_message_message")).isPresent()).toBe(true);
          element(by.css("div.row.mandatory > div.area")).click();
          element(by.id("new_client_message_title")).sendKeys("Automation message");
          element(by.id("new_client_message_message")).sendKeys("I am not logged-in client. Please call me.");
          element(by.id("new_client_message_email")).sendKeys("idanvcita@gmail.com");
        });

        it('LiveSite Portal - Existing client send new message - Welcome back for existing client', function() {
          element(by.id("new_client_message_first_name")).click();
          browser.wait(EC.visibilityOf(element(by.css("span.welcome-back"))), 10000);
          expect(element(by.css("span.welcome-back")).isPresent()).toBe(true);
        });

        it('LiveSite Portal - Existing client send new message - Messeage Sent', function() {
          element(by.name("commit")).click();
          waitPageToLoad(); 
          expect(element(by.css(".final-container")).isPresen()).toBe(true);t
        });

        it('LiveSite Portal - Existing client send new message - Back to home page', function() {
          element(by.css(".standard-button")).click();
          expect(element(by.model("email")).isPresent()).toBe(true);
          browser.driver.sleep(2000);
        });

    } else {

        it('LiveSite Portal - Send new message from the text box - Text Area', function() {
          // expect(element(msgBtn.isPresent()).toBe(true);
          element(by.xpath("//div[@id='main_container']/main/div/div/section/div[2]/div/div[2]/footer/form/div[2]/textarea")).sendKeys("Hello!\nHow are you?\nHave a good day! :)");
        });

        it('LiveSite Portal - Send new message from the text box - Message has been sent', function() {
          element(by.xpath("//div[@id='main_container']//button[.='Send']")).click();
          browser.wait(EC.visibilityOf(element(by.xpath("//div[@id='main_container']//h2[.='Quick conversation']"))), 10000);
          browser.driver.sleep(2000);
        });

    }

});
<a class="btn btn-void btn-with-font-round-icon engage-btn icon-lg brand-theme-before icon-env ng-binding" ng-click="goExternalUrl(contact_url)" ng-bind="truncate(livesite_actions_texts.contact, 22)" title="Leave Your Details">Leave Your Details</a>
这是元素=msgBox:

describe('LiveSite Portal - Existing client send new message', function() {

    var msgBox = expect(element(by.css(".final-container")).isPresent()).toBe(true);
    //var msgBox = element.all(by.css('#main_container > main > div > div > section > div.row.cz-content.inner-content.full-height > div > div.action.ng-scope > footer > form > div.row.form-control.textarea-holder.ng-isolate-scope.ng-hide > textarea'));
    var EC = protractor.ExpectedConditions;

    it('LiveSite - Home Page', function() {
       liveSiteHome();
    });

    if (msgBox === false) {

        it('LiveSite Portal - Existing client send new message - Message form', function() {
          browser.wait(EC.visibilityOf(element(by.xpath("//div[@class='actions-row']//a[.='Leave Your Details']"))), 10000);
          element(by.xpath("//div[@class='actions-row']//a[.='Leave Your Details']")).click();
          waitPageToLoad(); 
          expect(element(by.id("new_client_message_message")).isPresent()).toBe(true);
          element(by.css("div.row.mandatory > div.area")).click();
          element(by.id("new_client_message_title")).sendKeys("Automation message");
          element(by.id("new_client_message_message")).sendKeys("I am not logged-in client. Please call me.");
          element(by.id("new_client_message_email")).sendKeys("idanvcita@gmail.com");
        });

        it('LiveSite Portal - Existing client send new message - Welcome back for existing client', function() {
          element(by.id("new_client_message_first_name")).click();
          browser.wait(EC.visibilityOf(element(by.css("span.welcome-back"))), 10000);
          expect(element(by.css("span.welcome-back")).isPresent()).toBe(true);
        });

        it('LiveSite Portal - Existing client send new message - Messeage Sent', function() {
          element(by.name("commit")).click();
          waitPageToLoad(); 
          expect(element(by.css(".final-container")).isPresen()).toBe(true);t
        });

        it('LiveSite Portal - Existing client send new message - Back to home page', function() {
          element(by.css(".standard-button")).click();
          expect(element(by.model("email")).isPresent()).toBe(true);
          browser.driver.sleep(2000);
        });

    } else {

        it('LiveSite Portal - Send new message from the text box - Text Area', function() {
          // expect(element(msgBtn.isPresent()).toBe(true);
          element(by.xpath("//div[@id='main_container']/main/div/div/section/div[2]/div/div[2]/footer/form/div[2]/textarea")).sendKeys("Hello!\nHow are you?\nHave a good day! :)");
        });

        it('LiveSite Portal - Send new message from the text box - Message has been sent', function() {
          element(by.xpath("//div[@id='main_container']//button[.='Send']")).click();
          browser.wait(EC.visibilityOf(element(by.xpath("//div[@id='main_container']//h2[.='Quick conversation']"))), 10000);
          browser.driver.sleep(2000);
        });

    }

});
<a class="btn btn-void btn-with-font-round-icon engage-btn icon-lg brand-theme-before icon-env ng-binding" ng-click="goExternalUrl(contact_url)" ng-bind="truncate(livesite_actions_texts.contact, 22)" title="Leave Your Details">Leave Your Details</a>
留下您的详细信息
这是错误:

c:\automation\tests>protractor conf.js
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
LiveSite Portal - Existing client send new message
  encountered a declaration exception - fail


Failures:

  1) LiveSite Portal - Existing client send new message encountered a declaratio
n exception
   Message:
     TypeError: Cannot read property 'matchersClass' of null
   Stacktrace:
     TypeError: Cannot read property 'matchersClass' of null
    at promiseMatchers (C:\Users\idan\AppData\Roaming\npm\node_modules\protracto
r\node_modules\jasminewd\index.js:203:38)
    at global.expect (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\
node_modules\jasminewd\index.js:221:12)
    at [object Object].<anonymous> (c:\automation\tests\msg.js:3:61)
    at [object Object].jasmine.Env.describe_ (C:\Users\idan\AppData\Roaming\npm\
node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:913:21
)
    at [object Object].jasmine.Env.describe (C:\Users\idan\AppData\Roaming\npm\n
ode_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:898:15)

    at describe (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_
modules\minijasminenode\lib\jasmine-1.3.1.js:658:27)
    at Object.<anonymous> (c:\automation\tests\msg.js:1:63)

Finished in 0.125 seconds
1 test, 1 assertion, 1 failure

[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1

c:\automation\tests>
c:\automation\tests>量角器conf.js
使用位于的selenium服务器http://localhost:4444/wd/hub
[launcher]正在运行1个WebDriver实例
LiveSite门户-现有客户端发送新消息
遇到声明异常-失败
失败:
1) LiveSite门户-现有客户端发送新消息时遇到声明
n例外
信息:
TypeError:无法读取null的属性“MatcherClass”
堆栈跟踪:
TypeError:无法读取null的属性“MatcherClass”
在promiseMatchers(C:\Users\idan\AppData\Roaming\npm\node\U modules\Gragrato
r\node\u modules\jasminewd\index.js:203:38)
在global.expect(C:\Users\idan\AppData\Roaming\npm\node\u modules\dragrator\
node_modules\jasminewd\index.js:221:12)
在[对象]。(c:\automation\tests\msg.js:3:61)
在[object object].jasmine.Env.description(C:\Users\idan\AppData\Roaming\npm\
node\u modules\dragrator\node\u modules\minijasminenode\lib\jasmine-1.3.1.js:913:21
)
在[object object].jasmine.Env.description(C:\Users\idan\AppData\Roaming\npm\n
ode_modules\dragrator\node_modules\minijasminenode\lib\jasmine-1.3.1.js:898:15)
在描述(C:\Users\idan\AppData\Roaming\npm\node\u modules\dragrator\node_
modules\minijasminenode\lib\jasmine-1.3.1.js:658:27)
反对。(c:\automation\tests\msg.js:1:63)
以0.125秒完成
1次测试,1次断言,1次失败
[launcher]0个WebDriver实例仍在运行
[launcher]chrome#1测试失败1次
[启动器]总体:1个失败的规范
[launcher]进程已退出,错误代码为1
c:\automation\tests>

既然您说这个问题发生在
if
语句中,我假设这个问题发生在访问msgBox时。因此,请尝试使用
element.all(by.css('.ng隔离范围ng原始范围ng有效))
而不是
元素(by.css(..)

或者尝试像这样访问元素

var msgBox = element.all(by.css('[ng-click="goExternalUrl(contact_url)"]'));
这一行:

var msgBox = expect(element(by.css(".final-container")).isPresent()).toBe(true);
在任何
it
声明之外发生。但是所有的量角器(真正的webdriver)神奇的承诺解析都发生在每个
上创建的ControlFlow中。所以,我认为这并不像你期望的那样有效

第二:

if (msgBox === false) {
正在检查
expect
的结果,这是一个承诺(如果有)。我很有信心它不是布尔型的。在任何情况下,您都试图更改它将执行的
函数,但这需要执行一些量角器代码,而这实际上是行不通的


看起来您想要检查页面,确定它是哪种“风格”,然后针对不同的风格运行不同的测试(带或不带文本框)。这似乎是一个合理的要求,但我不认为量角器有一个很好的方式来表达这一点。(我认为许多人会建议您设置测试,以便您的测试知道预期的情况,并且它会导致两组代码都执行。这种有条件的方法意味着测试“通过”可能不会执行您的所有代码。)

您需要隔离实际错误发生的代码。您的测试用例中使用了多个css选择器,因此不可能立即获得此错误的根本问题
InvalidSelectorError
。尝试减少步骤并逐个运行它们。您还可以使用browser.pause()暂停步骤,这样您就可以确定哪些步骤实际导致了此错误。谢谢malik,但我知道此问题发生在哪里,并且与IF语句有关。我已经做了一些研究来发现这一点,但我不知道原因是什么/再次感谢你,伙计,但还是不行。我已经更新了错误、代码和css。请您指教。谢谢@malik_Curtinhm。您确定这里有当前css选择器,
(“.ng隔离范围ng原始有效)”
?你能发布html代码吗?你试图通过msgBox访问的元素的名称是什么?好的,试着像这样使用
element.all(by.css(“#main_container>main>div>div>section>div.row.cz-content.inner-content.full-height>div>div>div.action.ng-scope>footer>form>div.row.form-control.textarea-holder.ng-isolate-scope.ng-hide>textarea”)
或者尝试我在编辑的答案中指定的方法