david001's avatar

Laravel dusk coming back to original browser tab

Hi, I have situation where I need to click the link and visit new tab and see if there is that particular text or not and then come back to original tab and perform some work.

this is the code I am using to go new tab when clicking view button


  $window = collect($this->driver->getWindowHandles())->last();
            $this->driver->switchTo()->window($window);

$browser->assertSee('Drop down');

Now I have to come to original tab, How can i do that ? Any help? Thanks

come back to original tab

0 likes
7 replies
bugsysha's avatar

The way I did it before, and I don't think this part changed, was to run the test while developing it in a normal mode. So just remove the headless option from the config and watch what happens. For my test, everything was focused so I just had to close the tab/window and it would go back to the initial page and I could continue where I left. Maybe there is a better way, but I haven't used Dusk for 3 years now.

david001's avatar

@bugsysha , is there anyway(dusk code) to close the recent tab so that i can come to first tab. Thanks

bugsysha's avatar

So what do you get from $this->driver->getWindowHandles()?

david001's avatar

dd($this->driver->getWindowHandles()); returns below info

array:1 [ 0 => "CDwindow-C3CA7C376C1A9EFFD5DF8D0867B6936F" ]

bugsysha's avatar

So did you disable headless mode to see what is happening?

david001's avatar

yes it is disabled, since I am doing dd() browser opens and shut down

david001's avatar

i tried this

      $originalWindow = $this->driver->getWindowHandle();

        $this->driver->switchTo()->window($originalWindow);

but this is not working

Please or to participate in this conversation.