Michio JP

Michio JP

1547797459

All you need to know about Laravel Dusk

Time and time again the discontent grew amongst developers at being unable to test applications using the out of the box tools that Laravel provided. Developers wanted to use and test the JavaScript components found their Laravel apps.


The long-awaited solution came in the form of Laravel Dusk.

Introduction to Laravel Dusk

Laravel Dusk charts a whole new path for developers in application testing. Application testing has been completely rewritten with ChromeDriver now the base of everything. The ChromeDriver works as a standalone diver that controls the workings of Chrome. Laravel Dusk works by sending your commands to ChromeDriver as you write your application tests. The ChromeDriver then lights up Chrome in which your tests run. While your tests run in the browser Laravel Dusk reports back to you the results.

Lavarel Dusk makes automated of browser tests in your application possible. The developers of Laravel have put out a tool that has made app functionality testing and automation very easy.

So how can you take advantage of what Laravel Dusk offers?

How To Get Laravel Dusk

Get an up to date and a recent version of the Laravel Dusk via composer.

composer require –dev laravel/dusk

As a note though; never register Dusk in your production environment in the event that you carry out a manual registration of Laravel Dusk’s service provider. If you do so random users could get access to authentication via your application.

When you are done with the installation of the Dusk package run the dusk: installcommand to complete the process and then get ready to run some tests.

php artisan dusk:install

Upon the installation, there will be a Browser directory created within a testsdirectory that will contain a test example. What come next is setting up the APP_URL  environment variable in the .env  file. The value of this APP_URL should be the same as the one you will be using while accessing your app in a browser.

You have the option of having Dusk use its own environment file. You can do this by creating a .env.dusk.{environment}  file. An example of this in a local environment file would be .env.dusk.local. This comes in handy in case you don’t want to test your current database but instead want to have a test of a test database instead.

Running Tests

When running any of your tests, make use of the dusk Artisan command. The duskcommand will accept any argument accepted by the phpunit command.

php artisan dusk

This command executes the ExampleTest within the tests\Browser\ExampleTest.php.  This gives you the result as shown below:

...
public function testBasicExample()
{
//Visit the homepage and look for the text 'Laravel'
$this->browse(function (Browser $browser) {
$browser->visit('/')
->assertSee(‘Laravel’);
});
}

The results show that the test was passed displaying the result OK (1 test, 1 assertion)

Opening the file tests\Browser\ExampleTest.php will display for you the method above.

The browse method used accepts a callback that is an instance of the Browerclass. Within this callback, different methods and assertions that are unique to Dusk can be called.

Going to the visit() method allows you to run a test that visits the URL which matches with the argument specified. 

The assertSee()  method inspects to find if the text matching the argument provided appears on the page.

In the example given above a visit on the homepage is done plus a check for the appearance of the text ‘Laravel’. A look at the documentation page on laravel.com will show you that there are other assertions available that you can look into.

 

So how does a failed test look like?

Go to the argument assertSee() and replace the text ‘Laravel’ with text that does not appear on the visited page for example ‘whoa’. You will promptly get a failed test message. A screenshot of the failed test will also be available in the tests\Browser\screenshots directory.

Creating Browsers

To begin with, write a test that verifies application login. Upon generating a test, make a modification to navigate to the login page. Key in the necessary credentials and then click the ‘Login’ button.

Call on the browse method to create browser instance.

<?php

namespace Tests Browser;

use App \User;
use Tests\DuskTestCase;
use Laravel\Dusk\Chrome;
use Illuminate\Foundation\Testing\Database\Migrations;
class ExainpleTest extends DuskTestCase
{
use DatabaseMigrations;
/**

  • A basic browser test example.

  • @return void
    */
    public function testBasicExample()
    {
    $user - factory(User::class)->create{[
    ‘email’ => ‘taylor@laravel,com’,
    ]);
    $this->browse (function (browser) use ($user) {
    $browser->visit(‘/login’)
    ->type(‘email1j $user->email)
    ->type(“password”, “secret”)
    ->press (’ Login’)
    ->assertPathIs(‘/home");
    });
    }
    }

From the example showcased above, it can be seen that the browse method does accept a callback.

This callback will automatically receive a browser instance from Dusk and through this instance interactions and assertions against the application will be made.

It is worth noting also that this test also can be used to test the make:auth  Artisan command generated login screen.

Multiple Browser Creation

It sometimes becomes necessary to have multiple browsers for proper testing to be done. An example of a chat screen that interacts with WebSockets may need testing on multiple browsers.

By going to the signature of the callback provided in the browse method and using “ask” for more than one browser you will be able to create multiple browsers.

$this->-browse(function ($first, $second) {
$first->loginAs( User::find(1))
->visit{’/home’)
->waitForText (‘Message’);

$second-&gt;loginAs(User::find(2)) 
 -&gt;visit('/home') 
 -&gt;waitForText('Message')
 -&gt;type('Message', 'Hey Taylor') 
 -&gt;press('Send')

 $first-&gt;waitForText('Hey Taylor')
      -&gt;assertSee('Jeffrey Way');

});

Working with Authentication and Forms

Laravel Dusk allows you to interact with forms and authentication testing. To see this set up the basic Laravel login and registration forms. Begin by creating a database and update the .env file with information on the database. Now run.

