問(wèn)題描述
我需要對(duì)我的 AngularJS 應(yīng)用程序進(jìn)行 E2E 測(cè)試,Protractor 似乎是正確的方法.設(shè)置相當(dāng)簡(jiǎn)單,它就像 Chrome 中的魅力一樣.但是我需要使用無(wú)頭瀏覽器并一直在研究如何將 Protractor 與 PhantomJS 一起使用,我發(fā)現(xiàn)了這一點(diǎn):
I need to E2E test my AngularJS Application an Protractor seems like the right way to do it. Setup was fairly straightforward and it works like a charm in Chrome. I need however use headless browser and been researching on how to use Protractor with PhantomJS and I found this:
注意:我們建議不要使用 PhantomJS 進(jìn)行 Protractor 測(cè)試.PhantomJS 崩潰和行為有許多報(bào)告的問(wèn)題不同于真正的瀏覽器.
Note: We recommend against using PhantomJS for tests with Protractor. There are many reported issues with PhantomJS crashing and behaving differently from real browsers.
以上來(lái)自 https://github.com/angular/protractor/blob/master/docs/browser-setup.md
所以我的問(wèn)題是:
情況仍然如此,Proractor 仍然存在 PhantomJS 的問(wèn)題嗎?
Is this still the case and Proractor still having issues with PhantomJS?
如果是這樣,它有多糟糕,有沒(méi)有更好的選擇?
If so how bad is it and is there any better option?
當(dāng)我的應(yīng)用部署到服務(wù)器時(shí),我將如何進(jìn)行 E2E 測(cè)試?
How would I do E2E testing when my app is being deployed to server?
推薦答案
情況仍然如此,Protractor 仍然存在 PhantomJS 問(wèn)題嗎?
Is this still the case and Protractor still having issues with PhantomJS?
這是真的.
如果是這樣,它有多糟糕,有沒(méi)有更好的選擇?
If so how bad is it and is there any better option?
很難回答它有多糟糕,但是關(guān)于掛起 phantomjs、垂死 phantomjs、執(zhí)行緩慢的 phantomjs 存在多個(gè)問(wèn)題,例如:
It's difficult to answer how bad is it, but there are multiple issues about hanging phantomjs, dying phantomjs, performing slow phantomjs e.g.:
- PhantomJS 有時(shí)會(huì)崩潰(開(kāi)放問(wèn)題超過(guò)一年)
- PhantomJS sometimes crashes (open issue for more than a year)
根據(jù)問(wèn)題,您使用 protractor
的主要原因是端到端測(cè)試.您應(yīng)該嘗試模仿真實(shí)世界的用例,模仿在您的應(yīng)用程序中工作的真實(shí)用戶.真正的用戶會(huì)使用什么瀏覽器?幻影JS?答案可能是否定的. 使用您的應(yīng)用程序設(shè)計(jì)的瀏覽器,以及您的真實(shí)用戶使用的瀏覽器.
According to the question, the main reason for you to use protractor
is end-to-end testing. You should try to imitate real-world use cases, imitate a real user working in your application. What browser would a real user use? PhantomJS? The answer is probably "no". Use the browsers which your application is designed to work in, and the browsers your real users use.
當(dāng)我的應(yīng)用部署到服務(wù)器時(shí),我將如何進(jìn)行 E2E 測(cè)試?
How would I do E2E testing when my app is being deployed to server?
最自然"的方法是使用提供不同功能(瀏覽器和平臺(tái))的遠(yuǎn)程 selenium 服務(wù)器.您可以啟動(dòng)和配置自己的 selenium 服務(wù)器,也可以使用 BrowserStack
或 Sauce Labs
做得很好,為您提供了一種在廣泛的應(yīng)用程序中測(cè)試您的應(yīng)用程序的方法各種不同的瀏覽器和系統(tǒng).
The most "natural" approach is to use a remote selenium server that provides different capabilities - browsers and platforms. You can start up and configure your own selenium server, or you can use BrowserStack
or Sauce Labs
which are doing a great job providing you a way to test your application among a wide variety of different browsers and systems.
您還可以在沒(méi)有真實(shí)顯示但虛擬顯示 (xvfb
) 的無(wú)頭環(huán)境"中運(yùn)行量角器,查看更多 這里.
You can also run protractor in a headless "environment" with no real, but virtual display (xvfb
), see more here.
這篇關(guān)于將量角器與 PhantomJS 一起使用的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!