I am creating various tests with codeception - especially acceptance tests where I test the frontend or an API. The problem ist that on my local machine I am using a webserver with a port 8080 on the test server the port is 9000.
Is there a way I can dynamically set the WebDriver url? In php or another yml file. Right now the URL is set in acceptance.suite.yml and it looks like this:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://localhost:8080/myapp'
browser: phantomjs
When I run this test on my test machine, all the tests fail (of course) because the server is running on port 9000 and not 8080.
Thanks.
I am using .env files for exactly this reason.
https://barryvanveen.nl/blog/36-environment-configuration-in-codeception-with-dotenv
Related
I am trying to launch my serenity-Cucumber tests on a Jenkins server. Actually I'm stuck with a simple error when it launch ChromeDriver :
"IPv4 port not available. Exiting..."
My failed tests are simple : goes to a special url and verify if the url is the one expected
I'm running on maven 1.9.9 - cucumber 1.9.5 - serenity 1.9.9 - chromedriver 2.40 - jenkins 2.19.1
I run my project with command "clean verify"
I tried to set a proxy but it didn t change anything - and I tried to change chromeDriver's port without results
Is there someone who has already face this problem ?
Starting ChromeDriver 2.40.565383 (76257d1ab79276b2d53ee976b2c3e3b9f335cde7) on port 4013
Only local connections are allowed.
Starting ChromeDriver 2.40.565383 (76257d1ab79276b2d53ee976b2c3e3b9f335cde7) on port 9015
Only local connections are allowed.
IPv4 port not available. Exiting...
i am containerising my spring boot app which uses selenium/standalone-firefox-debug i have created docker compose file,but when i up it it gives me error as
Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
But if i run the spring-boot app directly and selenium/standalone-firefox-debug seperatly it works.I want to run it with docker-compose
Dockerfile:
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
ADD ${JAR_FILE} app.jar
ENTRYPOINT exec java -jar /app.jar
Dockercompose:
version: '2.2'
services:
employer-url:
image: "adib/employer-url"
ports:
- "8080:8080"
depends_on:
- firefox
firefox:
image: "selenium/standalone-firefox-debug"
ports:
- "4444:4444"
environment:
- no_proxy=localhost
this is how i create driver in spring app
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.firefox());
Problem
This http://localhost:4444/wd/hub URL refers to the localhost which belongs to the container runtime. The springboot container does not have port 4444 running that's why it's complaining.
Solution
You should access the selenium service from its hostname (not localhost). In springboot application, you can use, http://firefox:4444/wd/hub URL and you'd be good to go.
Rationale
You are missing the core of the networking concept in containers here. Both of these images (viz springboot and selenium) are running inside containers and hence they have their separate environments. If you refer to localhost inside any container, it means the localhost of that container. You are expecting localhost to refer to the localhost of the docker host machine. You exposed port 4444 on the docker host machine. So if you try to run your jar from the docker host (while selenium is containerized) localhost:4444 would work but if you access it from inside a container, it's not going to work. Following Diagram shows the concept:
I'm trying to setup selenium standalone chrome service to test my Codeception suit.
I run chrome standalone as a service:
services:
- mysql:latest
- selenium/standalone-chrome:latest
And then I setup the connections for my Codeception test uses WebDriver with an extension for WordPress:
WPWebDriver:
url: 'http://localhost'
host: 'selenium__standalone-chrome'
browser: chrome
port: 4444
restart: true
wait: 2
adminUsername: admin
adminPassword: 1234
adminUrl: /wp-admin
All other tests run well but when it comes to the suite where I use Selenium it refuses to connect:
Time: 7.55 seconds, Memory: 16.00MB
There was 1 failure:
---------
1) SampleTestCept: Test if wp is working in selenium
Test tests/php/acceptance/SampleTestCept.php
Step See "Just another WordPress site"
Fail Failed asserting that on page /
--> This site can’t be reached
localhost refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED
Reload
DETAILS
--> contains "this site can't be reached".
Scenario Steps:
2. $I->see("This site can't be reached") at tests/php/acceptance/SampleTestCept.php:6
1. $I->amOnPage("/") at tests/php/acceptance/SampleTestCept.php:4
Any ideas of what am I doing wrong?
Use environment variable HOSTNAME, to find gitlab runner actual hostname.
I worked around this by replacing 'localhost' in your webdriver config by the ip-address of the gitlab runner. You might want to check out my blog post about running codeception tests on gitlab-ci.
Probably the issue is that you are using http://localhost url and running selenium server on separate host.
Selenium tries to connect to port 80 of its own, not of the machine which is running tests.
Im currently making an acceptance test with the following tools:
Codeception
Selenium Webdriver
PhantomJS (as headless browser ghost)
My problem is My Tests fail when visiting a self-signed (https) page
What I've tried:
phantomjs --webdriver=5555 --ignore-ssl-errors=true --ssl-protocol=any
Adding this in capabilities phantomjs.cli.args: ["--ignore-ssl-errors=true"] in my acceptance.suit.yml
So far these options doesnt give me any luck.
Here is my acceptance.suit.yml file
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver:
url: https://myproject.com
browser: firefox
capabilities:
unexpectedAlertBehaviour: 'accept'
env:
phantom:
modules:
enabled:
- WebDriver
config:
WebDriver:
url: https://myproject.com
http_proxy: 192.1.1.1
http_proxy_port: 3000
browser: phantomjs
capabilities:
phantomjs.cli.args: ["--ignore-ssl-errors=true"]
UPDATE
This error shows up [ModuleException] WebDriver: Current url is blank, no page was opened
I don't know why this error happens since I've indicated a page. Here is a sample of my test
public function tryToTestThis(AcceptanceTester $I)
{
$I->wantTo('Test this function');
$I->amOnPage('/mypage/');
$I->see('This text');
}
An answer in Codeception would be preferable. Thanks
We figured out the cause if this problem. It was because I was running Selenium and phantomJS at the same time. (I got this idea from some tutorial.)
I was doing
java -jar selenium.jar
then I do this since it causes an error running phantomjs at port 4444 (Obviously selenium is using it) I use port 5555 instead.
phantomjs --webdriver=5555 --ignore-ssl-errors=true --ssl-protocol=any
Note: Everything works fine if not involved with https / ssl self-signed pages.
We think that codeception prioritize port 4444 and disregarding any option indicated in my phantomjs i.e. --ignore-ssl-errors=true --ssl-protocol=any thats why in fails to visit https/self-signed pages.
So basically, the fix was just running phantomjs alone without selenium.
phantomjs --webdriver=4444 --ignore-ssl-errors=true --ssl-protocol=any
Thank you
I have Selenium server listening to 4444 port. How can I make selenium listen to connection only from localhost but not from the whole internet?
Or is there any other way to secure Selenium?
My selenium server is run with such parameters:
java -jar selenium-server-standalone-2.44.0.jar -p 4444
This is something that is out of the scope of the application itself, you could place your Selenium server behind a reverse proxy (e.g., Apache Web Server) and just allow local connections to it or just configure your OS's firewall.