John Davidson

php - Symfony(4.4) Panther Test case doesn't work on GitlabCI

0 comments
Message:


I use Panther Tests Case and PHPUnit on my symfony project for functional testing.
When I run my tests on my computer (php bin/phpunit), everything works fine. When i'm connected on my server and I run my tests, everything works fine.Chrome-driver is correctly installed on th server and i can run it with command lines.
BUT, when i push on gitlab and my CI starts, i always have the same error :
That is a screenshot from gitlab interface


My script begins with a connection to my server using SSH.So the beahviour should be the same as when i connect to my server using Putty and SSH...
The command i use on my .gitlab.ci script is 'php bin/phpunit'. The same that i use locally.


I've found some posts speaking about this problem but all on Selenium and nothing for panther... Please help ! :)



My Answer:
Below is an example of a Symfony Panther test case in PHP:

php
use Symfony\Component\Panther\PantherTestCase;

class MyPantherTest extends PantherTestCase
{
public function testLoginPage()
{
$client = static::createPantherClient();
$client->request('GET', '/login');

$this->assertSelectorTextContains('h1', 'Login');
}

public function testLoginForm()
{
$client = static::createPantherClient();
$client->request('GET', '/login');

$client->submitForm('Login', [
'username' => 'testuser',
'password' => 'password123',
]);

$this->assertSelectorTextContains('.alert-success', 'Login successful');
}
}


In this test case, we have two test methods: `testLoginPage` and `testLoginForm`. The `testLoginPage` method tests if the login page contains the heading "Login", while the `testLoginForm` method tests if the login form submits successfully with valid credentials.

To run these test cases, you can use the following command:


php bin/phpunit tests/MyPantherTest.php


Make sure to have Symfony Panther installed and configured in your Symfony project before running these test cases.

Rate this post

4 of 5 based on 1107 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us