I'am getting this error, i'am trying to change the tab of the page.
1) Tests\Browser\RegisterTest::testExample
ErrorException: Only variables should be passed by reference
/var/www/html/dusk/tests/Browser/RegisterTest.php:59
/var/www/html/dusk/vendor/laravel/dusk/src/TestCase.php:91
/var/www/html/dusk/tests/Browser/RegisterTest.php:66
<?php
namespace Tests\Browser;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class RegisterTest extends DuskTestCase
{
/**
* A Dusk test example.
*
* @return void
*/
public function testExample()
{
$this->browse(function (Browser $browser) {
$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')
->driver->switchTo()->window(end($browser->driver->getWindowHandles()))
->waitFor('.titulo', 10)
->click('.titulo');
});
}
}
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)
Most helpful comment
Try something like this instead: