Cypress tests against devtools port only - cypress

We use some third party enterprise software ("Container App"), which has an embedded Chromium browser, in which our webapp runs.
We use Cypress to test our webapp in a stand-alone browser outside of this container, however we would like to be able to test it inside, as it interacts with the container in various ways through javascript.
The only thing the container exposes is a "remote devtools-url" to the target (our) browser, which can be pasted to a native browser outside of the container and then debugged in devtools. Like this:
The Container provides 2 different url's for above debugging purposes, and they both work and seemingly similarly. They are something like the following (not precise, unfortunately I am not at work atm):
devtools://...inspector.html?id=xxx
http://ip/...inspector.html?id=xxx
Is it possible to setup Cypress to test "as normal", only having access to this remote devtools-url/port?
The target browser inside the container cannot be started by Cypress, as only the container can start and close it. So the target browser will already be running (with a --remote-debugging-port). I can get the devtools-id dynamically through a call to /json/list.
If not possible, any other way to achieve the goal of testing the browser/app running inside the container?

It is not possible. Testing with Cypress a web page in embedded Chromium running in your application means Cypress needs to connect to already running browser. Cypress doesn't have that possibility.
The documentation states:
When you run tests in Cypress, we launch a browser for you. This enables us to:
Create a clean, pristine testing environment.
Access the privileged browser APIs for automation.
There is a request in Cypress issue tracker to add the option to connect to already running browser. But there is no response on it from Cypress developers.

Related

Access filesystem in Karma-Jasmine

I have a bunch of HTML5 canvas tests in my library which I run via Karma and Jasmine. If I detect differences in my tests I show the canvas DOM elements with my generated image output and a diff on the browser page. But when I run my tests in Chrome Headless and/or on my CI environment I have no way of checking the test results in case they fail. And that's currently the issue I'm facing: when I run the tests with a UI, they are green, if I run them in Chrome Headless they fail but I have no chance of checking my visual output.
As solution I'd like to write my generated images to disk. On local tests I can then check this folder what happened an on CI I can publish the result images as artifacts. But here comes the point: Karma and Jasmine seem to have no proper mechanism in place for this task. Also I could not find any plugin tackling this challenge of properly accessing the local file-system from your tests.
A tricky aspect is also that I cannot use promise (async/await) operations at the place where I want to save files. I am within a Jasmine CustomMatcher which does not have promise support I could try rewriting my tests again to handle the error reporting to Jasmine.
My attempts so far:
I started with a custom Karma reporter listening to browser logs and potentially use this as channel to hand over the image bytes to Node for writing to disk. But this additional plugin registration messed with my overall Karma configuration. Karma and Rollup were not working anymore once I registered my custom reporter and I never found out if such large byte amounts can be even transferred via this channel.
Then I started with an API via karma-express-http-server where I "upload" the files to be saved. But I stopped half way as such a simple task seem to require again a bunch of libs and custom implementation to get a simple file upload running (karma-express-http-server, multer). Also I need to rely on synchronous Ajax calls here which is not really future proof.
The Native File System API heavily relies on Promises so I cannot use it.
There must be a simpler way of just writing a file as part of your tests to disk while when using Karma and Jasmine.

Faking non-XHR network requests for Cypress

I have an AngularJS application and I'm trying to use Cypress to stub some of the network requests that it makes. Currently, my problem is with a request with resource type Img. I know from Cypress documentation that Cypress cannot stub non-XHR resource types/requests, but I'm looking for a workaround.
My application requests the image from a backend server, which I want to stub or fake. I prefer not to modify the application code, and would rather create an external workaround.
I've looked into the following and found them not to be useful in this scenario:
Sinon.js - Similarly can only handle XHR requests.
nock - Replaces node's http.request, but that doesn't seem to work within Cypress. It might work if I added it straight into my application code, which I prefer not to do.
I've also tried the following but was unsuccessful:
mockserver - Ran the mockserver and added an expectation, but none of the requests made to the mockserver seemed to go through.
Service Worker API - Was unsure about how to register my service worker, since it requires a .js file as an input. What .js file would be served as input if I'm controlling the service worker via Cypress?
a mock server using express - The issue is the application is running on localhost:<some_port>, while the mock server is running on localhost:<some_other_port>. I'm having trouble specifying port numbers when constructing the request through the application. Basically, my application isn't really respecting different port numbers.
EDIT:
I've been successful with creating a mock server using express. According to Cypress documentation, servers shouldn't be started and stopped within before() and after()'s. Instead, they should be started prior to Cypress being started, and stopped after Cypress is stopped.

Cypress secure to use with production data

