2

I'm fairly new to protractor and writing test cases.I tried to run this test case as shown below which is to open a page and click on "Home" which then takes back to another page added as expectation. The content of conf.js is:

 exports.config = { framework: 'jasmine', seleniumAddress: 'http://localhost:4444/wd/hub', specs: [ '*navigating_spec.js' ], useAllAngular2AppRoots: true }; 

similarly the test case:

// spec.js describe('Navigatiion', function() { it('GNavigate to search page and back to dashboard', function() { browser.get('http://appspot.com/#/pages/search'); element( by.ccs('/pages/dashboard')).click(); var EC = protractor.ExpectedConditions; // Waits for the URL to contain 'foo'. browser.wait(EC.urlContains('http://appspot.com/#/pages/dashboard'), 1000000); }); }); 

The click part is not working, and I do not know which locator to use for this "Home" button The text in application under text is shown below in image: HTML text When I run this test case, it does not do the click part and ends with error as process exited with error 1. Suggestions are appreciated is appreciated.

Just something to add, The conf.js file is working with another test, so configuration file should not be an issue. I just dont know which locator to use base don html code

2
  • Just something to add, The conf.js file is working with another test, so configuration file should not be an issue. I just dont know which locator to use base don html code. Commented Jan 17, 2017 at 11:59
  • If you want to add something, you can edit. Commented Jan 17, 2017 at 12:20

1 Answer 1

3

Your locator element( by.ccs('/pages/dashboard')) is not valid CSS. You have a few options that I can see:

1) Select item by text:

element(by.cssContainingText('a', 'Home')).click()

2) Select item using attributes:

element(by.css('a[href="#/pages/dashboard"]')).click();

Also depending on the error you are getting, you can use an Expected Condition on that link too.

browser.wait(EC.elementToBeClickable(...)) (or present, or visible etc.)

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot Gunderson; it helped. Really appreciate it, Keep doing the good work.
@Syed Glad it helped! If it solved your problem, please consider accepting my answer to help others.
I have one more question, there is another input field which I do not understand how to use locator for. In the code it is '<input _ngcontent-tvt-19="" class="form-control ng-pristine ng-valid ng-touched" placeholder="You can search keywords" type="text">' . I want to fill this field with a value using the code in spec file as 'element(by.binding('You can search keywords ')).sendKeys("04");' but it does not work. I have also tried with cssContainingText and it did not work. Do you have any idea about the locator or how can I change the code line.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.