在browser.get之前设置cookie [英] Setting cookies before browser.get

查看:221
本文介绍了在browser.get之前设置cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的(PHP)应用程序需要设置某些cookie才能加载Angular.js客户端应用程序.如果未设置Cookie,则会引发异常并显示错误页面.

Our (PHP) application requires certain cookies to be set in order to load an Angular.js client app. If the cookies are not set an exception is thrown and error page is shown.

这意味着要运行E2E测试,我们需要设置cookie,但是以下操作失败,因为量角器试图在browser.get调用之后立即找到Angular(它不存在,因为引发了异常).

This means in order to run E2E tests we need to set the cookies, but the following fails because Protractor is trying to find Angular right after the browser.get call (it's not there because the exception was thrown).

browser.get('http://' + domain + '/');
browser.manage().addCookie('foo', 'boo', '/', domain);

设置cookie后,我尝试致电browser.get:

I tried to call browser.get after setting the cookies:

browser.manage().addCookie('foo', 'boo', '/', domain);
browser.get('http://' + domain + '/');

但这会产生以下错误:

无法在文档"上设置"Cookie"属性: 在数据:" URL中被禁用.

Failed to set the 'cookie' property on 'Document': Cookies are disabled inside 'data:' URLs.

有没有办法处理这种情况?也许是要告诉量角器在进行第一次browser.get调用时不要检查Angular,或者在调用获取URL之前以某种方式为我们的域设置cookie?

Is there a way how to handle this situation? Perhaps to tell Protractor not to check for Angular when doing the first browser.get call or somehow set cookies for our domain before calling getting the URL?

推荐答案

我在请注意browser.driver.get而不是browser.get.这将阻止量角器寻找Angular应用程序,并且可以设置cookie.然后,在it语句中使用另一个browser.get.

Note the browser.driver.get instead of browser.get. This will prevent Protractor looking for the Angular app and cookies can be set. I then use another browser.get inside of it statement.

这篇关于在browser.get之前设置cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