Web front-end testing - e2e testing

Development environment: macbook with node installed (windows not tested)

first step:

Create projects that you need to test, such as creating a test directory on the desktop as our project root directory.

Open sublim text and drag the item into sublim text for easy management.

Step two:

Open the terminal, enter the command cd Desktop/test to enter the project root directory, enter npm init, and press Enter all the way to generate the package.json file.

third step:

Configure the package.json file.

"e2e":"node ./e2e/index.js"

the fourth step:

Create an e2e folder under the test directory, and create an index.js file under the e2e folder.

index.js file content:

const {Builder, By, Key, until} = require('selenium-webdriver');

(async function example() {
  let driver = await new Builder().forBrowser('firefox').build();
  try {
    await driver.get('https://www.baidu.com/ 

');
    await driver.findElement(By.name 

('wd')).sendKeys('abc', Key.RETURN);
    await driver.wait(until.titleIs('abc_百度搜索'), 1000);
  } finally {
    await driver.quit();
  }
})();

the fifth step:

Install the test package required by e2e: selenium-webdriver

npm install selenium-webdriver --save-dev

Step six:

Add the driver required by the test browser, open www.npmjs.com, enter selenium-webdriver and click to open selenium-webdriver to download the instructions for use.

Select the browser driver you need to test, for example, select the first chrome, click to enter the download page

Download the driver corresponding to the system of your computer

Unzip it after downloading, and drag the decompressed small black window file to the root directory of your project.

Step seven:

Enter in the terminal: npm run e2e to test.

Precautions:

1. Install the package required for testing: selenium-webdriver

2. Index.js is written correctly.

3. Pay attention to the browser you want to test (there are many versions of chrome browser, I use ff browser for convenience)

4. Whether to enter the project directory for installation.

5. Whether the driver has been added to the project.

6. The name value of the page element to be tested, the search value, and the obtained value.

 

Guess you like

Origin blog.csdn.net/xishaoguo/article/details/82658059