|
1 | | - |
2 | | ---- |
| 1 | +# Run Selenium Tests With Laravel On LambdaTest |
3 | 2 |
|
4 | | -# PHP Laravel Dusk todo |
5 | | -A Sample PHP-Laravel app to run selenium automation tests on LambdaTest grid. |
| 3 | + |
6 | 4 |
|
7 | | -### Prerequisites |
8 | | -- Install php and composer on your system. Setup Instructions for the same can be found [here](https://www.lambdatest.com/support/docs/display/TD/Quick+Guide+To+Run+PHP+Tests+on+LambdaTest+Selenium+Grid) |
| 5 | +<p align="center"> |
| 6 | + <a href="https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=php-laravel-dusk-todo" target="_bank">Blog</a> |
| 7 | + ⋅ |
| 8 | + <a href="https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=php-laravel-dusk-todo" target="_bank">Docs</a> |
| 9 | + ⋅ |
| 10 | + <a href="https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=php-laravel-dusk-todo" target="_bank">Learning Hub</a> |
| 11 | + ⋅ |
| 12 | + <a href="https://www.lambdatest.com/newsletter/?utm_source=github&utm_medium=repo&utm_campaign=php-laravel-dusk-todo" target="_bank">Newsletter</a> |
| 13 | + ⋅ |
| 14 | + <a href="https://www.lambdatest.com/certifications/?utm_source=github&utm_medium=repo&utm_campaign=php-laravel-dusk-todo" target="_bank">Certifications</a> |
| 15 | + ⋅ |
| 16 | + <a href="https://www.youtube.com/c/LambdaTest" target="_bank">YouTube</a> |
| 17 | +</p> |
| 18 | +  |
| 19 | +  |
| 20 | +  |
| 21 | + |
| 22 | +*Learn how to use Laravel framework to configure and run your PHP automation scripts on the LambdaTest platform* |
| 23 | + |
| 24 | +[<img height="58" width="200" src="https://user-images.githubusercontent.com/70570645/171866795-52c11b49-0728-4229-b073-4b704209ddde.png">](https://accounts.lambdatest.com/register) |
| 25 | + |
| 26 | +## Table Of Contents |
| 27 | + |
| 28 | +* [Pre-requisites](#pre-requisites) |
| 29 | +* [Run Your First Test](#run-your-first-test) |
| 30 | +* [Local Testing With Laravel](#testing-locally-hosted-or-privately-hosted-projects) |
| 31 | + |
| 32 | + |
| 33 | +## Prerequisites |
| 34 | + |
| 35 | +Before you begin automation testing with Laravel Dusk, you would need to: |
| 36 | + |
| 37 | +* Download **PHP v7.1**. You can download and install **PHP** using following commands in the terminal: |
| 38 | + |
| 39 | + * **MacOS:** Previous versions of **MacOS** have **PHP** installed by default. But for the latest **MacOS** versions starting with **Monterey**, **PHP** has to be downloaded and installed manually by using below commands: |
| 40 | + ```bash |
| 41 | + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
| 42 | + brew install php |
| 43 | + ``` |
| 44 | + * **Windows:** |
| 45 | + ```bash |
| 46 | + sudo apt-get install curl libcurl3 libcurl3-dev php |
| 47 | + ``` |
| 48 | + **Note:** For **Windows**, you can download **PHP** from [here](http://windows.php.net/download/). Also, refer to this [documentation](http://php.net/manual/en/install.windows.php) for ensuring the accessibility of PHP through Command Prompt(cmd). |
| 49 | + |
| 50 | + You can change the **PHP** version to **7.1** by using below homebrew commands in the terminal: |
| 51 | + ```bash |
| 52 | + brew unlink php && brew link --force php@7.1 |
| 53 | + ``` |
| 54 | + **Note:** You need to download **PHP v7.1** inorder to link to that version. |
| 55 | + |
| 56 | +* Download **composer** in the project directory ([Linux/MacOS](https://getcomposer.org/download/), [Windows](https://getcomposer.org/doc/00-intro.md#installation-windows)). |
| 57 | + |
| 58 | + **Note:** To use the **composer** command directly, it either should have been downloaded in the project directory or should be accessible globally which can be done by the command below: |
| 59 | + |
| 60 | + ```bash |
| 61 | + mv composer.phar /usr/local/bin/composer |
| 62 | + ``` |
| 63 | + |
| 64 | +### Installing Selenium Dependencies And Tutorial Repo |
| 65 | + |
| 66 | +**Step 1:** Clone the LambdaTest’s php-laravel-dusk-todo and navigate to the code directory as shown below: |
9 | 67 |
|
10 | | -### Installation |
11 | 68 | ```bash
|
12 | | -# setup project dependencies |
| 69 | +git clone https://github.com/LambdaTest/php-laravel-dusk-todo |
| 70 | +cd php-laravel-dusk-todo |
| 71 | +``` |
| 72 | +**Step 2:** Install the composer dependencies in the current project directory using the commands below: |
| 73 | +```bash |
13 | 74 | composer install
|
14 | 75 | composer dump-autoload
|
15 | 76 | ```
|
| 77 | +### Setting Up Your Authentication |
| 78 | + |
| 79 | +Make sure you have your LambdaTest credentials with you to run test automation scripts on LambdaTest Selenium Grid. You can obtain these credentials from the [LambdaTest Automation Dashboard](https://automation.lambdatest.com/build) or through [LambdaTest Profile](https://accounts.lambdatest.com/login). |
| 80 | + |
| 81 | +**Step 3:** Create .env from example file |
| 82 | +```bash |
| 83 | +cp .env.example .env |
| 84 | +``` |
| 85 | + |
| 86 | +**Step 4:** You would have to update your LambdaTest credentials in the newly created .env file. |
| 87 | + |
| 88 | +```bash |
| 89 | +LT_USERNAME="<Your_Username>" |
| 90 | +LT_ACCESS_KEY="<Your_Access_Key" |
| 91 | +``` |
| 92 | + |
| 93 | +**Step 5:** Set LambdaTest `Username` and `Access Key` in environment variables. |
| 94 | + |
| 95 | + * For **Linux/macOS**: |
| 96 | + ```bash |
| 97 | + export LT_USERNAME="YOUR_USERNAME" export LT_ACCESS_KEY="YOUR ACCESS KEY" |
| 98 | + ``` |
| 99 | + * For **Windows**: |
| 100 | + ```bash |
| 101 | + set LT_USERNAME="YOUR_USERNAME" set LT_ACCESS_KEY="YOUR ACCESS KEY" |
| 102 | + ``` |
| 103 | + |
| 104 | +## Run Your First Test |
| 105 | + |
| 106 | +>**Test Scenario**: The sample TodoTest.php file tests a sample to-do list app by marking couple items as done, adding a new item to the list and finally displaying the count of pending items as output. |
| 107 | + |
| 108 | + |
| 109 | +**Step 6:** In [DuskTestCase.php](https://github.com/LambdaTest/php-laravel-dusk-todo/blob/master/tests/DuskTestCase.php), we are passing browser, browser version, and operating system information, along with LambdaTest Selenium grid capabilities via capabilities object. Update platform configuration in driver method of `tests/DuskTestCase.php`, to specify the target where tests should run. The capabilities object in the above code are defined as: |
| 110 | + |
| 111 | +You can generate capabilities for your test requirements with the help of our inbuilt [Desired Capability Generator](https://www.lambdatest.com/capabilities-generator/). |
| 112 | + |
| 113 | +### Executing The Test |
| 114 | + |
| 115 | +**Step 7**: The tests can be executed in the terminal using the following command: |
16 | 116 |
|
17 | | -### Configuration steps |
18 | | -- Create `.env` from example file |
19 | | - ```bash |
20 | | - cp .env.example .env |
21 | | - ``` |
22 | | -- Replace `LT_USERNAME` with your LambdaTest username. It can be obtained from [LambdaTest dashbaord](https://automation.lambdatest.com/) |
23 | | -- Replace `LT_ACCESS_KEY` with your access key. It can be generated from [LambdaTest dashbaord](https://automation.lambdatest.com/) |
24 | | -- Update platform configuration in driver method of `tests/DuskTestCase.php`, to specify the target where tests should run. (List of supported OS platfrom, Browser, resolutions can be found at [LambdaTest capability generator](https://www.lambdatest.com/capabilities-generator/)) |
25 | | - Sample configuration |
26 | | - ```php |
27 | | - return RemoteWebDriver::create($url, |
28 | | - DesiredCapabilities::chrome() |
29 | | - ->setCapability("platform", "win10") |
30 | | - ->setCapability("browserName", "chrome") |
31 | | - ->setCapability("version", "71.0") |
32 | | - ->setCapability("resolution", "1024x768") |
33 | | - ->setCapability("build", "LaravelDusk Build") |
34 | | - ->setCapability("name", "LaravelDusk Test") |
35 | | - ->setCapability("network", true) |
36 | | - ->setCapability("video", true) |
37 | | - ->setCapability("visual", true) |
38 | | - ->setCapability("console", true) |
39 | | - ->setCapability("tunnel", false) |
40 | | - ); |
41 | | - ``` |
42 | | - |
43 | | - |
44 | | - |
45 | | -### Routing traffic through your local machine |
46 | | -- Set tunnel value to `true` in test capabilities (found in driver method of `tests/DuskTestCase.php`). |
47 | | - |
48 | | - e.g: |
49 | | - ```php |
50 | | - return RemoteWebDriver::create($url, |
51 | | - DesiredCapabilities::chrome() |
52 | | - ->setCapability("platform", "win10") |
53 | | - ->setCapability("browserName", "chrome") |
54 | | - ->setCapability("version", "71.0") |
55 | | - ->setCapability("resolution", "1024x768") |
56 | | - ->setCapability("build", "LaravelDusk Build") |
57 | | - ->setCapability("name", "LaravelDusk Test") |
58 | | - ->setCapability("network", true) |
59 | | - ->setCapability("video", true) |
60 | | - ->setCapability("visual", true) |
61 | | - ->setCapability("console", true) |
62 | | - ->setCapability("tunnel", true) |
63 | | - ); |
64 | | - ``` |
65 | | -> OS specific instructions to download and setup tunnel binary can be found at the following links. |
66 | | -> - [Windows](https://www.lambdatest.com/support/docs/display/TD/Local+Testing+For+Windows) |
67 | | -> - [Mac](https://www.lambdatest.com/support/docs/display/TD/Local+Testing+For+MacOS) |
68 | | -> - [Linux](https://www.lambdatest.com/support/docs/display/TD/Local+Testing+For+Linux) |
69 | | - |
70 | | -### Run tests |
71 | 117 | ```bash
|
72 | 118 | php artisan dusk
|
73 | 119 | ```
|
74 | 120 |
|
75 | | -### Generate test cases |
76 | | -- Change directory to project root `cd /your/project` |
77 | | -- Execute `php artisan dusk:make {test case name}` |
78 | | - e.g: |
79 | | - ```bash |
80 | | - php artisan dusk:make TodoTest |
81 | | - ``` |
82 | | -### Note |
83 | | -Our sample test case can be found in `tests/Browser/TodoTest.php` file. It navigates to our sample to-do app. |
84 | 121 |
|
| 122 | +### Generate Test Cases |
| 123 | + |
| 124 | +* Change directory to the project root: `cd /your/project` |
| 125 | + |
| 126 | +* To generate the test cases, you need to execute the following command: |
| 127 | +* |
| 128 | + `php artisan dusk:make {test case name}`. |
| 129 | + |
| 130 | + An example for the same is shown below: |
| 131 | + |
| 132 | + ```bash |
| 133 | + php artisan dusk:make TodoTest |
| 134 | + ``` |
| 135 | + |
| 136 | +Our sample test case can be found in [TodoTest.php](https://github.com/LambdaTest/php-laravel-dusk-todo/blob/master/tests/Browser/TodoTest.php) file. |
| 137 | + |
| 138 | +## Testing Locally Hosted Or Privately Hosted Projects |
| 139 | + |
| 140 | +You can test your locally hosted or privately hosted projects with LambdaTest Selenium grid using LambdaTest Tunnel. All you would have to do is set up an SSH tunnel using tunnel and pass toggle `tunnel = True` via desired capabilities. LambdaTest Tunnel establishes a secure SSH protocol based tunnel that allows you in testing your locally hosted or privately hosted pages, even before they are live. |
| 141 | + |
| 142 | +Refer our [LambdaTest Tunnel documentation](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) for more information. |
| 143 | + |
| 144 | +Here’s how you can establish LambdaTest Tunnel. |
| 145 | + |
| 146 | +Download the binary file of: |
| 147 | +* [LambdaTest Tunnel for Windows](https://downloads.lambdatest.com/tunnel/v3/windows/64bit/LT_Windows.zip) |
| 148 | +* [LambdaTest Tunnel for macOS](https://downloads.lambdatest.com/tunnel/v3/mac/64bit/LT_Mac.zip) |
| 149 | +* [LambdaTest Tunnel for Linux](https://downloads.lambdatest.com/tunnel/v3/linux/64bit/LT_Linux.zip) |
| 150 | + |
| 151 | +Open command prompt and navigate to the binary folder. |
| 152 | + |
| 153 | +Run the following command: |
| 154 | + |
| 155 | +```bash |
| 156 | +LT -user {user’s login email} -key {user’s access key} |
| 157 | +``` |
| 158 | +So if your user name is lambdatest@example.com and key is 123456, the command would be: |
| 159 | + |
| 160 | +```bash |
| 161 | +LT -user lambdatest@example.com -key 123456 |
| 162 | +``` |
| 163 | +Once you are able to connect **LambdaTest Tunnel** successfully, you would just have to pass on tunnel capabilities in the code shown below : |
| 164 | + |
| 165 | +**Tunnel Capability** |
| 166 | + |
| 167 | +```java |
| 168 | +DesiredCapabilities capabilities = new DesiredCapabilities(); |
| 169 | + capabilities.setCapability("tunnel", true); |
| 170 | +``` |
| 171 | + |
| 172 | +## Documentation & Resources :books: |
| 173 | + |
| 174 | + |
| 175 | +Visit the following links to learn more about LambdaTest's features, setup and tutorials around test automation, mobile app testing, responsive testing, and manual testing. |
| 176 | + |
| 177 | +* [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=php-laravel-dusk-todo) |
| 178 | +* [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=php-laravel-dusk-todo) |
| 179 | +* [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=php-laravel-dusk-todo) |
| 180 | + |
| 181 | +## LambdaTest Community :busts_in_silhouette: |
| 182 | + |
| 183 | +The [LambdaTest Community](https://community.lambdatest.com/) allows people to interact with tech enthusiasts. Connect, ask questions, and learn from tech-savvy people. Discuss best practises in web development, testing, and DevOps with professionals from across the globe 🌎 |
| 184 | + |
| 185 | +## What's New At LambdaTest ❓ |
| 186 | + |
| 187 | +To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/) |
| 188 | + |
85 | 189 | ## About LambdaTest
|
86 | | -[LambdaTest](https://www.lambdatest.com/) is a cloud based selenium grid infrastructure that can help you run automated cross browser compatibility tests on 2000+ different browser and operating system environments. LambdaTest supports all programming languages and frameworks that are supported with Selenium, and have easy integrations with all popular CI/CD platforms. It's a perfect solution to bring your [selenium automation testing](https://www.lambdatest.com/selenium-automation) to cloud based infrastructure that not only helps you increase your test coverage over multiple desktop and mobile browsers, but also allows you to cut down your test execution time by running tests on parallel. |
| 190 | + |
| 191 | +[LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=php-laravel-dusk-todo) is a leading test execution and orchestration platform that is fast, reliable, scalable, and secure. It allows users to run both manual and automated testing of web and mobile apps across 3000+ different browsers, operating systems, and real device combinations. Using LambdaTest, businesses can ensure quicker developer feedback and hence achieve faster go to market. Over 500 enterprises and 1 Million + users across 130+ countries rely on LambdaTest for their testing needs. |
| 192 | + |
| 193 | +### Features |
| 194 | + |
| 195 | +* Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments. |
| 196 | +* Real-time cross browser testing on 3000+ environments. |
| 197 | +* Test on Real device cloud |
| 198 | +* Blazing fast test automation with HyperExecute |
| 199 | +* Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale. |
| 200 | +* Smart Visual Regression Testing on cloud |
| 201 | +* 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more. |
| 202 | +* Automated Screenshot testing across multiple browsers in a single click. |
| 203 | +* Local testing of web and mobile apps. |
| 204 | +* Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems. |
| 205 | +* Geolocation testing of web and mobile apps across 53+ countries. |
| 206 | +* LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports |
| 207 | + |
| 208 | + |
| 209 | +[<img height="58" width="200" src="https://user-images.githubusercontent.com/70570645/171866795-52c11b49-0728-4229-b073-4b704209ddde.png">](https://accounts.lambdatest.com/register) |
| 210 | + |
| 211 | +## We are here to help you :headphones: |
| 212 | + |
| 213 | +* Got a query? we are available 24x7 to help. [Contact Us](support@lambdatest.com) |
| 214 | +* For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=php-laravel-dusk-todo) |
0 commit comments