当前位置:网站首页>Verification code is the natural enemy of automation? Ali developed a solution

Verification code is the natural enemy of automation? Ali developed a solution

2022-06-11 15:41:00 Two black

Verification Code

1、 What is a captcha :

A randomly generated message ( Numbers 、 Letter 、 Chinese characters 、 picture 、 problem in arithmetic ) In order to prevent malicious request behavior , Increase the security of the application

Registration or login is also required in the automation process , So you need to deal with validation

2、 Verification code processing method :

  • Remove the captcha

    Operated by the developer , Used in the test environment

    This is the easiest way , For developers , Just comment out the relevant code of the verification code , If it's in a test environment , This saves testers a lot of trouble , If the automation script is to run in a formal environment , This brings certain risks to the system .

  • Picture setting universal verification code

    Operated by the developer , Generally, it is only used in the test environment

  • Picture verification code recognition technology

    Because of the technical difficulty , Recognition rate is difficult to achieve 100%, Records are generally not recommended COOKIE Pass record cookie To skip the login operation

  • Can pass add_cookie() Method to write the user name and password to the browser cookie, When you visit the website again, the server reads the browser directly Cookie Sign in

Cookie

1、Cookie principle
Cookie By Web Server generated , And a small text file saved in the user's browser , It can contain user related information

  • Cookie data format : Key value pairs make up (python Dictionary in )

  • Cookie produce :

    The client requests the server , If the server needs to record the user status , Just give the client browser a Cookie data

  • Cookie Use :

    When the browser requests the site again , The browser combines the requested data with Cookie Submit the data to the server together , Server check Cookie, To identify user status

2、Selenium operation cookie

  • driver.get_cookie(name) Gets the name of the cookie Information , Back is a dictionary

  • driver.get_cookies() What you get is all cookie Information about , It returns a list

  • driver.add_cookie(dict_cookie) Add... To the browser driver cookie,dict_cookie It's a dictionary

Take Baidu for example

BDUSS Is the only identity certificate after login Baidu (*.baidu.com), Get BDUSS It's like taking control of the account , Post Bar 、 know 、 Encyclopedias 、 library 、 Space 、 Baidu cloud and other major products of Baidu .

  • Sign in baidu, Grab after successful login (BDUSS)

  • Use add_cookie() Method , add to () Key and value

  • Call the refresh method driver.refresh()

How to get BDUSS Value ?( Grab the bag to realize )

adopt fiddler After tool grabbing , obtain BDUSS


If the bag grabbing tool is inconvenient , You can search through the browser cookie Information

  • Click on chrome Browser settings

  • Enter... In the settings search cookie

  • View all cookie And website data

  • Search Baidu domain name :baidu.com

  • obtain BDUSS

Code implementation


After refresh , Result display

Learning resource sharing

Finally, thank everyone who reads my article carefully , Watching the rise and attention of fans all the way , Reciprocity is always necessary , Although it's not very valuable , If you can use it, you can take it

These materials , For those who want to engage in 【 software test 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you ! You can get it for free by joining our communication group below , I hope that's helpful …….

原网站

版权声明
本文为[Two black]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111534317200.html