如何使用量角器处理基本身份验证?

2023-02-15前端开发问题
1

本文介绍了如何使用量角器处理基本身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试量角器在非角度应用程序中编写一些测试.我必须通过谷歌浏览器中的基本身份验证登录页面,但我不知道如何.

I'm trying protractor to write a few tests in a non angular application. I have to login in a page trough basic authentication in google chrome, but i have no idea how.

我已经尝试过 baseUrl: 'https://username:password@url'capabilities: {浏览器名称":铬",铬选项":{参数:['--login-user=foo', '--login-password=bar']}}

但如果这些对我有用,则没有.有谁知道该怎么做?我在这方面遇到了一些困难.

But none if these worked for me. Anyone knows how to do it? I'm having some hard time on it.

推荐答案

简短的回答是在 chrome 上没有简单的方法,因为它们不支持修改请求标头 - 请参阅 https://code.google.com/p/selenium/issues/detail?id=141 (标题表示响应标题,但如果您阅读它,它适用于所有标题).

The short answer is there is no easy way of doing it on chrome because they do not support modifying request headers -- see https://code.google.com/p/selenium/issues/detail?id=141 (title says response headers, but if you read it, it's for all headers).

话虽如此,有办法做到这一点,尽管很困难.

That being said, there are ways to do it, albeit difficult.

1) 找到一个允许您修改标题的 chrome 扩展/插件.一个简单的搜索就可以找到很多:https://chrome.google.com/webstore/search/modify%20header.您需要将插件添加到 webdriver:请参阅 量角器测试下是否可以给chromedriver添加插件?.

1) Find a chrome extension/plugin that allows you to modify header. A simple search bring up many of them: https://chrome.google.com/webstore/search/modify%20header. You'll need to add the plugin to webdriver: see Is it possible to add a plugin to chromedriver under a protractor test?.

2) 你可以使用 browsermob-proxy (https://github.com/lightbody/browsermob-代理);这样,您可以通过代理路由您的流量,这将为您添加标头.来自文档:

2) You can use browsermob-proxy (https://github.com/lightbody/browsermob-proxy); this way you route your traffic through the proxy, which would add the headers for you. From the docs:

POST /proxy/[port]/auth/basic/[domain] - Sets automatic basic authentication for the specified domain
Payload data should be json encoded username and password name/value pairs (ex: {"username": "myUsername", "password": "myPassword"}

有一个节点项目可以帮助你,https://github.com/zzo/browsermob-节点,但您仍然需要自己设置代理服务器.

There's a node project that may help you, https://github.com/zzo/browsermob-node, but you would still need to set up your proxy server yourself.

chrome 的两种方法都很复杂,但都能得到你想要的.(或者你可以坚持使用 Firefox 并按照罗伯特的回答)

Both ways for chrome are complex, but would get you what you want. (or you can stick with firefox and follow Robert's answer)

这篇关于如何使用量角器处理基本身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

js删除数组中指定元素的5种方法
在JavaScript中,我们有多种方法可以删除数组中的指定元素。以下给出了5种常见的方法并提供了相应的代码示例: 1.使用splice()方法: let array = [0, 1, 2, 3, 4, 5];let index = array.indexOf(2);if (index -1) { array.splice(index, 1);}// array = [0,...
2024-11-22 前端开发问题
182

JavaScript小数运算出现多位的解决办法
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...
2024-10-18 前端开发问题
301

JavaScript(js)文件字符串中丢失"\"斜线的解决方法
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转...
2024-10-17 前端开发问题
437

layui中table列表 增加属性 edit="date",不生效怎么办?
如果你想在 layui 的 table 列表中增加 edit=date 属性但不生效,可能是以下问题导致的: 1. 缺少日期组件的初始化 如果想在表格中使用日期组件,需要在页面中引入 layui 的日期组件,并初始化: script type="text/javascript" src="/layui/layui.js"/scrip...
2024-06-11 前端开发问题
455

Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)...
2024-04-20 前端开发问题
5

CoffeeScript 总是以匿名函数返回
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)...
2024-04-20 前端开发问题
13