Read localstate by chrome-extension - selenium-webdriver

I'm looking for a way to pass arguments from selenium to my chrome-extension in the moment of creating new selenium session. I could pass all arguments using setLocalState, but I have no idea how to read these options by chrome-extension.
Currently what I'm doing is:
create new selenium session with my chrome-extension
open specific url and add all arguments in query string. Chrome is waiting for this url and then parse query string to get these arguments.
Is it possible to pass arguments from selenium and read them by chrome-extension without doing any extra step apart from creating new session with arguments passed in Capabilities?
It's possible In Firefox using profile preferences, but cannot find any way to do that in chrome

Related

using ms-word protocol from a react application to open a docx in MS word

Currently trying to allow users to click a button in a react application to open a .docx document in their local version of word.
Have a C# rest endpoint setup that will return a document as a FileStreamResult if you pass it a document id.
Wondering if anyone has accomplished this before as I was eventually hoping that i could pass an endpoint in to the save parameter so once saved it would upload back to the server.
Tried running the ms-word command however it comes up with "this action couldn't be performed because office doesn't recognize the command it was given". ms-word:ofe|u|<>
Thanks in advance.

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 to pass\ in URL in windows authentication?

To handle windows authentication, one way to handle such scenario is by passing credentials in URL itself as shown below :
driver.get('http://domain\username:password#abc.com')
my user name contains a domain ex. domain\Username. However, when i pass https://domain\username:password#example.com URL it gets converted to '/'. I am using C# selenium bindings. Please suggest a solution to get this working.
You need to replace any special character using its ASCII value .
For \ , it's 092
Also, I believe browsers have dropped support for this syntax of passing credentials along with url and i am sure it won't work if you are using latest browser version of chrome/firefox.
You should instead allow browser to show credential alert and handle it using selenium.
IAlert alert = webDriver.SwitchTo().Alert();
alert.SetAuthenticationCredentials(userId,password);
alert.Accept(); //not sure if this line is required.

Get instance ID when running multiCapabilities in Protractor

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!

select file in Safari in Protractor

Executing this code in Safari doesn't work, but it works in chrome and firefox:
var pathToFile = path.resolve('./scripts', file);
element( by.css('input[ng-file-select="onFileSelect($files)"]')).sendKeys(pathToFile);
In digging around it looks like it's not possible to interact with file inputs in this way in Protractor running on Safari. Does anyone know of a workaround in Safari to put a file path in an input?
This is due to a leaky abstraction, which requires a Safari specific solution:
I guess the workaround for those that really want to do file upload for SafariDriver would be not to do it natively via SafariDriver but by using external code libraries to perform the upload via HTTP/HTTPS (POST) requests (combining any other form data in addition to the file being uploaded/sent), then get response and check whether upload succeeded or not, then go back to SafariDriver code and navigate to next page to check upload succeeded or not, and/or to continue from there for the next steps in the automation.
This approach would be similar to the file download method using HTTP requests externally that has been mentioned in various posts in WebDriver and Selenium user Google groups. Here, it's just the inverse, doing upload instead of download.
Though if the upload requires a session (cookie), then you can extract Selenium session cookie and use with HTTP request. Or if session is stored with session ID in URL, extract that and pass along with HTTP request.
References
Selenium Issue 4220: The SafariDriver does not support file uploads
How to upload file using Selenium when the file input is hidden?
Access is denied error in IE while file uploading
Changing the value of input file
Chrome file upload bug: on change event won't be executed twice with the same file
Selenium IDE 1.4.1 throwing security error when uploading a local file
Dynamically submitting a file upload form in IE10 using jQuery

Resources