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.
Related
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.
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.
I run a lot of automation using Firefox driver, and it takes a while (20-30 minutes). Naturally, while its running, I continue to work on something else.
However, while I doing things, I occasionally press the Shift key while a new Firefox instance is starting up. However, Firefox has hardcoded that it will boot in safe mode if you are holding shift, which then freezes automation in its "Are you sure you want to boot in safe mode?"
Here's the different options I've considered:
When I first ran into this, I thought that it was an issue with Firefox crashing multiple times. I changed toolkit.startup.max_resumed_crashes to 99999999 and browser.safebrowsing.enabled to false, both manually, and in my FirefoxProfile
I've tried this and this, both of which apparently refer to an old version of firefox, because the files they describe no longer exist.
This doesn't sound like it will work because profiles don't have anything to do with Safe Mode and I can't execute any AutoIt code because Selenium is still maintaining control as its frozen with the popup.
Running Firefox 3.6 or lower is not an option. Running headless is currently in the works (using Phantom), but we'll never stop running it with firefox. The same is true for the Grid (and I like running it local so I can actually see it run).
I've run into this enough times that I'm pretty desperate for any solution...whether that means changing something in my code, firefox settings, some files in the firefox folder, or even some AutoHotKey script (which I've considered, but don't know how it would work).
Thank you!
This solution you mentioned seems to work well for me even with the newest Firefox 22.
The omni.ja file is the one you want to unpack. It is a regular zip file.
Inside it:
Simply unpack, change the file, repack, save. Worked for me.
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
I'm using selenium rc to do functional website testing and I've recently experienced a mysterious issue with safari and opera.
When a test fails I make a screenshot using the captureEntirePageScreenshotToString command as well as retrieving the html source.
Sometimes however this fails with a FileNotFoundException:
java.io.FileNotFoundException: C:\DOKUME~1\selenium\LOKALE~1\Temp\customProfileDir8aa20800ab1a46dbb3ef71d4d2d31b77\screenshots\page-screenshot-8aa20800ab1a46dbb3ef71d4d2d31b77.png
Is this a selenium bug? How can I workaround this issue?
I'm using selenium rc standalone 2.0a4.
thanks,
hans
So I've been using the 'captureScreenshotToString' method which is a little different, but still provides the means to get a screenshot from a remote selenium instance.
The large different/problem with this approach is that it requires the selenium server to be an unlocked windows session so it can access the display buffer to get at the physical screen. This has created problems with my headless selenium-grid machines, that I remote desktop into to administrate/troubleshoot.
In order to workaround that I've used an autologon script for this msdn article, and setup a task to restart the computer after a remote desktop session ends.
To setup Auto-Restart after remote desktop disconnect:
Open up the task scheduler
Create a new task (Create task...)
Set the name of the task to be 'Auto-Restart after remote desktop disconnect'
In the General tab, change the user to NT AUTHORITY\SYSTEM
Change to the Triggers tab, click New... to create a new trigger
Set the Begin the task to 'On disconnect from user session'
By default, it will be for any user, and from remote computers, which is exactly what we are looking for.
Change to the Actions tab, click New... to create a new action
Select the action to be Start a program. Set the program to be 'C:\Windows\System32\shutdown.exe', and then add '/r /f /t 5' (Restart, Force quit applications, wait 5 seconds to restart).
Fair warning, this is not the most secure way to have a computer sitting around
I suggest you use the Apache Commons FileUtils function makeDirs() to create all the parent directories of the directory where the png image will be located.