Codeception: Webdriver could not be found and loaded - selenium

I am having some issues running Codeception with Selenium on Windows 8 at my new job.
I get this error:
[Codeception\Exception\Configuration]
Webdriver could not be found and loaded.
I started the Selenium server manually like I described last time in this post: Web Driver Curl Exception
Anyone have any ideas how to fix this?
Edit - Some more info:
I am running WAMP server.
I have configured a Virtual Host in httpd-vhostsconf
I have verified that the Selenium server is started. I tried to run the codeception test with and without the server started, in both cases I get the exact same message.
This is the content of acceptance.suite.yml:
modules:
enabled:
- Webdriver
- AcceptanceHelper
config:
PhpBrowser:
url: 'http://www.mywebsite.dev/'
Webdriver:
url: 'http://www.mywebsite.dev/'
browser: firefox

So look like the problem is mistake in the module name, it should be WebDriver instead of Webdriver
Try running with:
modules:
enabled:
- WebDriver
- AcceptanceHelper
config:
PhpBrowser:
url: 'http://www.mywebsite.dev/'
WebDriver:
url: 'http://www.mywebsite.dev/'
browser: firefox
It should work.

Related

KarateUI: How to add "Host" header into addOptions during the driver configuration? [duplicate]

This question already has answers here:
Karate - UI Testing - When using Zalenium Safari and MSEDGE immediately error on driver/session call => no capabilities found [duplicate]
(2 answers)
Closed 1 year ago.
When I run the test remotely in chrome browser, I was faced with the error [type: STRING, value: Host header is specified and is not an IP address or localhost.] It is an issue https://github.com/web-iq/chrome-remote-debug/issues/1
To overcome it I should set the header = {host: 'localhost'}. The IP address is impossible to use in my case.
My driver configuration:
if (driver == 'docker') {
var driverConfig = {
type: 'chrome',
showDriverLog: true,
start: false,
host: 'karate-chrome.test.svcj',
port: 9222
};
karate.configure('driver', driverConfig);
}
Please, provide the solution for adding "Host" header into addOptions.
It is not clear for which request we need to have this host header and we would like some help replicating this and maybe you can submit a pull request with help from your team.
If you use the Docker container for Karate, it will start "socat" along with Chrome and do port forwarding so you don't run into this problem. Here is an excerpt from the Docker file:
[program:socat]
command=/usr/bin/socat tcp-listen:9222,fork tcp:localhost:9223
So maybe you can add something like this into your environment.

Selenium ChromeDriver Cannot assign requested values

The chromedriver for selenium has recently stopped being able to bind. I am able to launch the hub and the chromedriver, but once I start running the tests, there are errors shown below. Does anyone know if the recent ChromeDriver upgrade has changed something? (Am using the 3.141 version of selenium)
15:28:46.684 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
Starting ChromeDriver 78.0.3904.70 (...-refs/branch-heads/3904#{#800}) on port XXXX
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1572622126.697][SEVERE]: bind() failed: Cannot assign requested address (99)
15:28:49.324 INFO [ProtocolHandshake.createSession] - Detected dialect: W3C
15:28:49.329 INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session 2ff751ceeb9c34c517e24c43a983a3cb (org.openqa.selenium.chrome.ChromeDriverService)
And the driver options configuration:
public WebDriver getDriver() {
AppContext.getEnv().setDriverPermissions(this);
new DesiredCapabilities();
ChromeOptions ops = new ChromeOptions();
ops.addArguments("--incognito");
ops.addArguments("--window-size=1920,1080");
ops.addArguments("--disable-notifications");
ops.addArguments("--allow-running-insecure-content");
ops.addArguments("--start-maximized");
ops.addArguments("--whitelisted-ips");
//ops.addArguments("--headless");
System.setProperty("webdriver.chrome.driver", AppContext.getEnv().getDriverPath(this));
return new ChromeDriver(ops);

WebDriverException: Error forwarding the new session Error forwarding the request Connect to my_ip:5555 [/my_ip] failed: Connection timed out

I installed selenium node on AWS windows and started it. And I setup Jenkins, git, Seleniuim hub on AWS Linux. When i'm building app on Jenkins, selenium hub is trying to connect to selenium node of AWS windows with private IP address. And i'm getting following exception:
org.openqa.selenium.WebDriverException:
Error forwarding the new session Error forwarding the request Connect to windows_private_ip:5555 [/windows_private_ip] failed: Connection timed out (Connection timed out)
Command duration or timeout: 190.25 seconds
Build info: version: '3.5.1', revision: '9c21bb67ef', time: '2017-08-17T15:26:08.955Z'
System info: host: 'some_host_name', ip: 'some_ip', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.76-3.78.amzn1.x86_64', java.version: '1.8.0_151'
Driver info: driver.version: RemoteWebDriver
Caused by: org.openqa.grid.common.exception.GridException: Error forwarding the new session Error forwarding the request Connect to windows_private_ip:5555 [/windows_private_ip] failed: Connection timed out (Connection timed out)
Grid Node command:
C:\Users\Administrator>java -Dwebdriver.chrome.driver=./drivers/windows-driver/chromedriver.exe -jar C:\\Users\\Administrator\\Desktop\\selenium-server-standalone-3.0.1.jar -role node -hub http://ip_address:4444/grid/register
My code is:
if (browser.equalsIgnoreCase("FF")) {
System.setProperty("webdriver.gecko.driver", "drivers/windows-driver/geckodriver.exe");
DesiredCapabilities cap = DesiredCapabilities.firefox();
// Set the platform where we want to run our test- we can use
// MAC and Linux and other platforms as well
cap.setPlatform(Platform.ANY);
cap.setCapability("gecko", true);
// Here you can use hub address, hub will take the
// responsibility to execute the test on respective node
URL url = new URL("http://hub_public_ip:4444/wd/hub");
// Create driver with hub address and capability
gbb = PageFactory.initElements(new RemoteWebDriver(url, cap), GuruBase.class);
} else if (browser.equalsIgnoreCase("IE")) {
System.setProperty("webdriver.ie.driver", "drivers/windows-driver/IEDriverServer.exe");
gbb = PageFactory.initElements(new InternetExplorerDriver(), GuruBase.class);
} else if (browser.equalsIgnoreCase("GC")) {
System.setProperty("webdriver.chrome.driver", "drivers/windows-driver/chromedriver.exe");
ChromeOptions cho = new ChromeOptions();
cho.addArguments("disabled-extensions");
cho.addArguments("--start-maximized");
gbb = PageFactory.initElements(new ChromeDriver(cho), GuruBase.class);
}
else if (browser.equalsIgnoreCase("html")) {
gbb = PageFactory.initElements(new HtmlUnitDriver(true), GuruBase.class);
}
I'm running selenium hub on Jenkins.
A quick solution will be to change :
java -Dwebdriver.gecko.driver=./drivers/windows-driver/chromedriver.exe -jar C:\\Users\\Administrator\\Desktop\\selenium-server-standalone-3.0.1.jar -role node -hub http://ip_address:4444/grid/register
As you are using Dwebdriver.gecko.driver with chromedriver.exe
To either :
Use GeckoDriver :
java -Dwebdriver.gecko.driver=./drivers/windows-driver/geckodriver.exe -jar C:\\Users\\Administrator\\Desktop\\selenium-server-standalone-3.0.1.jar -role node -hub http://ip_address:4444/grid/register
Use Chromedriver :
java -Dwebdriver.chrome.driver=./drivers/windows-driver/chromedriver.exe -jar C:\\Users\\Administrator\\Desktop\\selenium-server-standalone-3.0.1.jar -role node -hub http://ip_address:4444/grid/register
Additionally, you need to check your if() loop as you have a mixed up representation of Windows and Linux styles in System.setProperty() line as follows :
GeckoDriver :
System.setProperty("webdriver.gecko.driver", "drivers/windows-driver/geckodriver.exe");
ChromeDriver :
System.setProperty("webdriver.chrome.driver", "drivers/windows-driver/chromedriver");
IEDriverServer :
System.setProperty("webdriver.ie.driver", "drivers/windows-driver/IEDriverServer.exe");
Note : On Windows Systems you need to mention the extension .exe part e.g. geckodriver.exe while on Linux Systems you need strip off the extension .exe part e.g. chromedriver
This probably caused by your ip not matched. I met the same error and I found that there are two IPv4 address for my machine. One is Eather net and another is WLAN.
Steps:
Disconnect the Wi-Fi.
Use command : ipconfig to check my IPv4 address (there's only one IP there).
With one IP only it should create session correctly.
Perhaps you are using your office computer to make transaction between your node and your hub.
to some extent, you can push your code from office computer <=> github <=> AWS EC2 console.
but registering it as a node / hub and trying to execute the test case may not be possible.
please try with a server in same environment.

How to append a query string to url in codeception

I am attempting to do acceptance testing on a website using Codeception and BrowserStack. The website I am testing requires a query string appended to the url in order to sign-in.
For example: https://examplesite.com/?realm=ab-cd
I have attempted to use this url in the acceptance.suites.yml file:
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://examplesite.com/?realm=ab-cd
host: 'hostmaster#examplesite.com:mykey#hub.browserstack.com'
port: 80
browser: firefox
capabilities:
javascriptEnabled: true
I have also attempted to place a sendGET in the actual test:
$I->sendGET('/?realm=ab-cd');
Both attempts result in not being able to sign in. What would the correct way to do this be?
So I found that in the acceptance.suite.yml file, the Url that you provide can not have a query string appended to it. Following Naktibalda's suggestion, I tried a few variations to the:
$I->amOnPage()
I found when appending a query string I had to start it with the ? (leaving off the preceding /). For example:
$I->amOnPage('?realm=bu-pd'); //Works
$I->amOnPage('/?realm=bu-pd'); //Doesn't work
I reached this question, found a solution myself so giving it here:
$I->amOnPage(['/path','query_param1' => 'bu-pd']);
sendGET belongs to REST module, use amOnPage in WebDriver test.

Setting up Sahi, Behat & PhantomJS on Vagrant

I'm trying to set up automated testing with PhantomJS, Behat and Sahi on my vagrant machine.
I'm getting the following output, when trying to run a test with behat:
[Behat\SahiClient\Exception\ConnectionException]
Exception has been thrown in "afterStep" hook, defined in FeatureContext::afterStep()
Connection time limit reached
Here is my userdata.properties:
# dirs. Relative paths are relative to userdata dir. Separate directories with semi-colon
scripts.dir=scripts;
# default log directory.
logs.dir=logs
# Directory where auto generated ssl cerificates are stored
certs.dir=certs
# Use external proxy server for http
ext.http.proxy.enable=false
ext.http.proxy.host=
ext.http.proxy.port=
ext.http.proxy.auth.enable=false
ext.http.proxy.auth.name=kamlesh
ext.http.proxy.auth.password=password
# Use external proxy server for https
ext.https.proxy.enable=false
ext.https.proxy.host=
ext.https.proxy.port=
ext.https.proxy.auth.enable=false
ext.https.proxy.auth.name=kamlesh
ext.https.proxy.auth.password=password
# There is only one bypass list for both secure and insecure.
ext.http.both.proxy.bypass_hosts=localhost|127.0.0.1|*.internaldomain.com
# Mark this property true to disable the proxy alert
proxy_alert.disabled=false
And my browswer_types.xml:
<browserTypes>
<browserType>
<name>phantomjs</name>
<displayName>PhantomJS</displayName>
<icon>safari.png</icon>
<path>/usr/bin/phantomjs</path>
<options>--ignore-ssl-errors=yes --proxy=localhost:9999 --ssl-protocol=any /usr/local/sahi/phantomjs-sahi.js</options>
<processName>phantomjs</processName>
<capacity>100</capacity>
<force>true</force>
</browserType>
</browserTypes>
behat.yml:
default:
extensions:
Behat\MinkExtension\Extension:
javascript_session: sahi
browser_name: phantomjs
goutte: ~
sahi:
host: localhost
port: 9999
Sahi run output:
--------
SAHI_HOME: ..
SAHI_USERDATA_DIR: ../userdata
SAHI_EXT_CLASS_PATH:
--------
Sahi properties file = /usr/local/sahi/config/sahi.properties
Sahi user properties file = /usr/local/sahi/userdata/config/userdata.properties
Added shutdown hook.
>>>> Sahi OS v5.0 started. Listening on port: 9999
>>>> Configure your browser to use this server and port as its proxy
>>>> Browse any page and CTRL-ALT-DblClick on the page to bring up the Sahi Controller
-----
Reading browser types from: /usr/local/sahi/userdata/config/browser_types.xml
-----
I've tried reinstalling a bunch of stuff, tried playing around with the ports, processes, proxy settings, nothing.
your vagrant comes with an empty or no db. so when you try to connect to your app, e.g log in with some known user it will crash cause it won't find it!
all the best ;)
Since version 4.3.2 of BrowserType change settings. Since there is no tag force. please check.
https://sahipro.com/docs/using-sahi/sahi-headless-execution-with-phantomjs.html#Documentation since Sahi Pro V4.3.2