Show List

TestCafe Test to Search Text on Web Browser

Here's a sample TestCafe test script that opens search engine page, enters text in search text field and clicks on Search button:


import { Selector } from 'testcafe'; fixture('Search Test') .page('https://www.example.com'); test('Perform Search', async t => { // Selectors for the search text field and search button const searchTextField = Selector('input[type="text"]'); const searchButton = Selector('button[type="submit"]'); // Text to enter in the search text field const searchText = 'TestCafe'; // Type text into the search text field await t.typeText(searchTextField, searchText); // Click the search button await t.click(searchButton); });

In this test:

  • We import the Selector function from TestCafe, which allows us to select elements on the web page.
  • We define a fixture named 'Search Test' and set the page to 'https://www.example.com'.
  • Inside the test function, we define selectors for the search text field and search button on the page.
  • We define the text to enter in the search text field.
  • We use TestCafe's typeText action to enter the search text into the search text field.
  • We use TestCafe's click action to click the search button.

You can replace 'https://www.example.com' with the URL of the website you want to test, and adjust the selectors accordingly based on the structure of the webpage you are testing.



Next: Assertions


    Leave a Comment


  • captcha text