I can handle it with FF web driver (selenium python) but when I change phantomjs the driver .it didnt handle it. is it possible to handle it?
the program must work on server so what must I do?
In short, no, this is not currently possible. The PhantomJS ghostdriver does not implement the primitives for handling alerts/prompts. See https://github.com/detro/ghostdriver/issues/20
This is also unlikely to change since development of PhantomJS has been discontinued.
the program must work on server so what must I do?
Your best option is to use the headless versions of Chrome or Firefox, which can run in a headless environment like PhantomJS just fine. Both Chrome (chromedriver) and Firefox (geckodriver) implement the necessary primitives for handling alerts/prompts.
Another option is that you can use a virtual screen program (e.g. xvfb) to enable you to use a headed browser in a headless environment.
Related
Since browser auto-update runs on the system unless we manually turn it off,
how to automate in selenium to identify if there is a browser upgraded?
If the browser updates e.g. Chrome, you will need to have the compatible binary for that browser. There's a good answer and overview on this here.
To avoid this, I personally used ephemeral instances of Chrome, specifically SauceLabs and containerized tests using docker-selenium.
On my local machine, I arrived to test my applications with Selenium with any problems.
But, when I'm doing the same operations on a server Centos7 (I have no graphical interface), I've many errors such as web element not found.
I'm using Docker containers for selenium (hub and nodes). The installation is OK and I can see my drivers on Http://:4444/grid/console.
Does Selenium require a graphical interface for its work?
Yes. Selenium requires the browser GUI to be present - which is also called viewport.
If you want that Selenium execution happen, without the browser GUI to be present, then you need to use a headless browser, which , as the name suggests is headless, which means there would be no GUI for them.
Examples of these headless browser include PhantomJS- link. Now Chrome also has a headless mode - link, which you can specify using ChromeOptions. Cheers!
Can anyone explain what is running selenium tests in headless mode in jenkins?
As per comment it's a way of running tests in a browser that doesn't have a GUI attached to it
What is a headless browser? (Quoted from ToolsQA)
Headless browser is a term used to define browser simulation programs
which do not have a GUI. These programs behave just like a browser but
don’t show any GUI. Famous ones are HtmlUnit and the NodeJs headless
browsers. There are a good number of more browsers too.
What is the use of Headless browsers?
Headless browsers are typically used in following situations
You have a central build tool which does not have any browser installed on it. So to do the basic level of sanity tests after every
build you may use the headless browser to run your tests.
You want to write a crawler program that goes through different pages and collects data, headless browser will be your choice. Because
you really don’t care about opening a browser. All you need is to
access the webpages.
You would like to simulate multiple browser versions on the same machine. In that case you would want to use a headless browser,
because most of them support simulation of different versions of
browsers. We will come to this point soon.
Things to pay attention to before using headless browser
Headless browsers are simulation programs, they are not your real
browsers. Most of these headless browsers have evolved enough to
simulate, to a pretty close approximation, like a real browser. Still
you would not want to run all your tests in a headless browser.
JavaScript is one area where you would want to be really careful
before using a Headless browser. JavaScript are implemented
differently by different browsers. Although JavaScript is a standard
but each browser has its own little differences in the way that they
have implemented JavaScript. This is also true in case of headless
browsers also. For example HtmlUnit headless browser uses the Rihno
JavaScript engine which not being used by any other browser.
I would like to make it clear about the difference between protractor VS ghostdriver.
With protractor:
start selenium web server for testing.
multiple browser testing.
whenever it start testing, it open the browser.
With ghostdriver:
start phantomjs web server.
can be config multiple browser too.
can run separate with selenium or integrate with selenium.
My question is PhantomJS webdriver can run alone without selenium webdriver, multiple browsers and good for CI. Why do we need to run selenium and integrate selenium with phantomjs using ghostdriver?
While I'm not entirely sure I understand your question, I'll take a stab at answering it. With WebDriver, driving a browser is done via a standardized JSON-over-HTTP wire protocol. This means that you need a "server" component that understands the wire protocol to drive any particular browser. For each of the major desktop browsers (Internet Explorer, Chrome, and Firefox), there is a server component that your WebDriver code talks to (IEDriverServer.exe, chromedriver.exe, or a Firefox browser extension, respectively). PhantomJS also implements a server component that understands the WebDriver wire protocol, so the same high-level WebDriver code can be used with PhantomJS that is used with other browsers. Note that the Selenium server is not required to drive any of the browsers on the local machine.
Now, since the protocol used is simply transmitted over HTTP, that gives WebDriver the opportunity to run the WebDriver code on one machine, while driving a browser located on an entirely different machine. That's where the Selenium server comes in. The Selenium server starts an HTTP server that understands the WebDriver JSON wire protocol. When that server receives a WebDriver command, it can forward that command to another "server" component, either running on that machine (as a standalone remote server), or on yet another machine running another instance of the Selenium server (in a "grid" configuration).
So to answer your question, yes, WebDriver code can be executed against PhantomJS without using the Selenium server. It can likewise be executed against Internet Explorer, Firefox, Chrome, Safari, and some versions of Opera, all without using the Selenium server. Notice that all of this is true without mentioning Protractor at all. Since Protractor is based on WebDriverJS, as long as there's a "server" component running, whether that's a Selenium server, chromedriver.exe, IEDriverServer.exe, or PhantomJS, the driver should be able to communicate with and drive that browser. Looking at the code, it appears that WebDriverJS (and, by extension, Protractor), should be able to execute against Chrome and PhantomJS without requiring the Selenium server, but I don't know enough about Protractor's wrapping of WebDriverJS to speak with authority.
So I came across zombie.js, is this a headless browser?
If so, what browser engine does it use?
Could I rely on it for doing lot of automated tests? Basically, I am restricted to a single server, so I would like to squeeze as many browser tests as possible.
Currently, I am relying on Selenium FirefoxDriver to run my tests. How would zombie.js compare in performance and efficiency to Selenium Webdriver browser instances running? However, there's limitation to how many browser instances I can run in parallel.
Yes, Zombie is headless.
"Whick browser engine?" - > well, it uses a mixture of technologies:
for Javascript: V8 from Chrome (run by node.js)
for DOM: JSDOM
for HTML5 parsing: https://github.com/aredridel/html5
Performance: should be much faster, according to author's statement: http://labnotes.org/2010/12/30/zombie-js-insanely-fast-full-stack-headless-testing/
is this a headless browser?
I haven't used it, but it certainly looks like a headless browser:
If you're going to write an insanely fast, headless browser, how can you not call it Zombie? Zombie it is.
Zombie.js is a lightweight framework for testing client-side JavaScript code in a simulated environment. No browser required.
what browser engine does it use?
From http://zombie.labnotes.org/guts.html#Grocking:
The DOM implementation is JSDOM, which provides an emulation of DOM Level 3.