docker dusk browser can't another web server container - docker

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');
});
}
}

Related

Playwright is not running tests on Selenium Grid + Docker

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?

DNS resolution failure error while connecting to grpc server running on docker

I am trying to access the grpc server which exposes 9000 port and is running as docker container.
I am using .net core client to connect to the server.It works perfectly fine when GRPC server is not running as a docker container.
I have tried using both the "localhost","dockerconatiner-ip" while creating the channel from client.I am running the grpc server on "0.0.0.0"and port 9000.
docker commands:
docker run -p 9000:9000 -a stdin -a stdout -it
Error:
Status(StatusCode=Unavailable, Detail="DNS resolution failed")
dockerfile:
FROM mcr.microsoft.com/dotnet/core/runtime:3.0
COPY Sample/bin/Release/netcoreapp3.0/publish/ app/
WORKDIR /app
EXPOSE 9000
ENTRYPOINT ["dotnet", "Sample.dll"]
Service Main:
static void Main(string[] args)
{
try
{
Environment.SetEnvironmentVariable("GRPC_VERBOSITY", "DEBUG");
const int Port = 9000;
Server server = new Server
{
Ports = { new ServerPort("0.0.0.0", 9000, ServerCredentials.Insecure) },
Services = { BindService(new TestService()) }
};
server.Start();
Console.WriteLine("starting server");
Console.WriteLine("Press any key to shut down");
Console.ReadKey();
server.ShutdownAsync().Wait();
Console.WriteLine("Grpc Server stopped");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
Test service has a method to print received text to console.

How to run TestCafe runner class with Docker

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

Connecting to docker container via telnet

I have a NET Core Console Application which has a socket binded to a port.
I have dockerized this application and i am trying to expose the binded port.The program shows its output correctly when i use docker attach [instance] .However when trying to connect with Telnet i get the error:
Error
$ telnet 127.0.0.1 20001
Connecting To 127.0.0.1...Could not open connection to the host, on port 8806: Connect failed
.NET Server
class Program {
public const int BUFFER_SIZE = 1024;
public const int EXPOSED_PORT = 20001;
public const string ADDRESS = "127.0.0.1";
public const int MAX_CONNECTIONS = 1;
public static ReadOnlyMemory<byte> CreateMessage(ReadOnlyMemory<byte>request) {
Memory<byte> response= Encoding.UTF8.GetBytes($"Response from Daemon:{DateTime.Now.ToString()}");
///------code------//
return response;
}
static async Task Main(string[] args) {
Memory<byte> buffer = ArrayPool<byte>.Shared.Rent(BUFFER_SIZE);
using (Socket serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) {
serverSocket.Bind(new IPEndPoint(IPAddress.Parse(ADDRESS), EXPOSED_PORT));
Console.WriteLine($"Server started at {DateTime.Now.ToShortTimeString()} \r\nListening on port{EXPOSED_PORT}");
serverSocket.Listen(MAX_CONNECTIONS);
var client =await serverSocket.AcceptAsync();
while (true) {
int rxCount =await client.ReceiveAsync(buffer, SocketFlags.None);
if ((char) buffer.Span[0] == 'x'){
break;
}
await client.SendAsync(CreateMessage(buffer.Slice(0, rxCount)), SocketFlags.None);
}
}
ArrayPool<byte>.Shared.Return(buffer.ToArray());
}
}
Dockerfile
FROM microsoft/dotnet:latest
WORKDIR /app
COPY ./bin/Release/netcoreapp2.1/publish .
ENTRYPOINT [ "dotnet","DockerContainerDaemon.dll" ]
EXPOSE 20001
docker and build command script
dotnet build -c Release
dotnet publish
docker build --build-arg Port=20001 -t daemon .
docker stop inst1
docker rm inst1
docker run --name inst1 -p 20001:20001 -d daemon
Running docker -ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f675c3e502ad daemon "dotnet DockerContai…" 5 seconds ago Up 3 seconds 0.0.0.0:20001->20001/tcp inst1
P.S As someone pointed out i tried exposing with both 127.0.0.1 and 0.0.0.0 from the .NET Application. to no avail.
Try to bind the application to 0.0.0.0 instead of 127.0.0.1. This will solve your problem.

Couldn't connect to Docker Aerospike from host

I'm running aerospike server in docker.
$ docker run -d --name aerospike aerospike/aerospike-server
0ad3b2df67bd17f896e87ed119758d9af7fcdd9b82a8632828e01072e2c5673f
It is started successfully.
$docker ps
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS NAMES
0ad3b2df67bd aerospike/aerospike-server "/entrypoint.sh asd"
4 seconds ago Up 2 seconds 3000-3003/tcp aerospike
I found the ip address of docker using below command.
$ docker inspect -f '{{.NetworkSettings.IPAddress }}' aerospike
172.17.0.2
When I trying to connect to aql using the below command, it is successful as well.
$ docker run -it aerospike/aerospike-tools aql -h $(docker inspect -f
'{{.NetworkSettings.IPAddress }}' aerospike)
Aerospike Query Client
Version 3.15.0.3
C Client Version 4.2.0
Copyright 2012-2017 Aerospike. All rights reserved.
aql> select * from test.person
0 rows in set (0.002 secs)
Now I am trying to connect to the aerospike server in docker using java client in host machine.
public class AerospikeDemo {
public static void main(String []args) {
AerospikeClient client = new AerospikeClient("172.17.0.2", 3000);
Key key = new Key("test", "demo", "putgetkey");
//Key key2 = new Key("1", "2", "3");
Bin bin1 = new Bin("bin1", "value1");
Bin bin2 = new Bin("bin2", "value2");
Bin bin3 = new Bin("bin2", "value3");
// Write a record
client.put(null, key, bin1, bin2, bin3);
// Read a record
Record record = client.get(null, key);
System.out.println("record is "+ record);
System.out.println("record bins is " + record.bins);
client.close();
}
}
When I run the above program, I'm getting below error -
objc[3446]: Class JavaLaunchHelper is implemented in both
/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java (0x10f7b14c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10f8794e0). One of the two will be used. Which one is undefined.
Exception in thread "main" com.aerospike.client.AerospikeException$Connection:
Error Code 11: Failed to connect to host(s): 172.17.0.2 3000 Error Code 11: java.net.SocketTimeoutException: connect timed out
at com.aerospike.client.cluster.Cluster.seedNodes(Cluster.java:413)
at com.aerospike.client.cluster.Cluster.tend(Cluster.java:306)
at com.aerospike.client.cluster.Cluster.waitTillStabilized(Cluster.java:271)
at com.aerospike.client.cluster.Cluster.initTendThread(Cluster.java:181)
at com.aerospike.client.AerospikeClient.<init>(AerospikeClient.java:210)
at com.aerospike.client.AerospikeClient.<init>(AerospikeClient.java:151)
at com.demo.aerospike.AerospikeDemo.main(AerospikeDemo.java:12)
I've tried both AerospikeClient("172.17.0.2", 3000) and AerospikeClient("localhost", 3000)
I see in the Dockerfile the port 3000 is exposed to the host but I'm not sure why I'm not able to use the aerospike server in the docker.
The IP 172.17.0.2 is only accessible within Docker (therefore you can use another container to connect). In case you want to connect from your host you need to map the respective port.
docker run -d --name aerospike -p 3000:3000 aerospike/aerospike-server
Afterwards you can use:
AerospikeClient client = new AerospikeClient("localhost", 3000);

Resources