0

My below test always fails as protractor cannot find the element by tag name.

it('should show test component',async () => {
    await browser.get('/trade')
    element(by.tagName(('test-component'))).isPresent()
    .then(value=>{
      console.log(value ,'first')
      expect(value).toBeTruthy()
    });

})

I have tried the same code in other test spec but it worked. What am I doing wrong here?

User3250
  • 2,961
  • 5
  • 29
  • 61

1 Answers1

1

Try using the below code snippet.

it('should show test component', async () => {

await browser.get('provide complete url');

var EC = browser.ExpectedConditions;
await browser.wait(EC.visibilityOf(element(by.tagName('test-component'))),10000);

element(by.tagName('test-component')).getText().then(async (value)=>{
console.log(value ,'first')
expect(await value).toBeTruthy();

});
Zohair
  • 268
  • 2
  • 7
  • It works, thanks a bunch! Although I would like to know that for each test I need to write so much of code? – User3250 Aug 14 '19 at 11:13
  • Well, It depends on the structure of your test suite. If you have used proper hooks in your framework than you can handle many repetitive tasks in your hooks and do the test specific tasks in your tests. Otherwise, you need to go with the repetition of your code which is not a good practice. – Zohair Aug 14 '19 at 11:48