小编in4*_*3sh的帖子

是否可以在 Playwright 中创建自定义命令?

我正在寻找一种在 Playwright 中编写自定义命令的方法,就像在 Cypress 中所做的那样。Playwright Issues 有一页与之相关,但我从未见过任何代码示例。

我正在研究一个测试用例,试图提高代码的可重用性。这是代码:

import { test, chromium } from '@playwright/test';

config();

let context;
let page;

test.beforeEach(async () => {
  context = await chromium.launchPersistentContext(
    'C:\\Users\\User\\AppData\\Local\\Microsoft\\Edge\\User Data\\Default',
    {
      headless: false,
      executablePath: 'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe',
    }
  );

  page = await context.newPage();
  await page.goto('http://localhost:3000/');
});

test.afterEach(async () => {
  await page.close();
  await context.close();
});

test('Sample test', async () => {
  await page.click('text=Open popup');
  await page.click('_react=Button >> nth=0');
  await page.click('text=Close popup');
});
Run Code Online (Sandbox Code Playgroud)

我正在尝试创建一个函数来调用钩子 test.beforeEach() 和 test.afterEach() …

javascript testing playwright

7
推荐指数
1
解决办法
5991
查看次数

反应 npm 错误“npm ERR!代码 ELIFECYCLE” 当我执行 npm start 时

我正在开发一个 React 应用程序。当我使用命令时npm start,它给出了一个错误。我尝试删除 node_modules 和 package-lock.json,然后执行npm install. 我也试过做npm cache clean --force。我做的最后一件事是npm audit fix。我仍然有同样的问题。这是我的错误:

> majestic-bay@0.1.0 start /home/serg/webdev/majestic-bay
> react-scripts start

/home/serg/webdev/majestic-bay/node_modules/terser-webpack-plugin/node_modules/p-limit/index.js:30
                } catch {}
                        ^

SyntaxError: Unexpected token {
    at new Script (vm.js:51:7)
    at createScript (vm.js:136:10)
    at Object.runInThisContext (vm.js:197:10)
    at Module._compile (internal/modules/cjs/loader.js:618:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Module.require (internal/modules/cjs/loader.js:598:17)
    at require (internal/modules/cjs/helpers.js:11:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! majestic-bay@0.1.0 …
Run Code Online (Sandbox Code Playgroud)

javascript node.js npm reactjs

5
推荐指数
1
解决办法
2895
查看次数

使用 Apple ID 登录返回“invalid_request 无效的 Web 重定向 url。”

我正在尝试将登录与 Apple id 集成到我的 NextJS 项目中。对于身份验证,我选择了 package next-auth。因此,在next-auth的文档中,它需要以下数据:

import Providers from `next-auth/providers`
...
providers: [
Providers.Apple({
    clientId: process.env.APPLE_ID,
    clientSecret: { 
    teamId: process.env.APPLE_TEAM_ID,
    privateKey: process.env.APPLE_PRIVATE_KEY,
    keyId: process.env.APPLE_KEY_ID,
    }
})
]
...
Run Code Online (Sandbox Code Playgroud)

我使用此链接为我的帐户创建凭据。

对于clientId我使用的 ServicesID 标识符,现在它看起来像com.test.client。对于teamId我使用的字符串,位于右上角。对于privateKey我使用在我的帐户中生成的密钥并下载它。我删除了显示 -----BEGIN PRIVATE KEY----- 和 -----END PRIVATE KEY----- 的部分,并确保密钥保留在一行中。keyId我从我的帐户中得到的。

我将所有值存储在 .env 变量中。我仔细检查了一下,问题不在于 .env 变量。

当我尝试使用 Apple id 登录时,它会将我重定向到以下错误页面:

当我尝试登录时重定向到的页面

以下是我的 ServicesID 页面中的 URL 列表:

域和子域:

测试网

测试网

返回网址

https://test.com

我猜问题出在我的重定向网址上,但我不明白它是什么。

reactjs next.js apple-sign-in next-auth

5
推荐指数
0
解决办法
2521
查看次数

Get url params in API route handler in Next.js

I have a client component GetUserInfoButton. In that component, I send a GET request on url http://localhost:3000/test/users/[id] where [id] is a MongoDb-like alphanumeric sequence.

Inside app/api/users/[id]/route.ts, I want to receive that request and work with that [id]. Here's my GetUserInfoButton component:

'use client';

export default function GetUserInfoButton({ id }: { id: string }) {
    const contentType = "application/json";
    const handleClick = async (id: string) => {
        try {
            const res = await fetch(`/api/users/${id}`, {
                method: "GET",
                headers: …
Run Code Online (Sandbox Code Playgroud)

javascript next.js

5
推荐指数
1
解决办法
4434
查看次数

Nginx 无法访问可用站点中的根目录

我在 Digital Ocean Droplet (Ubuntu) 上设置了基本的 nginx。我只有一个 root 用户。在我的 nginx 配置文件中,我有

server {
    listen 80;

    server_name site.com;

    root /var/www/html/site;
}
Run Code Online (Sandbox Code Playgroud)

我尝试将其更改为

root /root/site
Run Code Online (Sandbox Code Playgroud)

但它给了我 403 Forbidden 错误。当我将其更改为 nginx 默认目录时

/var/www/html/site;
Run Code Online (Sandbox Code Playgroud)

一切正常。

为什么它给我这个错误?我知道只有root用户才能访问根目录,但为什么浏览器不能只从那里读取文件?是否可以创建另一个文件夹,而不是像“/var/www/html/23rdsquad;”那样 我的服务器上的某个位置(不是 /root 或 /var/www)并使用它?

linux nginx server

2
推荐指数
1
解决办法
1万
查看次数

next-auth 中 useSession、getSession 和 getServerSession 之间的区别?

我正在查看这个问题的答案,但我仍然不清楚有什么区别。而现在,他们又增加了一种新的方法getServerSession()。请澄清有什么区别以及何时使用什么

next.js next-auth

1
推荐指数
1
解决办法
1672
查看次数