Get instance ID when running multiCapabilities in Protractor - angularjs

I'm using multiCapabilities with Protractor. Is there any way to get the instance ID that my tests is running on. I need this because I want each browser sign in with a different account.

What you want to look for is not "instance ID" but sessionID. You would retrieve this by running the following code in your spec:
browser.getSession().then(function(session) {
// do something with sessionID.
});
This will provide the sessionID for the specific spec in a multiCapabilities configuration.

Apparently it is not possible per this GitHub ticket.
What I did was using a buffer JSON file for keeping my configs per capability and use fs to read from it in onPrepare method that runs per capability. I mark each set of params that is used in the file again to avoid using the same set of params again. This way each capability can sign in with a different user name.
It was very manual but worked!

Related

Sending request to WinAppDriver (WebDriver) using Postman

Recently I was attempting to use an xPath query to find a set of elements within my Windows Universal application. I was using WinAppDriver to automate the tests. The specific challenge was that due to the nature of the application and the automation it would take 60-90 seconds to automate my application to the point where I could execute my xPath query. Since I am not terribly familiar with xPath queries I needed to identify the desired query via what can only be described as a trial and error process. The combined time of making a code change, rebuilding the application and then running the app until the point where the xPath query was evaluated meant that it took me a few minutes per iteration and the process was very slow. I decided that it would be much more efficient if I could set a break point in the test code, execute the code to the point where the application under test was in the desired state and then use Postman to execute multiple queries while I figure out the exact query I need to be running.
It is possible to send Appium or Selenium requests to a WebDriver compatible service. This approach is not recommended as an alternative automation technique but can be convenient to debug specific commands.
The steps are outlined below:
Create a new Postman environment to contain your WinAppDriver requests
Create a new request tab within this environment
The URL for WebDriver requests should be of the following form “http://[ip address:port]/session/{{sessionID}}/[command].
The ip address should match the WebDriver address used when launching your WebDriver service. Typically, this is 127.0.0.1 by default
The port is the port specified when connecting to the WebDriver service. By default, this is typically 4723 but it can be specified at run time when you launch the WebDriver service on your local machine.
The session id can be found in the WinAppDriver console window
The screen shot below shows a capture of a WinAppDriver command. The first circled area is the Session ID value that should be used in the query above. The second circled area is the ip address and the port ID value and the third area is the query body that was sent. This query body corresponds to the WinAppDriver command.
The corresponding Postman query would look like the screen shot below.
I set the Content-Type to be “application/json”. Note that the last line in the screen grab above is the response content and contains the session variable again along with the element ID of the discovered element.
The [command] value and any optional query body is specific to the desired command. The best way to figure that out is to run the desired command from within your automation software and refer to the WinAppDriver output to see the command that is getting sent. Typically, I set a breakpoint in the debugger on the line I want to execute and then single step through that command while looking at the WinAppDriver output window. This lets me determine exactly the output corresponding to my command. You can then send multiple command from PostMan while the test application is stopped in the debugger. Do not close the test application until you are done because this will free up the session connection.
This approach lets you quickly try different iterations of the desired command and see if WinAppDriver finds the desired control

how do I mock a session_id in my integration test

I have this code in one of my controllers
$this->request->getSession()->id()
One of my integration tests fails, because this method call is not returning anything. I tried the following in my test setup, but it does not work:
$this->session([
'id' => 'cb3d42b1-4ea0-44c6-8e29-368e948257eb',
]);
Is there a way to make $this->request->getSession()->id() return a value in the integration test setup?
The \Cake\TestSuite\IntegrationTestTrait::session() method accepts values that are being written into the session for the test request, ie session data, it will not configure any other session aspects like the ID.
Normally CakePHP's session class would set a value of cli for the session id when running on the CLI, simply by doing $this->id('cli'), but as of PHP 7.2 that will not work anymore when there's already been output generated, also as of CakePHP 3.5, CakePHP actively prevents setting the ID in case headers have already been sent, ie you probably won't be able to change the ID in your test cases.
So what can you do? Well, you can settle for a fixed value and set it in your test bootstrap (tests/bootstrap.php), which is what the default test bootstrap in the CakePHP 4.x application template now does too, ie simply do:
session_id('my-custom-id');

