preface

I wrote automatic test scripts for the company’s applications every day, but I never applied these automation scripts to my life. Until I went to the community and saw that I wrote a crawler script with Node+wechaty and sent warm words to my female (male) friends on wechat every day, I found such a fun thing. So I enjoyed it and thought there was a better way to do it.

The above script also carries on the scan code login operation, for often write automatic script we had better be once and for all. So this time my script: just log in once. 😁

Now to the point

To prepare

  • A Windows operating system.
  • Install the wechat client on Windows.
  • Install CukeTest on Windows

So why do I use CukeTest?

Because CukeTest is a special tool for automated testing, I often use it to develop automated test scripts for Windows,Web,Mobile,Api and so on. This time, I mainly want to use it to automatically operate the Windows version of wechat. After you log in to wechat on Windows, don’t worry about it, it will always be online, as long as the computer is not turned off, so as to avoid the trouble of scanning code login.

Install wechat client on Pc, we manually log in, in order to facilitate the automation script to find you which she (or he), you can put her (or his) wechat at the top.

Heartwarming content source

As one of the above

Weather information comes from ink weather

Use the library

  • chromedriver
  • selenium-webdriver
  • moment

These libraries should be familiar to anyone who writes automated tests regularly. Chromedriver Is a driver for chrome, selenium- WebDriver Web automation library. The principle of my script is relatively simple, that is, we usually manual operation steps into an automatic script, automatically open chrome browser, to one and ink weather page to extract information. Because CukeTest built-in Windows control operation, use CukeTest directly to automatically operate wechat, the above extracted information can be sent out.

GitHub

Github.com/autonodejs/…

run

git clone https://github.com/autonodejs/auto_wechat.git
cd auto_wechat
npm install
Copy the code

Open the project with CukeTest and click Run to see how it works.

Key code snippet

1. Edit a story scene

2. Get information

For One,

await driver.get(url);
let css_selector = '.fp-one-cita-wrapper>.fp-one-cita > a'; // Element positioning
let text = await driver.findElement({css:css_selector}).getText();
this.oneText = text;
Copy the code

For the weather

await driver.get(url);
let current_tm = await driver.findElement({ css:'div.wea_weather.clearfix > em'}).getText();
let current_state = await driver.findElement({ css:'.wea_weather.clearfix > b'}).getText();
let wea_tips = await driver.findElement({ css:'.wea_tips.clearfix > em'}).getText();
let current_about = await driver.findElement({ css:'.wea_about.clearfix'}).getText();
this.today_wea = ` temperature:${current_tm}° weather:${current_state}
${current_about}
${wea_tips}
`
});
Copy the code

3. Wechat interface operation

To operate the wechat interface, you need to add virtual controls in CukeTest.

After adding virtual controls, call the API provided by CukeTest. You can see it in the model manager.

Copy or drag the associated methods into the code editor.

4. Run