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

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.

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.)

Nightwatch switchWindow() not working in Google Chrome

I have a test that cause a new window to open that contains a form to fill out. In FireFox it works to switch to this window using browser.switchWindow(windowName), but in Chrome it does not seem to switch to the window as it is then unable to find the form to fill out in the new window.
Anyone run into anything like this and have a possible solution? Thanks!
Edit:
This is a small code snippet I found showing what I did.
browser
.click('selector') // Button click to open new window
.pause(1000)
.switchWindow('newWindowID')
I got it to work, for me it was as simple as putting a short pause() before trying to switchWindow(). It seems it tried to switch to the new window before it actually opened.
I can't leave a comment because of not a high enough reputation, but I was wondering if you could show your code for the solution to this. I am trying to figure out how to get this same scenario to work, and am stumped. Thanks
if it is not working for some of you, specially in mac machine then try below thing :
Starting with version 75, Chromedriver has W3C Webdriver protocol enabled by default. If you'd like to stick to the JSONWire for now adjust the chromeOptions:
chromeOptions: {
w3c: false
}
into nightwatch.json file

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 a way to NOT open a new window every time I click on a link on Chrome, using watir-webdriver

I am trying to using Google Chrome to automate my testing of a mobile app developed in JavaScript for iPhone, and since it is Webkit based only Safari and Google Chrome can render the content, so I have no other option then to use watir-webdriver.
I have done a lot of research in trying to find a solution to automate on Google Chrome and the closest I could get is with Watir-WebDriver.
I have the following code:
require "rubygems"
require "watir-webdriver"
browser = Watir::Browser.new(:chrome)
website = "http://xxx.yyy.zzz"
browser.goto(website)
browser.link(:xpath,"/html/body/div/ul/li/a").click #step1
browser.link(:xpath,"/html/body/div/div[2]/div/ul/li//*[#id=btn_WEBURL]").click #step2
As soon as the #step1 is executed, the content is opened in a new browser window, which results in:
C:/Program Files/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.2/lib/watir-
webdriver/elements/element.rb:241:in `assert_exists': unable to locate element,
using {:xpath=>"/html/body/div/div[2]/div/ul/li//*[#id=btn_WEBURL]", :tag_name=>
"a"} (Watir::Exception::UnknownObjectException)
from C:/Program Files/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.2
.2/lib/watir-webdriver/elements/element.rb:69:in `click'
from ft.rb:13
Is there a way to NOT open a new window every time I click on a link on Chrome, using watir-webdriver. Or any other solution to my problem.
Thanks
You can locate and use the other window:
browser.window(:title => "your popup window").use do
browser.button(:id => "close").click
end
see more examples: https://github.com/jarib/watirspec/blob/watir2/window_switching_spec.rb

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.