I am trying to use cypress for running some monitoring tests on production.I am also using snapshot match plugin to compare screenshots.
I just want to know is this safe to do ?
I am not using any dashboard services from cypress -just running tests on our local machines-will cypress sent any info outside our network?
Cypress doesn't send anything to Cypress's servers unless you specifically configure it to - it's safe.
The only other thing is, by default, Cypress will send crash reports (when Cypress itself crashes) to be analyzed. You can turn this off by following the instructions here.

How to use headless browser via Jmeter GUI

I tried to use the all jmeter's drivers to create headless browser, but unfortunately without success. HtmlUnit Driver works, but doesn't run the javascript, when i run the both Chrome and PhantomJs drivers, i getting the Exception:
java.lang.IllegalArgumentException: Browser has not been configured. Please ensure at least 1 WebDriverConfig is created for a ThreadGroup.
Below my Phantom and Chrome configurations:
Looking into the error you're getting it seems that your Chrome Driver Config and/or PhantomJS Driver Config are not enabled, you need to make the Config element active via Edit -> Toggle menu or pressing Ctrl+T.
Be aware that you can run in fact any browser in headless mode, on Linux you can use virtual framebuffer and on Windows you can just run JMeter as LocalSystem account. Check out Headless Execution of Selenium Tests in Jenkins guide for comprehensive instructions.
Also be informed that even in headless mode real browser footprint in terms of CPU and RAM usage will still be immense so I wouldn't recommend using real browsers for creating the main load, you should stick to JMeter's HTTP Request samplers instead and if needed use single real browser instance via WebDriver Sampler integration for client-side performance checks.
I found the solution myself. If the machine with Jmeter on linux, you should give the permissions to run the executable:
chmod 755 "path to you driver executable file"
Thanks to: https://stackoverflow.com/a/40556732/5279455

Run UI SeleniumRC tests as a part of CI process

I'm trying to setup CI environment for QA department. They use SeleniumRC to run UI tests in IE and FF browsers to test some web application. I had a success configuring it to run as a windows service as described here. However when i run the test it hangs. I can see iexplore.exe process spawned by Selenium service in the process list but nothing more happens. No browser window appears, no entries in the windows event log. I did a lot of googling and as fas as i understand the problem is interaction with desktop. I tried to run the service under SYSTEM account with "Allow service to interact with desktop" check-box set as well as under a regular user account with local admin permissions. So my question is if it's possible at all?
In our organization we have a continuous integration server (Cruise Control) running the build including Selenium RC tests. The CI server is run as a Windows service (on MS Windows 2003 Server) and Selenium tests are just part of the test suite.
That is quite a straightforward setup and frankly I see no reasons for giving up with it. Currently in our setup the Selenium server (and client) is started directly from the tests (however we used to have Selenium as a separate service).
In Java code (actually in the super class of all web tests) we do something like:
// to start the server
RemoteControlConfiguration config = new RemoteControlConfiguration();
config.set(...) // set the serverHost and port
...
SeleniumServer server = new SeleniumServer(config);
server.start();
// and then to start the client
Selenium selenium = new DefaultSelenium(serverHost, port, "*firefox", "http://www.google.com");
selenium.start();
selenium.open("http://www.google.com");
// now the browser should be visible for you (if you run it locally, not as a service)
So I would suggest you trying the following (whatever language you are using):
Try to run the Selenium server and client from just a standalone application. The browser should show up as a window. Adjust the settings to your needs (browser type, etc.).
Try to incorporate the code within your test framework (xUnit or whatever). Run them manually. The result should be the same.
Then you can try to have the tests run from the continuous-integration. Run the CI server as a service and let it build your project. The browser wouldn't be visible, but that's not required for the tests to be run, isn't it?
NOTE:
if you wanted to peep what Selenium is doing, I believe it would be easier on UNIX machine. You could point the tests to use the X-server DISPLAY of your choice - a fake one or a true one connected to some monitor.
I'm skeptical about running anything as a windows service that is supposed to interact with a desktop application. Windows services run in their own sandbox; they're not supposed to interact with a user's desktop or its applications. To do so requires special efforts to communicate with the service, so if it is possible at all, I would think there would be some kind of desktop client running as well, acting as a liaison between the browser and the windows service.
I can't tell you it won't work, though, because it is obviously possible if people are blogging about it.
Why does it need to run as a Windows service, by the way? Is that how Selenium has set up their automation, or can you do it without the Windows service? Because I think that would be the shortest distance between two points.
My recommendation would be to have a dedicated machine (or virtual machine) for running Selenium RC. In my experience it's best to let Selenium run interactively rather than in a headless mode.

Resources