   php artisan make:auth

This command results in the creation of migration and scaffolding files for authentication. Worth noting here is, in case you are running MYSQL that is lower than 5.7.7 or MariaDB you will have to go to the default string length in the boot method and edit the file setting app\Providers\AppServiceProvider.php

use Illuminate\Support\Facades\Schema;

public function boot()
{
Schema::defaultStringlength{l9l);
}

After this run;

php artisan migrate

This command generates database tables for you from the migration files. A visit to the homepage of your project will reveal the following along with the Login and Register Links on the far right corner.

Run the following command to create a new test named RegisterTest

   php artisan dusk:make RegisterTest

If you look at the tests\Browser folder you will see the file RegisterTest.php that will look like the snapshot below;

<?php

namespace Tests\Browser;

use Tests\DuskTestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;

class RegisterTest extends DuskTestCase
{
/**

  • A Dusk test example.

*@return void
*/
public function testExample()
{
$this->browse(function (Jbrowser) {
$browser->visit(‘/’)
->assertSee(‘Laravel’);
});
}
}

Make changes to the testExample() method so that it looks similar to the image below;

public function testExample()
{
$this->browse(function ($browser) {
$browser->visit(‘/’) //Go to the homepage
->clickLink(‘Register’) //Click the Register link
->assertSee(‘Register’) //Hake sure the phrase in

//Fill the form with these values
->value(‘#name’,‘Joe’)
->value(‘#email’, ‘joe@example.com’)
->value(‘#password’, ‘123456’)
->value(‘#password-confirm’, ‘123456’)
->click(‘button[type=“Submit”]’) //Click the submit butt
->assertPathIs(‘/home’)//Make sure you are in the home
//Make sure you see the phrase in the argument
->assertSee(“You are logged in!”);
}>;
}

After making customizations and edits to your command you may opt to get rid of the ExampleTest.php file which you no longer need.

   php artisan dusk:make RegisterTest

Some Final Thoughts

Laravel Dusk brings efficient and easy test writing to your fingertips. We have mentioned the key aspects of Laravel Dusk that you need to know about to get started. On the other side, Laravel Dusk still has plenty to it in relation to features. We shall delve more into the other features in forthcoming articles.



#laravel-

What is GEEK

Buddha Community

Seamus  Quitzon

Seamus Quitzon

1595201363

Php how to delete multiple rows through checkbox using ajax in laravel

First thing, we will need a table and i am creating products table for this example. So run the following query to create table.

CREATE TABLE `products` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
 `description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
 `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
 `updated_at` datetime DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

Next, we will need to insert some dummy records in this table that will be deleted.

INSERT INTO `products` (`name`, `description`) VALUES

('Test product 1', 'Product description example1'),

('Test product 2', 'Product description example2'),

('Test product 3', 'Product description example3'),

('Test product 4', 'Product description example4'),

('Test product 5', 'Product description example5');

Now we are redy to create a model corresponding to this products table. Here we will create Product model. So let’s create a model file Product.php file under app directory and put the code below.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $fillable = [
        'name','description'
    ];
}

Step 2: Create Route

Now, in this second step we will create some routes to handle the request for this example. So opeen routes/web.php file and copy the routes as given below.

routes/web.php

Route::get('product', 'ProductController@index');
Route::delete('product/{id}', ['as'=>'product.destroy','uses'=>'ProductController@destroy']);
Route::delete('delete-multiple-product', ['as'=>'product.multiple-delete','uses'=>'ProductController@deleteMultiple']);

#laravel #delete multiple rows in laravel using ajax #laravel ajax delete #laravel ajax multiple checkbox delete #laravel delete multiple rows #laravel delete records using ajax #laravel multiple checkbox delete rows #laravel multiple delete

sophia tondon

sophia tondon

1618970788

Top Laravel Development Company India | Laravel Development Services

Laravel is a popular framework for website development, acquiring 25.85% of the PHP framework market share. As a most admired framework among PHP frameworks, it is being utilized for e-commerce, enterprise, social media, and various different types of websites.

There are more than 1 million websites worldwide available over the web that are created using Laravel. Laravel framework is the first preference of PHP developers as it allows them to develop highly scalable, flexible, and faster web applications.

Surely, you, too, would want to deliver a splendid and unhindered user experience to your target audience over the web. Laravel framework can help you achieve this pursuit at ease; all you need to do is hire Laravel developers from reliable & coveted hosts. But! There is no shortage of Laravel development companies that promise to deliver an excellent solution, but only some are able to deliver top-notch quality.

Therefore, I have decided to enlist top Laravel development companies to help you find a reliable and expert host for web development. So, stay hooked with me till the end of this article and explore the best Laravel developers in 2021.

While creating this list, I have kept the following pointers in reflection:

Years of excellence (average 8 years)
Workfolio
Rewards & Recognition
Client rating & feedback
Hourly/Monthly Price
Number of happy clients
Number of successfully launched projects
Minimum man-years experience
So, let’s not waste a minute and glance at top Laravel development companies to hire for creating excellent web solutions.

Read More - https://www.valuecoders.com/blog/technology-and-apps/top-laravel-development-companies-to-hire-experts/

#hire a laravel developer #hire laravel developer #hire laravel developers #laravel developer for hire #laravel developers #laravel developers for hire

sophia tondon

sophia tondon

1620977020

Hire Laravel Developers | Laravel Development Company, Services India

Looking for a team of experienced offshore Laravel developers? Hire a top dedicated team of Laravel developers from India online with 6+ years of average experience on an hourly or dedicated (monthly) basis from ValueCoders and enjoy easy hiring, quality work, and on-demand scalability at up to 60% less cost.

Our offshore Laravel development experts are fully competent to build scalable, secure, and robust custom web apps suiting your business requirements.

First Time Right Process
Complete Control Over The Team
Certified Laravel Coders
Agile & DevOps Enablement
Non-Disclosure Agreement
No Contract Lock-Ins

Visit Us- https://www.valuecoders.com/hire-developers/hire-laravel-developers

#hire a laravel developer #hire laravel developer #laravel development #hire laravel experts #find laravel developers #laravel development services india

Seamus  Quitzon

Seamus Quitzon

1595205213

How to perform migration rollback in laravel

As we know that laravel migration provides very simple way to create database table structure. We need to create migration file and write table structure then migrate that migration. Sometimes we need to rollback that migration. So here we will discuss about the migration rollback in laravel.

We can run the rollback artisan command to rollback on a particular step. We can execute the following artisan command.

php artisan migrate:rollback --step=1

Every time when we will rollback, we will get the last batch of migration.

**Note: **This rollback command will work on laravel 5.3 or above version. For the version below 5.3, there is no command available for migration rollback in laravel.

We can also use the following command to rollback and re migrate.

php artisan migrate:refresh --step=2

It will rollback and remigrate last two migration.

You can also checkout the article for executing single migration by clicking on the link below.

How to migrate single migration in laravel

#laravel #how to perform rollback migration in laravel #laravel migration rollback #migration refresh in laravel #migration rollback batch in laravel #migration rollback for one specific migration #migration rollback in laravel

Seamus  Quitzon

Seamus Quitzon

1595208840

How to Hire Laravel Developers and How Much Does It Cost.

There are many recruitment cycles to hire Laravel developers for developing your high-end applications. It is important to choose the right cycle that suits the requirements of the unique needs of your business and development. The following are some of the most commonly used recruitment methods to hire the best Laravel developers.

1. Laravel freelance developers

The Freelance Laravel developers are easily available on many different sites that can cater to your company’s requirements. If you already have a team of developers and only require a small amount of temporary work to be done. Hiring freelance Laravel developers is the best model for you.

2. Laravel Offshore Developers

When it comes to offshore Laravel developers, it is more similar to the freelance developer but with enhanced security and more trustworthy developers duly NDA signed with a legal contract.

3. Laravel in-house Developers

If you already have a team of Laravel developers and if your company needs a consistent requirement for Laravel development, it should probably hire the best in-house Laravel developer for your team which can be on a permanent or contract basis.

4. Outsource Laravel developer/team

Outsourcing is also similar to offshore development. Based on the requirement and the size of your in-house team, you can hire an offshore Laravel developer or a team.

5. Laravel Development company

If you or your company has no idea over the technical knowledge of your project development, it is the best choice to involve the technical team of experts to do the work. In that case, hiring a Laravel development company can help you with all the requirements and many added benefits comes along for a longer-term. If you are interested in ROI, hiring the best Laravel development company is everything that your business deserves.

Hourly Rate of Laravel Developer

The Laravel developer salary may differ depending on the experience of the developer, the hiring company size, the country, and many other factors. When we are talking about the national average salary of a Laravel developer, it is the approximate number taken from a number of Laravel developers across the country.

According to Payscale, the average Laravel developer salary is $64,479/ year in the United States. The highly experienced professional developer earns about $94k and freshers earn about $43k.

This means that the hourly rate of Laravel developer is about $24.09 / hour in the US. Here is the list of the national salary of Laravel developer salaries across countries. All the information below is with reference to the information given in Payscale.com.

Laravel developer Salary in India – Rs. 546,000

Laravel developer salary in Canada – $110,000

Laravel developer Salary in Germany – €46,454

Laravel developer Salary in UK – £68,000

All the details mentioned in the above table are taken from Payscale on the 27th of May, 2020.

So, it is a wise option to consider hiring the best offshore developers for your project if you are cost-effective solutions.

We, Agira technologies are a technology solution company with business services and domain solutions that support global clients who comprise the current world economy. Some of the exclusive services that we offer are web development, mobile app development, Blockchain, IoT, and DevOps Consulting.

#laravel #hire laravel developer #hire laravel developer company #hire laravel developer india #laravel developer cost #laravel developer skills