How to append a query string to url in codeception - 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.

Related

Ansible: How to use examples from the documentation?

I'm starting to learn Ansible and for this I copy and paste examples from the documentation. For example this one
- name: Check that a page returns a status 200 and fail if the word AWESOME is not in the page contents
ansible.builtin.uri:
url: http://www.example.com
return_content: yes
register: this
failed_when: "'AWESOME' not in this.content"
which I've found in uri module documentation.
Every single time I do this, whatever the module I get:
ERROR! 'ansible.builtin.uri' is not a valid attribute for a Play
The error appears to have been in '/home/alfrerra/test2.yml': line 1, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Check that a page returns a status 200 and fail if the word AWESOME is not in the page contents
^ here
I have only 2 playbooks that only ping successfully:
-
name: ping localhost
hosts: localhost
tasks:
- name: ping test
ping
and
---
- name: ping localhost
hosts: localhost
tasks:
- name: ping test
ping
So I adapted the example to match these 2 examples, but to no avail so far.
I'm sure it's nothing much but it's driving me crazy.
As already mentioned within the comments, the documentation are to show how to use certain parameter of certain modules within a single task. They are not mentioned to work in a copy and paste manner by itself or only.
You may have a look into the following minimal example playbook
---
- hosts: localhost
become: false
gather_facts: false
tasks:
- name: Check that a page returns a status 200 and fail if the word 'iana.org' is not in the page contents
uri:
url: http://www.example.com
return_content: yes
environment:
http_proxy: "localhost:3128"
https_proxy: "localhost:3128"
register: this
failed_when: "'iana.org' not in this.content"
- name: Show content
debug:
msg: "{{ this.content }}"
resulting into the output of the page content.
Please take note that the web page of the example domain is connected and delivers a valid result, but it does not contain the word AWESOME. To address this the string to lookup was changed to the page owner iana.org and to not let the task fail. Furthermore and since working behind a proxy it was necessary to address the proxy configuration and which you probably need to remove again.
Your first example is a single task and failing therefore with ERROR! ... not a valid attribute for a Play. Your second and
third examples are playbooks with a single task and therefore executing.
Documentation
Module format and documentation - EXAMPLES block
... show users how your module works with real-world examples in multi-line plain-text YAML format. The best examples are ready for the user to copy and paste into a playbook.
Ansible playbooks
failed_when must be a comparison or a boolean.
example :
- name: Check that a page returns AWESOME is not in the page contents
ansible.builtin.uri:
url: http://www.example.com
return_content: yes
register: this
failed_when: this.rc == 0;
It will execute the task only if the return value is equal to 0

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.

Pattern matching for profile in Spring Cloud Config Server

Context
I am attempting to separate configuration information for our applications using the pattern-matching feature in Spring Cloud Config Server. I have created a repo for "production" environment with a property file floof.yaml. I have created a repo for "development" environment with a property file floof-dev.yaml.
My server config:
spring:
application:
name: "bluemoon"
cloud:
config:
server:
git:
uri: file://${user.home}/tmp/prod
repos:
development:
pattern:
- \*/dev
uri: file://${user.home}/tmp/dev
After starting the server instance, I can successfully retrieve the config content using curl, and can verify which content was served by referring to the "source" element as well as the values for the properties themselves.
Expected Behavior
When I fetch http://localhost:8080/floof/prod I expect to see the source "$HOME/tmp/prod/floof.yaml" and the values from that source, and the actual results match that expectation.
When I fetch http://localhost:8080/floof/dev I expect to see the source "$HOME/tmp/dev/floof-dev.yaml" and the values from that source, but the actual result is the "production" file and contents (the same as if I had fetched .../floof/prod instead.
My Questions
Is my expectation of behavior incorrect? I assume not since there is an example in the documentation in the "Git backend" section that suggests separation by profile is a thing.
Is my server config incorrectly specifying the "development" repo? I turned up the logging verbosity in the server instance and saw nothing in there that called attention to itself in terms of misconfiguration.
Are the property files subject to a naming convention that I'm not following?
I had the same issue. Here is how I resolved::
spring cloud config pattern match for profile
Also, check if you are using Brixton.M5 version.
After some debugging on the PatternMatching source code here is how I resolved the issue: You can choose one of the two ways.
application.yml
server:
port: 8888
spring:
cloud:
config:
server:
git:
uri: ssh://xxxx#github/sample/cloud-config-properties.git
repos:
development:
pattern: '*/development' ## give in quotes
uri: ssh://git#xxxgithub.com/development.git
OR
development:
pattern: xx*/development,*/development ##since it is not allowed to have a value starting with a wildcard( '*' )after pattern I first gave a generic matching but the second value is */development. Since pattern takes multiple values, the second pattern will match with the profile.
uri: ssh://git#xxxgithub.com/development.git
pattern: */development.Error on yml file- expected alphabetic or numeric character, but found but found /.
The reason the profile pattern git repo was not identified because : although spring allows multiple array values for pattern beginning with a '-' in the yml file, the pattern matcher was taking the '-' as string to be matched. i.e it is looking for a pattern '-*/development' instead of '*/development'.
repos:
development:
pattern:
-*/development
-*/staging
Another issue i observed was, I was getting a compilation error on yml file if i had to mention the pattern array as '- */development' - note space after hyphen(which is meant to show that it can hold multiple values as array) and start with a '*/development' with an error: expected alphabetic or numeric character, but found but found /
repos:
development:
pattern:
- */development
- */staging

Codeception: Webdriver could not be found and loaded

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.

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