# Test execution time

By default, this module will check if you have a local installation of Tesseract on your machine/in your pipeline. If you don't have a local installation it will automatically use a [NodeJS](https://github.com/naptha/tesseract.js) version. This might cause some slowness because the image processing will be done by Node.js. NodeJS is not the best system to do heavy processing.

**BUT....**, there are ways to optimize the execution time. Let's take the following test script

```
import { browser } from "@wdio/globals";



describe("Search", () => {

    it("be able to search for a value", async () => {

        await browser.url("https://webbrowser.io");

        await browser.ocrClickOnText({

            text: "Search",

        });

        await browser.ocrSetValue({

            text: "docs",

            value: "specfileretries",

        });

        await browser.ocrWaitForTextDisplayed({

            text: "specFileRetries",

        });

    });

});
```

When you execute this for the first time you might see the following results where it took 5.9 seconds to finish the test.

```
npm run wdio -- --logLevel=silent



> ocr-demo@1.0.0 wdio

> wdio run ./wdio.conf.ts --logLevel=silent





Execution of 1 workers started at 2024-05-26T04:52:53.405Z



[0-0] RUNNING in chrome - file:///test/specs/test.e2e.ts

[0-0] Estimating resolution as 182

[0-0] Estimating resolution as 124

[0-0] Estimating resolution as 126

[0-0] PASSED in chrome - file:///test/specs/test.e2e.ts



 "spec" Reporter:

------------------------------------------------------------------

[chrome 125.0.6422.78 mac #0-0] Running: chrome (v125.0.6422.78) on mac

[chrome 125.0.6422.78 mac #0-0] Session ID: d281dcdc43962b95835aea8f64cab6c7

[chrome 125.0.6422.78 mac #0-0]

[chrome 125.0.6422.78 mac #0-0] » /test/specs/test.e2e.ts

[chrome 125.0.6422.78 mac #0-0] Search

[chrome 125.0.6422.78 mac #0-0]    ✓ be able to search for a value

[chrome 125.0.6422.78 mac #0-0]

[chrome 125.0.6422.78 mac #0-0] 1 passing (5.9s)





Spec Files:      1 passed, 1 total (100% completed) in 00:00:08
```

## Cropping the search area of a screen[​](#cropping-the-search-area-of-a-screen "Direct link to Cropping the search area of a screen")

You can optimize the execution time by providing a cropped area to execute the OCR on.

If you would then change the script to this:

```
import { browser } from "@wdio/globals";



describe("Search", () => {

    it("be able to search for a value", async () => {

        await browser.url("https://webdriver.io");

        await driver.ocrClickOnText({

            haystack: $(".DocSearch"),

            text: "Search",

        });

        await driver.ocrSetValue({

            haystack: $(".DocSearch-Form"),

            text: "docs",

            value: "specfileretries",

        });

        await driver.ocrWaitForTextDisplayed({

            haystack: $(".DocSearch-Dropdown"),

            text: "specFileRetries",

        });

    });

});
```

Then you will see a different execution time.

```
npm run wdio -- --logLevel=silent



> ocr-demo@1.0.0 wdio

> wdio run ./wdio.conf.ts --logLevel=silent





Execution of 1 workers started at 2024-05-26T04:56:55.326Z



[0-0] RUNNING in chrome - file:///test/specs/test.e2e.ts

[0-0] Estimating resolution as 182

[0-0] Estimating resolution as 124

[0-0] Estimating resolution as 124

[0-0] PASSED in chrome - file:///test/specs/test.e2e.ts



 "spec" Reporter:

------------------------------------------------------------------

[chrome 125.0.6422.78 mac #0-0] Running: chrome (v125.0.6422.78) on mac

[chrome 125.0.6422.78 mac #0-0] Session ID: c6cb1843535bda3ee3af07920ce232b8

[chrome 125.0.6422.78 mac #0-0]

[chrome 125.0.6422.78 mac #0-0] » /test/specs/test.e2e.ts

[chrome 125.0.6422.78 mac #0-0] Search

[chrome 125.0.6422.78 mac #0-0]    ✓ be able to search for a value

[chrome 125.0.6422.78 mac #0-0]

[chrome 125.0.6422.78 mac #0-0] 1 passing (4.8s)





Spec Files:      1 passed, 1 total (100% completed) in 00:00:08
```

Cropping images

This reduced the local execution time from **5.9** to **4.8 seconds**. This is a reduction of almost **19%**. Imagine what it can do for a larger script with more data on it.

## Using a local installation of Tesseract[​](#using-a-local-installation-of-tesseract "Direct link to Using a local installation of Tesseract")

You can speed up your execution time to even less than a minute if you have a local installation of Tessarect on your local machine and or in your pipeline (more information about installing Tesseract on your local system can be found [here](https://tesseract-ocr.github.io/tessdoc/Installation.html)). You can find the execution time of the same script using a local installation of Tesseract below.

```
npm run wdio -- --logLevel=silent



> ocr-demo@1.0.0 wdio

> wdio run ./wdio.conf.ts --logLevel=silent





Execution of 1 workers started at 2024-05-26T04:59:11.620Z



[0-0] RUNNING in chrome - file:///test/specs/test.e2e.ts

[0-0] PASSED in chrome - file:///test/specs/test.e2e.ts



 "spec" Reporter:

------------------------------------------------------------------

[chrome 125.0.6422.78 mac #0-0] Running: chrome (v125.0.6422.78) on mac

[chrome 125.0.6422.78 mac #0-0] Session ID: 87f8c1e949e15a383b902e4d59b1f738

[chrome 125.0.6422.78 mac #0-0]

[chrome 125.0.6422.78 mac #0-0] » /test/specs/test.e2e.ts

[chrome 125.0.6422.78 mac #0-0] Search

[chrome 125.0.6422.78 mac #0-0]    ✓ be able to search for a value

[chrome 125.0.6422.78 mac #0-0]

[chrome 125.0.6422.78 mac #0-0] 1 passing (3.9s)





Spec Files:      1 passed, 1 total (100% completed) in 00:00:06
```

Local installation

This reduced the local execution time from **5.9** to **3.9 seconds**. This is a reduction of almost **34%**. Imagine what it can do for a larger script with more data on it.