How to pass deployment settings to application?

I am trying to deploy a Qooxdoo web application backed by CherryPy-hosted web services onto a server. However, I need to configure the client-side Qooxdoo application with the hostname of the server on which the application resides so that that the Ajax callbacks resolve to the right host. I have a feeling I can use the capabilities of the generate.py Qooxdoo script to generate client-side code with this appropriately set, but reading through the docs hasn't helped make it clear how yet. Anyone have any tips?
(FWIW, I know how I'd approach this using something like PHP and a different client-side framework like Echo 3--I'd have the index file be a PHP file that reads a local system configuration file prior to sending back client-side code. In this case, however, the generate.py file is a necessary part of the toolchain, so I can't see how to do it so simply.)
You can use qx.core.Enviroment class to add/get configuration for your project. The recommend way is only during compilation time, but there is a hack if you want to configure your application during run time.
Configuration during compilation time
If you want to configure the environment during compilation time see this.
In both cases after you add any environmental variable to your application, it can be accessed using the qx.core.Environment.get method.
On run time
WARNING this method isn't supported/documented from qooxdoo. Basically it's a hack
If you want to make available some environment configuration on run time you have to do this before qooxdoo loads. In order to this you could add some javascript into your webpage e.g.
window.qx = { };
window.qx.$$environment = {
"myawsomeapp.hostname": "example.org",
};
This should be added somewhere in your page before the qooxdoo start loading otherwise it will not have the desirable effect. The advantage of this method is that you can push configuration to the client e.g. some api keys that may be different between instances of your application.
The easiest way will be to compose your AJAX URL on the fly from window.location; ideally, you would be able to use window.location.origin which for this StackOverflow website would be "https://stackoverflow.com" but there are issues with that on IE.
A cross platform solution is:
var urlRoot = window.location.protocol + "//" +
window.location.hostname + (window.location.port ? ':' +
window.location.port: '');
This means your URL will always be correct, even if the server name changes (eg your on a test server instead of production).
See here for more details:
https://tosbourn.com/a-fix-for-window-location-origin-in-internet-explorer/

Cookies for inferHtmlResources

I want to use Gatling for testing that I can access html resources.
In order to access given HTML, and its resources, I have to have some cookies defined.
I can set Cookies in http call with simple .header("Cookie","test=test"), but that way, it doesn't set cookie to inferred resources.
According to docs, you should be able to set cookies as:
One might want to manually add or compute a cookie:
exec(addCookie(Cookie("name", "value")))
but that doesn't work for me at all when used like this:
val someScenario = scenario("scenario").exec(
exec(addCookie(Cookie("test","test"))),
exec(http("httpcall").get("someUrl")))
Is there a way to set cookies for inferHtmlResources?
Cookies are bound to a domain. If you don't specify one with withDomain, Gatling will use the one of the HttpProtocol baseUrl, and crash if you don't have one. So, a possible explanation is that this default domain doesn't match the one of your resources. If that's the case, set a proper domain on your cookie.
Otherwise, it could be a bug. Check the bug tracker, upgrade your Gatling version if you use an old one (as you don't specify the version you're using, which is bad), and give the latest snapshot a try. If nothing works, open an issue where you provide a way to reproduce.

Disable Session.checkAgent for one action

I have built a controller that is uses the media view to stream videos to users. When someone accesses the controller from an iOS device, the user agent being sent is not matching and the session logs out.
I am using the iPad plugin for Flow Player and I have seen other posts about flash not sending the correct user agent strings, so instead of messing with that, I'd like to disable Session.checkAgent for that specific action. I have tried adding it to beforeFilter(), but the check clearly happens before that point.
Is there some other method I can override to implement this?
I haven't tested it, but if you know (part of) the URL, you can check the $_GET['url'] inside your app/Config/core.php and modify the session configuration based upon its value, For example, $_GET['url'] starts with '/videos/view'.
You need to do this inside the configuration file, otherwise the session is already started as you already discovered.
Note that $_GET['url'] is only used in older versions of CakePHP. For newer versions of CakePHP, you may need to user $_SERVER['REQUEST_URI'] or another $_SERVER environment variable.

Resources