简体   繁体   English

routerLink在angular2中使用保护器在e2e测试中不起作用

[英]routerLink doesn't work in e2e test using protrator in angular2

I have this angular2 routerLink which allows user to navigate to editComponent by passing userId as parameter. 我有这个angular2 routerLink,它允许用户通过将userId作为参数来导航到editComponent。

<a [routerLink]="['/edit',user._id]" (click)="returnUser(user._id)" id="redirect" class="btn" name="user-{{i}}">
    <i class="fa fa-eye fa-fw"></i>
</a>

I want to test this using protractor, but When I am running my e2e test.after executing click event this link is not redirecting to editComponent. 我想使用量角器对此进行测试,但是当我运行e2e test.exe时,在执行click事件之后,此链接不会重定向到editComponent。

Following is my test: 以下是我的测试:

it('should redirect to edit', () => {
element(by.id("redirect")).evaluate("user._id").then(
  function (userId) {
    browser.get('/edit/' + userId);
    browser.waitForAngular();
  }, function (err) {
    console.log(err);
  })
});

Also I am getting below error: 我也得到下面的错误:

asynchronous script timeout: result was not received in 30 seconds 异步脚本超时:30秒内未收到结果

what am I doing wrong here? 我在这里做错了什么?

any inputs? 有输入吗?

thanks 谢谢

You are not clicking on the link actually. 您实际上没有单击链接。

it('should redirect to edit', () => {
      element(by.id("redirect")).evaluate("user._id").then(function (userId) {
       element(by.id("redirect")).click(); //click the edit link
       browser.waitForAngular();  //wait for page load
       expect(browser.getCurrentUrl()).toContain('/edit/' + userId); //if you are using jasmine framework do an ssertion with the current url
  }, function (err) {
      console.log(err);
  })
});
  1. can you try 你能试一下吗

element(by.id("redirect")).click().then( element(by.id(“ redirect”))。click()。then(

  1. also, check if u need to click on this 另外,检查您是否需要单击此

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM