首页 > 其他分享 >docker运行的playwright记录

docker运行的playwright记录

时间:2023-03-16 16:45:27浏览次数:45  
标签:src playwright 记录 -- py File docker line

下载官方镜像:https://playwright.dev/python/docs/docker

使用命令;

docker pull mcr.microsoft.com/playwright/python:v1.31.0-focal

然后运行:

docker run -it --rm --name=test_play -v /Users/kaka/miniconda3/envs/playwright_tianmao/project/src:/src mcr.microsoft.com/playwright/python:v1.31.0-focal /bin/bash

因为把本地的那个工作目录就挂载到容器内了么,所以本地修改代码,容器内的也可以运行:

 1 root@5958fc57326e:/# python /src/tian_mao.py 
 2 Traceback (most recent call last):
 3   File "/src/tian_mao.py", line 100, in <module>
 4     run (playwright)
 5   File "/src/tian_mao.py", line 22, in run
 6     context = playwright.firefox.launch_persistent_context (
 7   File "/usr/local/lib/python3.8/dist-packages/playwright/sync_api/_generated.py", line 14691, in launch_persistent_context
 8     self._sync(
 9   File "/usr/local/lib/python3.8/dist-packages/playwright/_impl/_sync_base.py", line 104, in _sync
10     return task.result()
11   File "/usr/local/lib/python3.8/dist-packages/playwright/_impl/_browser_type.py", line 155, in launch_persistent_context
12     from_channel(await self._channel.send("launchPersistentContext", params)),
13   File "/usr/local/lib/python3.8/dist-packages/playwright/_impl/_connection.py", line 44, in send
14     return await self._connection.wrap_api_call(
15   File "/usr/local/lib/python3.8/dist-packages/playwright/_impl/_connection.py", line 419, in wrap_api_call
16     return await cb()
17   File "/usr/local/lib/python3.8/dist-packages/playwright/_impl/_connection.py", line 79, in inner_send
18     result = next(iter(done)).result()
19 playwright._impl._api_types.Error: 
20 ╔════════════════════════════════════════════════════════════════════════════════════════════════╗
21 ║ Looks like you launched a headed browser without having a XServer running.                     ║
22 ║ Set either 'headless: true' or use 'xvfb-run <your-playwright-app>' before running Playwright. ║
23 ║                                                                                                ║
24 ║ <3 Playwright Team                                                                             ║
25 ╚════════════════════════════════════════════════════════════════════════════════════════════════╝
26 =========================== logs ===========================
27 <launching> /ms-playwright/firefox-1378/firefox/firefox -no-remote -wait-for-browser -foreground -profile /Users/kaka/firefox2 -juggler-pipe --disable-blink-features=AutomationControlled --disable-extensions --disable-popup-blocking --ignore-certificate-errors --disable-plugins-discovery --no-first-run --no-service-autorun --no-default-browser-check --disable-dev-shm-usage about:blank
28 <launched> pid=232
29 [pid=232][err] Error: no DISPLAY environment variable specified
30 [pid=232] <process did exit: exitCode=1, signal=null>
31 [pid=232] starting temporary directories cleanup
32 ============================================================
33 root@5958fc57326e:/# 
View Code

这个也报错,但是和之前的我的运行chrome的相比,这个起码还可以运行:

 

 

 所以我在这里面,我就用的修改成了firefox,但是因为我的设置为headless=False所以,我们先测试一下,这个如果改为TRUE的话能不能跑:

 1 root@5958fc57326e:/# python /src/tian_mao.py
 2 快速进入->Exception:Timeout 2000ms exceeded.
 3 =========================== logs ===========================
 4 waiting for get_by_role("button", name="快速进入")
 5 ============================================================
 6 未获取到登录的淘宝昵称->Exception:Timeout 5000ms exceeded.
 7 =========================== logs ===========================
 8 waiting for locator(".site-nav-bd > ul.site-nav-bd-l > li#J_SiteNavLogin > div.site-nav-menu-hd > div.site-nav-user > a.site-nav-login-info-nick")
 9 ============================================================
10 root@5958fc57326e:/# 
View Code

虽然还是有问题,但是这个问题是运行的程序的问题,起码证明这个官方的这个可以用,我在试一下这个如果改为False之后,按照上文的报错的指引,如此运行:

 1 root@5958fc57326e:/# xvfb-run python src/tian_mao.py 
 2 获取拖动按钮位置并拖动->Exception:Timeout 2000ms exceeded.
 3 =========================== logs ===========================
 4 waiting for frame_locator("#baxia-dialog-content").locator("#nc_1_n1z")
 5 ============================================================
 6 快速进入->Exception:Timeout 2000ms exceeded.
 7 =========================== logs ===========================
 8 waiting for get_by_role("button", name="快速进入")
 9 ============================================================
10 获取到登录的淘宝昵称是:tb4210828_2012
11 root@5958fc57326e:/# 
View Code

可以看到,获取到了我的淘宝昵称。

 


标签:src,playwright,记录,--,py,File,docker,line
From: https://www.cnblogs.com/kaka0318/p/17223155.html

相关文章

  • docker-compose编排环境报错
    docker-composeup拉取环境出现如下报错,看到Timeout以为是网络不好,其实不然,用vim/etc/docker/daemon.json添加新的镜像地址,再次docker-compose的时候就顺利进行了。......
  • 使用Docker快速部署一个Net项目
    前言Docker可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化。优点Web应用的自动化打包和发......
  • docker mysql8.0 启动,挂数据卷,定时备份,恢复~
    安装mysql从mysql社区版的官方源去拉取镜像:mysql/mysql-server-DockerImage|DockerHubdockerrun--name=mysql1-dmysql/mysql-server:latest 镜像起来之后,mys......
  • 笔记本水冷改造记录
    1、前言最近用的电脑风扇总是起飞,打开idea都会像喷气飞机一样,使用时还经常卡顿。查看了一下闲鱼,当年8000多买的笔记本,3年半二手只能出大概3500。笔记本跟了一段时间了,还......
  • WINDOWS 10更改WSL DOCKER镜像目录
    转载申明:此文档转载自:https://www.cnblogs.com/friend/p/16722869.html 现在Docker Desktop默认使用WSL2来运行,而不是以前的Hyper-V。WSLWSL:适用于Linux的Window......
  • centos7 安装docker 错误解决
    yum-config-manager--add-repohttp://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repoyum-yinstalldocker-ce安装报错:错误:软件包:2:container-selinux-2......
  • docker 部署 xxl-job 详细步骤
    1、先安装mysqldockerpullmysql2、运行mysql容器(端口3306容器名称mysql密码123456)dockerrun-d--namemysql-eMYSQL_ROOT_PASSWORD=123456-p3306:3......
  • parquet文件的操作记录
    importpyarrow.parquetaspqparquet_file="36152ae88916cad7eecc74cafa5c6413.parquet"schema=pq.ParquetFile(parquet_file).schema可以查看schema,我们可以看到......
  • docker login "Password change required but no TTY available."
    docker login"PasswordchangerequiredbutnoTTYavailable."报错现象 原因原因为账号密码过期或登录方式不支持解决方式一sudodockerlogin-uuser-px......
  • Docker搭建MySQL负载均衡
    Docker拉取MySQL集群https://www.cnblogs.com/zuoyoua/p/17212377.html前言:为什么要搭建负载均衡#在搭好集群的情况下,负载均衡可以消除服务器之间的负载不平衡,可以优......