I'm trying to implement E2E testing in NestJS application. I'm using Postgres in a docker container. It is running fine for other testing. The only problem is E2E testing. And I'm getting the following error:
No Docker client strategy found
at node_modules/testcontainers/dist/docker/docker-client.js:46:11
at fulfilled (node_modules/testcontainers/dist/docker/docker-client.js:5:58)
● Test suite failed to run
TypeError: Cannot read properties of undefined (reading 'close')
59 |
60 | afterAll(async () => {
> 61 | await app.close();
| ^
62 | await container.stop();
63 | });
64 |
at Object.<anonymous> (test/event.e2e-spec.ts:61:15)
My code is given below:
describe('EventAPI (e2e)', () => {
jest.setTimeout(180_000);
let app: INestApplication;
let service: Service;
let container: E2EPgContainer;
beforeAll(async () => {
container = new E2EPgContainer();
await container.init();
// eslint-disable-next-line #typescript-eslint/no-var-requires
const AppModule = require('../src/server/app/app.module').AppModule;
const module: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = module.createNestApplication();
app.useGlobalPipes(new ValidationPipe({ transform: true }));
service = module.get<Service>(Service);
await app.init();
});
afterEach(() => {
jest.clearAllMocks();
});
afterAll(async () => {
await app.close();
await container.stop();
});
describe('GET-POINT API', () => {
it('GET /:customerId --> should return success 200 after get points', async () => {
// test code
});
});
});
How can I solve this issue?
I'm assume that your docker container is running, but not as rootless. Make sure you are running your docker as rootless. You can try following:
$ sudo groupadd docker
$ sudo gpasswd -a $USER docker
Now make sure the following environment variables are set (or add them to ~/.bashrc)
export PATH=/home/ubuntu/bin:$PATH
export DOCKER_HOST=unix:///run/user/1001/docker.sock
Now try to restart docker
$ sudo service docker restart
After all steps try following docker command in terminal without sudo:
$ docker ps
If you are able to see your docker container, then it will solve your problem.
Related
I have created VM instance in GCP using pulumi and installed docker. And I am trying to connect remote instance of the docker but its getting failed to due to connection establishment (asking for a key verification in a pop up window).
const remoteInstance = new docker.Provider(
"remote",
{
host: interpolate`ssh://user#${externalIP}:22`,
},
{ dependsOn: dockerInstallation }
);
I can able to run docker containers locally. But want to run the same in VM. The code snippet is here
with the recent version of "#pulumi/docker": "^3.2.0" you can now pass the ssh options. Reference
const remoteInstance = new docker.Provider(
"remote",
{
host: interpolate`ssh://user#${externalIP}:22`,
sshOpts: [
"-o",
"StrictHostKeyChecking=no",
"-o",
"UserKnownHostsFile=/dev/null",
],
},
{ dependsOn: dockerInstallation }
);
I'm trying to run some Playwright (Node.js) tests on Docker through Selenium Grid, but the tests are failing because of timeout. Chrome is apparently not starting. Locally without Docker everything is fine.
According to the Playwright documentation, it would be enough to run the tests using the following command:
SELENIUM_REMOTE_URL=http://localhost:4444/wd/hub npx playwright test
But that is not working.
I'm building the environment in Docker by running the following file through Powershell:
$maxNodes = 1
function GetImages()
{
docker pull selenium/hub:latest
docker pull selenium/node-chrome:latest
}
function CreateGrid()
{
docker network create grid
}
function CreateHub()
{
docker run -d -p 4442-4444:4442-4444 --net grid --name hub selenium/hub:latest
}
function CreateNodes()
{
$nodes = 1
while($nodes -le $maxNodes)
{
docker run -d -P --net grid -e SE_EVENT_BUS_HOST=hub -e SE_EVENT_BUS_PUBLISH_PORT=4442 -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 -e SE_NODE_SESSION_TIMEOUT=120 selenium/node-chrome:latest
$nodes++
}
}
cls
GetImages
CreateGrid
CreateHub
CreateNodes
cls
Write-Host "HUB AND NODES CREATED!!"
After running the tests using the above mentioned command, the result is as follows.
In Docker Selenium Grid, the following is displayed.
The session is "empty" with nothing running. The browser has a blank page.
The config from playwright.config.ts is:
import { PlaywrightTestConfig } from '#playwright/test';
const config: PlaywrightTestConfig = {
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 1 : 0,
timeout: 20000,
workers:1,
use: {
baseURL: 'https://www.google.com',
viewport: { width: 1280, height: 720 },
browserName: "chromium",
channel: "chrome",
headless: false
}
};
export default config;
And the test running is:
test('Acessar Google', async ({ page }) => {
await page.goto('/');
const length = await page.locator('input[type=submit]').count();
expect(length >= 1).toBeTruthy();
});
I don't know what could be going wrong.
Can anyone help me?
I am new in Rust and to study new language I have decided to write simple "server app" based on TcpListener. It's simple main function that looks like this:
fn main() {
println!("Start server");
let server = TcpListener::bind("127.0.0.1:7878").unwrap();
match server.accept() {
Ok((_socket, addr)) => {
println!("new client: {:?}", addr);
loop {
//do something
}
}
Err(e) => { println!("couldn't accept the client: {:?}", e) }
}
println!("server disconnect")
}
and also I have some client code that connect to listener
fn client() {
match TcpStream::connect("127.0.0.1:7878") {
Ok(mut stream) => {
println!("connect to server");
loop {
// do some work
}
}
Err(e) => { println!("couldn't connect to server: {:?}", e) }
}
println!("client disconnect")
}
When I run it from cmd everything works well but when I run it in docker conteiner I can not connect to listener
couldn't connect: Os { code: 10061, kind: ConnectionRefused, message:
"No connection could be made because the target machine actively
refused it." }
How can I fix it?
I am new in Docker as in Rust so if you need more information pls leave a comment.
Dockerfile:
FROM rust:1.50
WORKDIR /usr/src/appname
COPY . .
RUN cargo install --path .
RUN cargo build --release
CMD cargo run
to run docker container I use docker run --rm -dp 7878:7878 appname
after that when I run client code it returns ok but server does not react (I expect that "new client" message will appear)
I am new to TestCafe and want to run my testcases with runner class in Docker container.
I am able to run single testcase through Docker. But when i want to run with runner class, i am not able to do that.
I have followed this thread https://github.com/DevExpress/testcafe/issues/2761 but i don't know how to define "Environment initialization steps from the TestCafe Docker script in your runner."
my runner file
const testCafe = require('testcafe');
const fs = require('fs');
function runTest(tcOptions) {
testCafe('localhost', 8080, 8081)
.then(function(tc) {
let runner = tc.createRunner();
return runner
.src(['./apps/tests/*.test.js'])
.browsers(['firefox'])
.concurrency(4)
.reporter([
'list',
{
name: 'html',
output: './dist/testcafe/testCafe-report.html'
}
])
.screenshots('./dist/testcafe/testcafe-screenshots', true)
.run(tcOptions)
.catch(function(error) {
console.log(error);
});
})
.then(failedCount => {
if (failedCount > 0) console.log('Error Tests failed: ' + failedCount);
else console.log('All Desktop Tests Passed');
process.exit(0);
})
}
const tcOptions = {
debugMode: false
};
runTest(tcOptions);
and running this Docker command
docker run -v `pwd`/:/tests -e "NODE_PATH=/tests/node_modules" -it --entrypoint node testcafe/testcafe /tests/apps/testcafe//testcafe-desktop-run.js
{ Error: No tests to run. Either the test files contain no tests or the filter function is too restrictive.
at Bootstrapper._getTests (/tests/node_modules/testcafe/src/runner/bootstrapper.js:92:19) code: 'E1009', data: [] }
You need to define the full path to your test files or change your working directory to the /tests directory in the container.
Besides, this step is intended to run the in-memory display server. You may skip it if you are going to run tests in a headless browser.
Here is a command that works on my side with the Runner class:
docker run -v //c/Users/User/test-docker:/tests -w=/tests -it --entrypoint node testcafe/testcafe /tests/test-run.js
set .env like the followings about Server address.
APP_URL=http://localhost:8000
APP_DOMAIN=localhost
I am using apache2 (docker container) as web server.
under this condition, to test with dusk, started up selenium/standalone-chrome as another container.
docker run -p 4444:4444 --name selenium --link apache2:apache2 -d selenium/standalone-chrome
to confirm the connection between docker containers,
used the following commands
docker exec -it selenium bash,
cat /etc/hosts/
result was
172.17.0.6 apache2 a1c15575e4c8
also confirmed ping apache2 from selenium container.
but from here, couldn't do dusk test using following command.
when I check the browser response, there was no contents.
docker exec apache2 php artisan dusk
I think setting is wrong. but can't notice it.
could you help?
the following is php source code.
DuskTestCase.php
abstract class DuskTestCase extends BaseTestCase
{
use CreatesApplication;
/**
* Prepare for Dusk test execution.
*
* #beforeClass
* #return void
*/
public static function prepare()
{
static::startChromeDriver();
}
/**
* Create the RemoteWebDriver instance.
*
* #return \Facebook\WebDriver\Remote\RemoteWebDriver
*/
protected function driver()
{
$options = (new ChromeOptions)->addArguments([
'--disable-gpu',
'--headless'
]);
return RemoteWebDriver::create(
'http://selenium:4444/wd/hub', DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY, $options
)
);
}
}
ExampleTest.php
class ExampleTest extends DuskTestCase
{
public function testBasicExample()
{
$this->browse(function (Browser $browser) {
print_r($browser->visit('/')->resolver->elements);exit;
$browser->visit('/')
->assertSee('login');
});
}
}