App open opening multiple window in sikuli - sikuli

Hello guys I loved this sikuli but I found one issue related to app.open as well as app.focus
Here is my code my code has single line to test wheater app.open or focus open single instance
App.open("C:\\program file\internet explorer\\iexplore.exe")
Or
App.focus("C:\\program file\internet explorer\\iexplore.exe")
Both app.open and app.focus open explorer multiple time for eg:- suppose not any explorer open on first app.open or focus it open explorer now re run code the it again open explorer i.e now I have explorer instance
Expected to check if multiple explorer instance is open then close all and open single instance and if single open then just focus it is there any other alternative

Try this code below. I got this to work. So, basically, we are checking if the app window exists and if it does, close it. Else, it will ofcourse break from the loop.
Check the below link for the exact explanation on how window command works:
https://sikulix-2014.readthedocs.io/en/latest/appclass.html#window
myApp = App("Notepad.exe")
while(myApp.window() is not None):
myApp.close()
myApp = App("Notepad.exe")

Related

Chrome external application launch links

In Google Chrome, I can type the following in a new browser:
pycharm://open?file=file_name
and press Enter. The result is that PyCharm IDE will launch and open the specified file. I have also come across similar links that launch other applications.
I tried to look for information about such links but did not reach any conclusions. Specifically, I would like to know:
what is the name of such a link?
who defines those links? Since I cannot find any documentation about those links on PyCharm's side, I am led to think that those links are some form of standard command that work for every external application?
how do those links work under the hood? Is it the browser spawning a new subprocess or does the browser somehow communicate the command to the OS which takes it from there?
I can also do the above programmatically:
window.open('pycharm://open?file=file_name', '_top');
How can I ensure that the focus switches to the target application? (Right now the application does indeed start, but the focus stays on Chrome.)

Open HTML file in non-default browser

I know how to do that manually. But, is there an option to set up one particular file to be opened always in Chrome, despite Firefox being the default browser.
What I want is to set up somehow, one HTML file on my desktop to be opened in Chrome, but the rest of the html files continue to open in Firefox, and I want this to apply always for this file, even when I move it to some other computer.
I will assume we are talking about the Windows OS first. Secondly, I will assume that you do not have a Chrome shortcut sitting on your desktop, if you do have a shortcut just skip to the second step otherwise continue reading on.
Step 1: Create a Chrome Shortcut
There are many ways of doing this. Simplest one is to just search for Chrome in the Start Menu and drag the shortcut to your desktop like I have in the picture below.
Step 2: Open the Shortcut Properties
Right click on your Chrome shortcut and click the Properties option, like in the image below.
Step 3: Edit Your Shortcut's Target Value
Find the Target option in the Shortcut tab of the Properties window. Add the following piece of code at the end of your target statement.
--app=https://example.com
Replace https://example.com with any website you like. In the image below the highlighted part shows where you have to edit the target value. I have made a shortcut for https://google.com.
Hope this helps!
Note: This is a Chrome specific trick and it will open a new window without a URL bar or a toolbar.
Edit: Added pictures with more description.
You can right click on the html file then got to open with and it should display the available browsers select the one you would like to open the file with
You should be able to set it to open (in Windows (7) ) by right-clicking on a html file, going to 'Open With' and 'Choose Default program':
on most Linux systems you should be able to right-click, go to 'Properties' and set it under 'Open With...':
also, in Google Chrome settings you should be able to set it as default:

accessing a chrome extension from outside the browser

Is it possible to access a Chrome Extension from outside the browser?
I would like to be able to run a command from my text editor (MacVim) that refreshes the page on which I am working. From reading the Chrome Extension documentation it looks like I could try something really hack-y, like opening a page that uses Chrome message passing to refresh another page, but there does not seem to be a strait-forward way to do this.
I am running Mac OS X. I've tried the shell command:
$ open <url>
But that opens a new tab every time in Chrome, so this doesn't help when I'm using the developer tools
You are right, there is no straight forward solution.
Your hacky approach is the simplest way to go. Only instead of messaging I would put a tab creation listener into background page, and when a tab with some special URL is created (http://example.com/?do=refresh) - close it and refresh the next selected tab. You will see new tab flickering, but that's as good as it gets.
You can also look into using WebSocket API, for which you would need to write a server side app (which you need to call from your editor somehow). Not sure how this all might turn out.

Is there an alternative to watir::ie.attach for watir-webdriver since attach is not supported on webdriver

I have a website which is only rendered in Webkit enabled browser (Google Chrome, Safari). I am using Google Chrome since I am on Windows 7.
I am using Watir-WebDriver to automate the same.
Issue: When I click on a button on the browser window, is launches another window and post click content is rendered in the new browser window. I need a way to be able to Identify this new browser window, in-order to be able to proceed with my testing. I have been reading on various forums, but not getting any certain answer/solution.
Q: Is there an alternative to watir::ie.attach for watir-webdriver since attach is not supported on Watir-Webdriver
Sample code:
require "rubygems"
require "watir-webdriver"
require "selenium-webdriver"
b = Watir::Browser.new(:chrome)
website = "http://xyz.com"
#a new browser is launched and the website is opened
b.goto(website)
#this opens a new browser window
b.link(:xpath,"/html/body/div/ul/li/a").click
#there is a button called "MAP" on the new browser window
b.link(:id,"btn_MAP")
#this gives an error, unknown link
"window" method is the alternative for ie.attach. Webdriver can handle the window opened by itself with window method.
b.link(:href,/server\/getPage/).click
b.window(:url,/server\/getPage/i).use do
b.link(:id,"btn_MAP").click
end
you can handle popped up windows in the window method block. If you want to keep handling popped up window, use it without block, like window(:url,/foobar/).use
see also:
http://groups.google.com/group/watir-general/browse_thread/thread/232df221602d4cfb
#Yutaka: Thanks a lot for all your help it lead me to use something like the following and it worked!
b.link(:xpath,"/html/body/div/ul/li/a").click
c = b.window(:url,"http:\/\/server\/getPage\/67\/1354")
c.use
b.link(:id,"btn_MAP").click
have you tried making the website the default homepage for the browser?
that might prevent you from having to do an attach.

Creating Chrome popup with a C++ program

Problem context:
I have a C++ program and a web presence. Currently the way things are working I have made a control panel with javascript and html. And it send commands via an unimportant communication medium to control things or get information from the C++ program.
Now, when the C++ program launches, I'm making it run a
ShellExecute(NULL, "open", addressBuffer," --new-window", NULL, SW_NORMAL);
This is a way of launching the default browser with the given address. The addressBuffer in this case points to an intermediate HTML file that quickly turns around and uses the
window.open()
in Javascript to open the final popup, then closes itself.
The result is the user now has the popup control panel that I want them to have but the user's main browser window also gets given focus, un-minimized, and placed on a different tab than the one they had selected. (Basically pops up out of nowhere and selects a another tab)
Problem:
I'm looking for a way to launch a Chrome popup, without disturbing a previously open browser window. Any ideas or solutions would be very helpful.
Lastly, it's worth noting that the " --new-window" from the code above doesn't actually open a new window like you would expect. In this case it's actually doing nothing... If it did work, none of this would really be an issue.
I know this is wordy so thanks in advance for you time!
-Michael
Alright, I came up with a solution.
Something about how ShellExecute processes it's commands was preventing the command line args to be passed in correctly.
My work-around includes grabbing the path to Chrome from the registry,
HKET_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe
Then simply doing a system() command with the chrome path "--new-window" and the web path.
Then I let the intermediate html page open it's popup and close itself.
Tada done.
Thanks.