Launch different tabs on the browser

24 views
Skip to first unread message

Sushant Mamgain

unread,
Jul 15, 2015, 2:45:59 AM7/15/15
to caius...@googlegroups.com
Hi ,

I was just wondering that, can I launch multiple tabs in a window via web-driver?
What i found it just a workaround of sending <Control + t> via send_keys. Is their any other clean method.

After that, As I get window handle for each tab I can switch focus to any of the tab via focus command and operate on the tab. Here is the focus method i have overridden in my way.

# to get all handles of the tabs --> set lWindows [[$::IB::WEB::browser session] windows]

method focus {args} {
set options(-handle) ""
array set options $args
if { $options(-handle) eq "" } {
set json "{ \"name\": \"$_handle\" }"
set expectedHandle $_handle
} else {
set json "{ \"name\": \"$options(-handle)\" }"
set expectedHandle $options(-handle)
}
set interval 10

            for {set i 0} {$i < 5} {incr i} {
                set response [::WebDriver::Protocol::dispatch -query $json \
                    [$_session session_url]/window]
                ::itcl::delete object $response
if { [[$_session active_window] handle]  eq $expectedHandle } {
break;
}
                after $interval
                set interval [expr $interval * 2]
            }

            if {$i == 5} {
                raise ::WebDriver::UnknownError "failed to activate window."
            }
        }



Also can I launch, different windows under same session?
I think, there will be a way for that, as all I am getting all the windows handles, then I should be able to launch as well.
But didn't find a way.

Need Assistance.


Thanks,
Sushant

tobia...@gmail.com

unread,
Jul 15, 2015, 8:53:56 AM7/15/15
to caius...@googlegroups.com, sushantm...@gmail.com

I was just wondering that, can I launch multiple tabs in a window via web-driver?

No. At least not specifically. Selenium is made for testing what's inside the browser, not the browser itself. From the driver's perspective it makes absolutely no difference if the application is running in a separate window or a tab.
 
What i found it just a workaround of sending <Control + t> via send_keys. Is their any other clean method.

Not that I'm aware of.
 
After that, As I get window handle for each tab I can switch focus to any of the tab via focus command and operate on the tab. Here is the focus method i have overridden in my way.
[...]
 
There shouldn't be a need to override the focus method. Version 0.15.1 has a fix for the problem you reported before.
 
Also can I launch, different windows under same session?

You can control multiple windows in the same session. But I suppose this is for when an application itself spawns new windows or popups. There is pretty much no other way a real-world web app would require a user to manually open two windows. And the WebDriver wire protocol as it is documented does not provision for that.

However, if you insist, you can inject javascript to achieve this. See the use of window execute in this example:

package require Itcl
package require Testing
package require WebDriver

itcl::class MyTests {
    inherit Testing::TestObject

    method test_window_focus {} {
        set caps [namespace which [WebDriver::Capabilities #auto -browser_name firefox]]
        set session [WebDriver::Session #auto http://127.0.0.1:4444/wd/hub $caps]

        $session set_logging_enabled true
        set window [$session active_window]

        # Load Google in the first window...
        $window set_url http://www.google.de

        # Use Javascript to open a second window in the same session.
        $window execute {open("http://www.yahoo.de")}

        # If you examine session_windows, you will now see two entries.
        set session_windows [$session windows]

        # Switch focus back and forth between the windows.
        for {set i 0} {$i < 10} {incr i} {
            set j [expr $i % 2]
            [lindex $session_windows $j] focus
            after 1000
        }

        ::itcl::delete object $session
    }
}

exit [[MyTests #auto] run $::argv]

Tobias

Sushant Mamgain

unread,
Jul 16, 2015, 12:28:03 PM7/16/15
to caius...@googlegroups.com
Hi,

FYI, 

There is an option of selenium grid for working parallel in different browsers. That's what I was thinking of launching multiple browsers and then testing parallel way.
(cross-browser, cross-platform and parallel testing)
I don't know it could be tied and harnessed with TCL. 

~Sushant
Reply all
Reply to author
Forward
0 new messages