javascript - How to solve error about "invalid selector" when using "if statement" in Protractor JS? -


i want use invisible element condition if present x , else y.

i've tried use class of element locator , ng-model , binding of him none of them worked :/

please assistance solve issue, lot.

this problematic test case:

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 details']"))), 10000);           element(by.xpath("//div[@class='actions-row']//a[.='leave 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 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 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 - 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 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 you?\nhave day! :)");         });          it('livesite portal - send new message 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);         });      }  }); 

this element = msgbox:

<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 details">leave details</a> 

this error:

c:\automation\tests>protractor conf.js using selenium server @ http://localhost:4444/wd/hub [launcher] running 1 instances of webdriver livesite portal - existing client send new message   encountered declaration exception - fail   failures:    1) livesite portal - existing client send new message encountered declaratio n exception    message:      typeerror: cannot read property 'matchersclass' of null    stacktrace:      typeerror: cannot read property 'matchersclass' of null     @ promisematchers (c:\users\idan\appdata\roaming\npm\node_modules\protracto r\node_modules\jasminewd\index.js:203:38)     @ global.expect (c:\users\idan\appdata\roaming\npm\node_modules\protractor\ node_modules\jasminewd\index.js:221:12)     @ [object object].<anonymous> (c:\automation\tests\msg.js:3:61)     @ [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 )     @ [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)      @ describe (c:\users\idan\appdata\roaming\npm\node_modules\protractor\node_ modules\minijasminenode\lib\jasmine-1.3.1.js:658:27)     @ 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 error code 1  c:\automation\tests> 

this line:

var msgbox = expect(element(by.css(".final-container")).ispresent()).tobe(true); 

happens outside it declarations. of protractor (really webdriver) magic promise resolution happens in controlflow created on each it. so, don't think works expect.

second:

if (msgbox === false) { 

is checking result of expect, promise (if anything). i'm pretty confident not boolean. in event, you're trying change it functions execute, requires having executed protractor code, isn't going work.

it looks want inspect page, decide "flavor" is, , run different tests different flavors (with or without text box). seems reasonable thing want, don't think protractor has way of expressing this. (i think many folks suggest set things test knows case expect , causes both sets of code execute. conditional approach means test "passing" may not have exercised of code.)


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -