Ok so the solution for me was to add ->pause(3000) to each stage of selecting or typing, but also when navigating to give it some time.
Dusk not typing or check
Hi. I'm struggling to get the dusk testing working correctly. I've tried multiple ways to check the checkboxes, via check, click and adding value etc. but none of the methods have worked.
The first few tests are working fine with exactly the same code, but as soon as i try this code it fails. Ive taken screenshots and they show that its all in the correct place. I've rejigged the css to make sure no elements are obstucting it, and I've removed all js and other scripts to test to make sure that isnt causing an issue and I still get the same.
I have this dusk test:
#[Test]
public function check_customers_junk_filter_test(): void
{
$this->browse(function (Browser $browser) {
$browser->scrollIntoView('@junkFilter')
->assertVisible('@filterMagazines')
->check('@filterMagazines') // Checkbox
->check('@filterCatalogues') // Checkbox
->click('@saveJunkMailButton')
->screenshot('after-save')
->assertChecked('@filterMagazines')
->assertChecked('@filterCatalogues')
->uncheck('@filterMagazines') // Checkbox
->uncheck('@filterCatalogues') // Checkbox
->click('@saveJunkMailButton')
->assertNotChecked('@filterMagazines')
->assertNotChecked('@filterCatalogues');
});
}
#[Test]
public function check_customers_user_names_test(): void
{
$user = $this->getTestUser();
$this->browse(function (Browser $browser) use ($user) {
$user1 = $user->verified_users->name1;
$user2 = $user->verified_users->name2;
$user3 = $user->verified_users->name3;
$user4 = $user->verified_users->name4;
$user5 = $user->verified_users->name5;
$redirection = $user->forwarding->redirection;
$redirection_2 = $user->forwarding->redirection_2;
$browser->click('@userNamesNavLink')
->assertVisible('@userNamesSection')
->assertInputValue('@name1Input', $user1)
->assertInputValue('@name2Input', $user2)
->assertInputValue('@name3Input', $user3)
->assertInputValue('@name4Input', $user4)
->assertInputValue('@name5Input', $user5)
->assertInputValue('@redirectionInput', $redirection)
->assertInputValue('@redirection2Input', $redirection_2)
->type('redirection', '0123456789')
->type('@redirection2Input', '0123456789')
->press('@saveUserNamesButton')
->screenshot('after-save-usernmaes')
->assertInputValue('@redirectionInput', '0123456789')
->assertInputValue('@redirection2Input', '0123456789')
->type('@redirectionInput', $redirection)
->type('@redirection2Input', $redirection_2)
->press('@saveUserNamesButton')
->assertInputValue('@redirectionInput', $redirection)
->assertInputValue('@redirection2Input', $redirection_2);
});
}
The blade view (there is components, and if I inspect the inputs, the dusk attribute is there and correct):
<form action="{{ route('customer.save-junk-filter') }}" id="junk-filter" class="scroll-m-36 " role="form" method="POST"
dusk="junkMailSection">
@csrf
<div class="mt-10">
<h1 class="text-3xl font-light text-red-800">
Junk mail filters
</h1>
</div>
<div class="mt-5">
<x-forms.checkbox label="Filter magazines to treat magazines as junk mail" name="filter_magazines"
:value="Auth::user()->settings->filter_magazines" dusk="filterMagazines" />
</div>
<div class="">
<x-forms.checkbox label="Filter catalogues to treat catalogues as junk mail" name="filter_catalogues"
:value="Auth::user()->settings->filter_catalogues" dusk="filterCatalogues" />
</div>
<x-forms.form-button label="Save changes" dusk="saveJunkMail" />
</form>
When I run the test, i get:
FAIL Tests\Browser\FrontendTest
✓ customer can login test 12.65s
✓ check customers mail values test 0.40s
✓ check customers account values test 0.07s
✓ check customers contact details test 0.33s
⨯ check customers junk filter test 0.66s
⨯ check customers user names test 1.13s
───────────────────────────────────────────────
FAILED Tests\Browser\FrontendTest > check customers junk filter test
Expected checkbox [@filterMagazines] to be checked, but it wasn't.
Failed asserting that false is true.
at tests/Browser/FrontendTest.php:92
88▕ ->check('@filterMagazines')
89▕ ->check('@filterCatalogues')
90▕ ->click('@saveJunkMailButton')
91▕ ->screenshot('after-save')
➜ 92▕ ->assertChecked('@filterMagazines')
93▕ ->assertChecked('@filterCatalogues')
94▕ ->click('@filterMagazines')
95▕ ->click('@filterCatalogues')
96▕ ->click('@saveJunkMailButton')
1 tests/Browser/FrontendTest.php:85
───────────────────────────────────────────────
FAILED Tests\Browser\FrontendTest > check customers user names test
Expected value [0123456789] for the [@redirectionInput] input does not equal the actual value [].
Failed asserting that two strings are equal.
-'0123456789'
+''
at tests/Browser/FrontendTest.php:129
125▕ ->type('redirection', '0123456789')
126▕ ->type('@redirection2Input', '0123456789')
127▕ ->press('@saveUserNamesButton')
128▕ ->screenshot('after-save-usernmaes')
➜ 129▕ ->assertInputValue('@redirectionInput', '0123456789')
130▕ ->assertInputValue('@redirection2Input', '0123456789')
131▕ ->type('@redirectionInput', $redirection)
132▕ ->type('@redirection2Input', $redirection_2)
133▕ ->press('@saveUserNamesButton')
1 tests/Browser/FrontendTest.php:107
Tests: 2 failed, 4 passed (29 assertions)
Duration: 15.39s
Any ideas?
Many thanks
Sorry I spoke to soon, but I did figure out what was going on...
When running the test with the --browse flag it was popping up with the "Change password" message in the browser which then stopped any input. It didn't show up on any screenshots when debugging when not using the --browser flag...
For anyone else hitting this issue. Heres what i done in the DuskTestCase.php file. It only needs the --incognito mode i think, but i threw the kitchen sink at it just in case :
protected function driver()
{
$options = new ChromeOptions();
$arguments = collect([
$this->shouldStartMaximized() ? '--start-maximized' : '--window-size=1920,1080',
'--disable-search-engine-choice-screen',
'--no-default-browser-check',
'--incognito',
'--no-first-run',
'--disable-default-apps',
'--disable-extensions',
'--disable-plugins',
'--disable-popup-blocking',
'--disable-notifications',
'--disable-translate',
'--disable-background-networking',
'--disable-component-update',
'--safebrowsing-disable-download-protection',
'--disable-client-side-phishing-detection',
'--disable-features=PasswordChangeDetection,PasswordCheck,SafeBrowsingEnhancedProtection',
'--ignore-certificate-errors',
'--ignore-ssl-errors',
'--disable-automation',
'--disable-blink-features=AutomationControlled',
])->unless($this->hasHeadlessDisabled(), function ($items) {
return $items->merge([
'--disable-gpu',
'--headless=new',
]);
})->all();
$options->addArguments($arguments);
$options->setExperimentalOption('prefs', [
'credentials_enable_service' => false,
'profile.password_manager_enabled' => false,
'profile.default_content_setting_values.notifications' => 2,
]);
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
return RemoteWebDriver::create(
'http://localhost:9515', // Default address for Chromedriver
$capabilities
);
}
Please or to participate in this conversation.