From a shell script open a new tab in a specific instance of Firefox - firefox

I have a shell script that creates Firefox profiles and then uses them to open multiple instances of Firefox simultaneously. The problem is how can I open a URL in a particular instance of Firefox?
I have tried
firefox -CREATEPROFILE test
firefox -P test -no-remote
firefox -P test -url www.google.ie
But the last part which is trying to open the URL using the test profile does not work, it always opens in the default profile.
Is there any way to tell Firefox from the command line to open a URL using a particular profile?
Thanks.
EDIT: I am using Linux, I don't think its possible to do what I want to do from the command line (However, Firefox command-line options are not fully documented so it could be possible). One solution to my problem would be to use JavaScript to open the tabs once the browser has been executed. I think changing the default profile to the profile I want to open each time I want to load a new URL may work also. This will require changes to profiles.ini each time a new URL is loaded. I haven't tested this but it looks promising.

Yes this can be done, Modify your profiles.ini (/home/username/.mozilla/firefox/profiles.ini) to change the default profile each time you want to open a URL in a different profile.
I know this is a bit of a pain but it works and its the only way to do this. Now I can have multiple Firefox instances/profiles open simultaneously and still open new tabs in which ever instance I want from my shell script.
YAY!

Unfortunately Firefox only supports one remote profile at a time, so all your command lines have to remote into the same process. (Mozilla Suite for Linux supported a per-profile remote, but then again it didn't support the -profile flag.)
On the other hand if you know all the URL(s) that you want to load in advance, then you can simply pass all of them on the Firefox command line, concatenated with | characters (but quoted to stop the shell interpreting them). So for instance if you want to start a new instance of the test profile opening the page www.google.ie (only), use firefox -no-remote -P test -browser www.google.ie

Related

Enable remote debugging on Chrome by default on mac?

I am working on getting the VS Code debugger to attach to Chrome as part of my regular workflow.
I keep Chrome running all the time, and the highly-regarded VS Code Live Server extension opens my project in a new tab, which I like. I would like to be able to attach the VS Code debugger to this instance, but it looks like I have to start Chrome from the command line with
sudo /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
Several questions:
Is there a way to modify Chrome's configuration file so that it always starts with that flag set?
Is that a stupid thing to do?
Do I really need the sudo in the line above? Some sources do not have it.
Alternatively, is there a way to create a desktop/toolbar shortcut to chrome that will start it will remote debugging enabled?
Thanks!
PS I see the related SO question for Windows.
There are various Mac answers that used to work that don't anymore. I found one that does and built a double-clickable icon. I posted it on GitHub.
Apparently it's also pretty easy to do using Automator.

The browser opened by geckodriver, is not using default settings for running Robot script

I've set layout.css.devPixelsPerPx in Firefox to be 0.9 (open a new tab, write "about:config" & hit Enter), since I want the browser to be opened with certain level of zoom aspect. It is working fine, when I'm opening the browser manually.
But when I run a robot script, it opens the browser with zoomed in instead of the one, already set above.
So far I've tried following options, apart from above -
1. Tried using Firefox extension, which set default zoom level, but the browser opened by Geckodriver, doen't have that extension available.
2. Run Cntrl+- to zoom out, but as soon as the url changes, the zoom is reset to 100%
3. I can have the Browser open with a command (which has the correct zoom level set). Is there a way, I can ask Robot to use the existing instance of browser than opening new one?
How can I have the Robot open the Firefox browser with certain level of zoom?
The reason why you don't see the setting effective when you run the script is because Selenium creates a new profile when it starts a browser.
Any changes you do in your browser, any extensions you add, are stored in your user's profile. Selenium uses a clean/vanilla (as in: having the default settings) profile so your testing environment is always clean - not influenced by customizations, extensions, cached resources you may have added in your daily work.
If you want to have a particular setting changed in your Selenium browser session, under Firefox with Robotframework - you're "in luck" :). The SeleniumLibrary that comes with it supports starting the browser with a precreted profile - see the documentation, the Open Browser keyword - it has an argument ff_profile_dir.
So create a FF profile with your setting set to the value you need (I don't see a reason why it won't be stored there), and pass its directory as parameter to the Open Browser keyword. Thus when Selenium creates a browser instance, it will use this profile, with that setting effective.

How to open chrome new session using UFT

Sometimes chrome is already open. During run time, UFT opens the AUT in chrome. The script fails sometimes because chrome was already open before the test run. I usually keep the chrome closed before the test runs for a consistent test run. However, it is difficult to keep chrome closed always because I need to keep other applications like Gmail open while I am running tests.
This is the code I have to open chrome.
SystemUtil.Run "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe","www.google.com"
How can UFT open the new session of chrome so UFT ignores the previous session of chrome during run time?
#bugfinder
Option1: Killing the chrome process when you run the test
SystemUtil.CloseProcessByName("chrome.exe")
Option2: Use "CreationTime:=1" ordinal identifier to perform actions on newly created browser instance
If the UFT will run only on the second browser
If you want to open 2 browsers and wanted to perform actions on a third browser then use "CreationTime:=2"
SystemUtil.Run "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe","www.google.com"
Browser("CreationTime:=1").Page("title:=Google").WebEdit("name:=q").Set "what to search"
Use the SytemUtil.CloseProcessbyWndTitle
You can provide regular expressions if parts of the title of your application are changing.
In case that is not possible, I'm afraid you will have to write your own cleanup method where you close all Chrome Instances except the ones you want to spare.

Open a Web Page in a Windows Batch FIle

I have a batch file that does a bunch of things and at the end needs to open up a web browser to a page. Is there a way to, in essence, call ShellExecute on a http to open the web page?
Windows Command Prompt
You can use the start command to do much the same thing as ShellExecute. For example
start "" http://www.stackoverflow.com
This will launch whatever browser is the default browser, so won't necessarily launch Internet Explorer.
1.To run from the default browser, use
start http://www.stackoverflow.com
Please make sure that the appropriate browser is set as default at Control Panel-> default program :
2.To launch page from specific browser, one can use
start "iexplore.exe" http://www.stackoverflow.com
start "chrome.exe" http://www.stackoverflow.com
start "firefox.exe" http://www.stackoverflow.com
Unfortunately, the best method to approach this is to use Internet Explorer as it's a browser that is guaranteed to be on Windows based machines. This will also bring compatibility of other users which might have alternative browsers such as Firefox, Chrome, Opera..etc,
start "iexplore.exe" http://www.website.com
When you use the start command to a website it will use the default browser by default but if you want to use a specific browser then use start iexplorer.exe www.website.com
Also you cannot have http:// in the url.
hh.exe (help pages renderer) is capable of opening some simple webpages:
hh http://www.nissan.com
This will work even if browsing is blocked through:
HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer
start did not work for me.
I used:
firefox http://www.stackoverflow.com
or
chrome http://www.stackoverflow.com
Obviously not great for distributing it, but if you're using it for a specific machine, it should work fine.

Firefox profile changing using command

I want to switch between two firefox profiles online using bat file without closing my firefox. Is it possible? thanx in advance.
Profiles says:
"Firefox saves your personal information such as bookmarks, passwords, and user preferences in a set of files called your profile, which is stored in a separate location from the Firefox program files."
I don't think that is possible. Firefox reads files from the profile directory at start-up and writes them back when quit. If you would do it by hand you still need to tell Firefox to read the initialization files again. This could mess up all the profiles at the end I guess.
Why would that make sense? What do you want to do w/ it?
You can't switch profiles without restarting Firefox.
However, you can run several copies of FF with different profiles simultaneously. I don't know what is your goal, but maybe this can help?
Command line:
firefox -P <profile-name> -no-remote
Be careful not to run more than one instance of Firefox with same profile. The -no-remote switch prevents a Firefox instance from knowing about other instances. If multiple instances access the same profile simultaneously, the profile can be corrupted.

Resources