在无头服务器上进行端到端测试

人气:491 发布:2022-10-16 标签: selenium-webdriver protractor headless end-to-end digital-ocean

问题描述

我正在尝试在数字海洋上运行 Ubuntu 服务器 12.04.3 的 droplet 上设置一个端到端测试环境.

I am trying to set up an environment for end-to-end testing on a droplet running Ubuntu server 12.04.3 on digital ocean.

我最终想要实现的是让我的 jenkins(安装在一个 droplet 上)能够运行我的端到端测试.现在,服务器当然是 headless 并且端到端测试需要通过浏览器运行(我正在使用量角器和带有 chromedriver 的 selenium 独立服务器).

What I am trying to achieve in the end is for my jenkins (installed on the one droplet) to be able to run my end-to-end tests. Now, the server is ofcourse headless and the end-to-end tests need to run through a browser (I am using protractor with the selenium standalone server with chromedriver).

我的问题是:如何在该机器上生成浏览器?我已经安装了 xorg,如果我在服务器上执行 startx,注销并 ssh -X 到它,我可以手动运行 end-端到端测试(我的本地机器上会弹出一个浏览器).但是我可以在没有 ssh -X 的情况下让它工作,因为 jenkins 位于要运行测试的同一个 droplet 上.好吧,我没有生成浏览器.

My question is: how do I spawn a browser on that machine? I have installed xorg and if I do startx on the server, log out and ssh -X to it, I can manually run the end-to-end tests (a browser pops up on my local machine). But I can get it to work without ssh -X to it, and since jenkins is on the same droplet where the tests are to be run. Well I dont get a browser to spawn.

注意:我知道我可能在这里遗漏了一些非常琐碎的东西,因为我不完全了解配置和 xorg.

NOTE: I know I might be missing something really trivial here since I don't fully understand the configuration nor the xorg.

非常感谢任何提示或完整答案,这让我白发苍苍.

Any hints or a complete answer is very much appreciated, this is giving me gray hair.

经过一番挖掘,我认为我弄错了 xorg 的东西,我猜 X 的目的是能够在远程机器(即我的本地机器)上生成一个窗口.而我所追求的更像是像 Xvfb 这样的虚拟帧缓冲区......

After a little digging I think i got the xorg stuff a bit wrong, i am guessing the purpose of X is to be able to spawn a window on a remote machine ( ie my local machine). And what i am after is more along the lines of a virtual frame buffer such as Xvfb...

推荐答案

有 PhantomJS 但有 Protractor 是 越野车和死胡同.

There is PhantomJS but with Protractor is buggy and a dead-end.

您仍然可以使用 Chrome &通过 docker-selenium 或者如果你不喜欢 Docker 你可以自己用 ubuntu-headless 示例.两种解决方案都提供 Chrome 和Firefox 使用 Xvfb 即使没有真正的 DISPLAY.

You can still use Chrome & Firefox headless through docker-selenium or, if you don't like Docker you can do it yourself with ubuntu-headless sample. Both solutions provide Chrome & Firefox by using Xvfb even though there is no real DISPLAY.

UPDATE 2 似乎可以在 OSX 中运行 Xvfb:http://xquartz.macosforge.org/landing/

UPDATE 2 Seems to be possible to run Xvfb in OSX: http://xquartz.macosforge.org/landing/

更新 1 Mac OSX selenium 无头解决方案:

UPDATE 1 Mac OSX selenium headless solution:

所以可以在 mac 上测试 selenium 无头.不是真的无头,而是作为另一个用户,所以它不会干扰您当前的用户显示.为此,您需要 kickstart:http://support.apple.com/en-us/HT201710开始使用 kickstart 实用程序

So can test selenium headless on mac. Not headless really but as another user so it doesn't interfere with your current user display. To do this you need kickstart: http://support.apple.com/en-us/HT201710 Begin using the kickstart utility

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -restart -agent

激活远程桌面共享,为所有用户启用访问权限并重新启动 ARD 代理:

Activate Remote Desktop Sharing, enable access privileges for all users and restart ARD Agent:

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -restart -agent -privs -all 

仅限 Apple Remote Desktop 3.2 或更高版本

允许所有用户访问并授予所有用户完全访问权限

Apple Remote Desktop 3.2 or later only

Allow access for all users and give all users full access

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -allowAccessFor -allUsers -privs -all

Kickstart 帮助命令

Kickstart help command

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -help

825