我正在尝试使用 Cypress 为该应用程序编写端到端测试:https://app.gotphoto.com/admin/auth/login
当我从浏览器访问上述网址时,会按预期显示登录表单。
当我通过 Cypress 访问上述网址时:
https://app.gotphoto.com/admin/auth/login
https://app.gotphoto.com/__/
并且登录表单未显示这是 Cypress 内部的两个屏幕截图:
我的问题是:为什么它在我的浏览器中的运行方式与在 Cypress / Cypress 浏览器中的运行方式有差异?
我使用的浏览器是 Chrome 89,无论是否使用 Cypress 运行。
我正在运行的整个测试是这样的:
describe('login screen', () => {
it('logs in', () => {
cy.visit('/admin/auth/login');
});
});
Run Code Online (Sandbox Code Playgroud)
使用 cypress.json:
{
"baseUrl": "https://app.gotphoto.com"
}
Run Code Online (Sandbox Code Playgroud)
我使用上述配置创建了一个存储库,因此很容易重现。
目标是以access token
编程方式从 MSAL 获取 Cypress e2e 测试。我们使用 V2.0 API。
根据这个我首先需要得到authorization code
:https : //docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow#request-an-authorization-code
获取access token
https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow#request-an-access-token
所以为了得到authorization code
我需要做这个请求
// GET
// Line breaks for legibility only
https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize?
client_id=6731de76-14a6-49ae-97bc-6eba6914391e
&response_type=code
&redirect_uri=http%3A%2F%2Flocalhost%2Fmyapp%2F
&response_mode=query
&scope=openid%20offline_access%20https%3A%2F%2Fgraph.microsoft.com%2Fmail.read
&state=12345
&code_challenge=YTFjNjI1OWYzMzA3MTI4ZDY2Njg5M2RkNmVjNDE5YmEyZGRhOGYyM2IzNjdmZWFhMTQ1ODg3NDcxY2Nl
&code_challenge_method=S256
Run Code Online (Sandbox Code Playgroud)
但这会返回,text/html
因此我需要手动登录才能获取代码。
有没有办法以编程方式获得authorization code
?
这是我的测试:
describe('settings page test', () =>{
it('tests navigation to settings page from login', () =>{
console.log(Cypress.config().baseUrl)
cy.visit(Cypress.config().baseurl)
Run Code Online (Sandbox Code Playgroud)
果然console.log(Cypress.config().baseUrl)
包含了我的 baseUrl 设置的值。
{
"baseUrl": "https://superniftyurltho.com",
"env": {
}
}
Run Code Online (Sandbox Code Playgroud)
这是错误
cy.visit() must be called with a url
or an options object containing a url as its 1st argumentLearn more
Run Code Online (Sandbox Code Playgroud)
有人知道会发生什么吗?
从 11.0.3 Angular/Core 版本开始,E2E 测试不适用于具有默认配置的项目。
我打开了一个问题https://github.com/angular/angular/issues/40221但它似乎不是回归(?)
https://github.com/BrunoBeraudPW/issue-angular-11.0.3
这是一个默认项目 Angular 11.0.3,我已将所有包更新到最新版本
我已经“手动”更新了所有软件包,因为“ng new”cmd 正在创建一个 Angular 10 应用程序,所以我想问题可能是由于其他软件包造成的。
但即使我刚刚更新了角度包,错误仍然存在
使用 fakeAsync 时:
Failed: zone-testing.js is needed for the async() test helper but could not be found.
Please make sure that your environment includes zone.js/dist/zone-testing.js
Run Code Online (Sandbox Code Playgroud)
selenium-webdriver 库中的几个错误(承诺)
C:\dev-phoenix\1-Photoweb-Forks\test\node_modules\selenium-webdriver\lib\promise.js:3067:27
this.pending_ = {task: task, q: this.subQ_};
task.promise.queue_ = this;
result = this.subQ_.execute_(task.execute);
~
this.subQ_.start();
} catch (ex) {
Run Code Online (Sandbox Code Playgroud)
Internal/modules/cjs/loader.js 中的几个错误
internal/modules/cjs/loader.js:955:30
jasmine-spec-reporter: unable to open 'internal/modules/cjs/loader.js'
Error: ENOENT: no such file …
Run Code Online (Sandbox Code Playgroud) 我正在尝试测试无效输入是否会警告用户。该输入的 html“类型”是“电子邮件”,因此浏览器实际上显示此气泡,而不是我们在网站上公开的元素。
据我所知,这个有问题的气泡是特定于浏览器的,并且据我所知它不会出现在 DOM 中。另外,我无法在其上使用“选择元素”光标工具,它会忽略该气泡,就好像它不存在一样。如果有帮助,它是由输入表单触发的浏览器特定事件。
有没有办法使用赛普拉斯断言来确认此警报是否存在?
使用 flutter 框架编写自动化测试(用户流程)最流行或最方便的框架是什么?任何帮助建议将不胜感激。
我有一个 Angular 应用程序,正在为其创建 Cypress E2E。
该应用程序的一个页面有一个表,其中第三列包含一个类名“link ng-star-inserted”的链接,我希望测试在找到特定行后单击该链接。
我实际上已经进行了执行此操作的测试 - 事实上该链接已被单击。
但它不是很优雅,它将 .click() 方法标记为错误(即使它确实有效)。
我正在寻找一种方法,让它不将 .click() 方法标记为错误。
这是我的代码...
cy.get(SELECTOR.dataTableBody).should('be.visible')
.contains('tr', 'Text I am looking for in the row I want')
.then($row => {
cy.log('found it');
cy.log('on row ' + $row.index());
//Yes this is kind of ugly. I tried it every other way I could think of and this is the only way it worked
let cellWithLink = $row.find('td:nth-child(3)');
cellWithLink.children().get(0).getElementsByClassName('link ng-star-inserted').item(0).click();
});
Run Code Online (Sandbox Code Playgroud)
这是 IDE 将 click() 标记为错误的镜头 - 尽管它确实有效。
非常感谢!
e2e ×7
cypress ×5
e2e-testing ×4
angular ×2
javascript ×2
automation ×1
base-url ×1
flutter ×1
jasmine ×1
protractor ×1
redirect ×1
testing ×1
typescript ×1
user-input ×1
zone.js ×1