Closed guirociozanini closed 7 years ago
Try something like this instead:
// Collect all tabs and grab the last one (recently opened).
$window = collect($browser->driver->getWindowHandles())->last();
// Switch to the new tab that contains the screenshot
$browser->driver->switchTo()->window($window);
I'am getting another error now:
1) Tests\Browser\RegisterTest::testExample
Error: Call to undefined method Facebook\WebDriver\Remote\RemoteWebDriver::assertSee()
// Switch to the new tab that contains the screenshot
->driver->switchTo()->window(collect($browser->driver->getWindowHandles())->last())
->assertSee('Exportar PDF')
->clickLink('Exportar PDF');
You cannot chain that call. You need to store a reference to the browser.
How do I store the reference to the browser?
$response = $browser->visit('/')
//Espera pelo icone de acesso de prestador e clica
->waitFor('img[src="imgs/001.gif"]')
->click('img[src="imgs/001.gif"]')
//Verifica se o form de login está na tela
->assertSee('Forma Acesso')
//Verifica se o campo CNPJ está selecionado
->radio('cpf_cnpj', 'cnpj')
->assertRadioSelected('cpf_cnpj', 'cnpj')
//Preenche os campos de acesso e realiza o login
->value('#ext-gen29', 'user')
->value('#ext-gen33', 'pass')
->click('#ext-gen42')
//Espera pelo icone de consulta da nota fiscal e clica
->waitFor('img[src="imgs/icon_nfse5.gif"]')
->click("img[src='imgs/icon_nfse5.gif']")
//Verifica se o radio Periodo está selecionado
->waitFor('input[name="opcConsulta"]')
->radio('opcConsulta', 'periodo')
->assertRadioSelected('opcConsulta', 'periodo')
//Preenche os campos de data De: / Até:
->valueByPosition('div > input', 1, Carbon::now()->subMonth()->startOfMonth()->format('d/m/Y'))
->valueByPosition('div > input', 2, Carbon::now()->subMonth()->endOfMonth()->format('d/m/Y'))
->click('.x-btn-text')
//Clicar e baixar a nota
->waitFor('.viewNota', 30)
->click('.viewNota');
// Collect all tabs and grab the last one (recently opened).
$window = collect($response->driver->getWindowHandles())->last();
// Switch to the new tab that contains the screenshot
$response->driver->switchTo()->window($window);
$response->waitFor('.titulo', 10)
->click('.titulo');
I did this and worked:
->driver->switchTo()->window(collect($browser->driver->getWindowHandles())->last());
$browser
->waitFor('.titulo')
->click('.titulo')
->pause(500)
I have another doubt, is it possible to download a static page pdf? Example:
www.mywebsite.com/19208312093821.pdf
Cause when dusk presses the download button, a popup opens to click Save (ubuntu window)
I'am getting this error, i'am trying to change the tab of the page.