During the photoshoot of MOE’s blog, there was a cameo appearance with one of his tools, and the first reaction was that it was so handy and untouchable.

Here is the tool: Katalon Recorder

Katalon Recorder

Installation address: Katalon Recorder

The official introduction is:

Best Selenium IDE record, play, debug app. Exports Selenium WebDriver code. Provides reports, logs, screenshots. Fast & extensible.

In simple terms, it can record your every action on the browser, including, click, input, input character, etc., the last key is converted into programming code, can be converted into languages:

  1. C#

  2. JAVA

  3. Katalon Studio

  4. Python2

  5. Roboot Framework

  6. Ruby

  7. XML

For example, the code below is directly converted to Python2

# -*- coding: utf-8 -*-from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.support.ui import Selectfrom selenium.common.exceptions import NoSuchElementExceptionfrom selenium.common.exceptions import NoAlertPresentExceptionimport unittest, time, reclass UntitledTestCase(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() self.driver.implicitly_wait(30) self.base_url = "https://www.katalon.com/" self.verificationErrors = [] self.accept_next_alert = True def test_untitled_test_case(self): driver = self.driver driver.get("https://zhangslob.github.io/") Driver.find_element_by_link_text (u" Subsequent solution for Cookies pool ").click() driver.find_element_by_xpath("//main[@id='main']/div/div").click() def is_element_present(self, how, what): try: self.driver.find_element(by=how, value=what) except NoSuchElementException as e: return False return True def is_alert_present(self): try: self.driver.switch_to_alert() except NoAlertPresentException as e: return False return True def close_alert_and_get_its_text(self): try: alert = self.driver.switch_to_alert() alert_text = alert.text if self.accept_next_alert: alert.accept() else: alert.dismiss() return alert_text finally: self.accept_next_alert = True def tearDown(self): self.driver.quit() self.assertEqual([], self.verificationErrors)if __name__ == "__main__": unittest.main()Copy the code

The test_untitled_test_case function is used to determine whether the test_case function is test_untitled_test_case.

Note that unitTest is used here, so take a look at the documentation if you’re not familiar with it

import unittestclass TestStringMethods(unittest.TestCase):    def test_upper(self):        self.assertEqual('foo'.upper(), 'FOO')    def test_isupper(self):        self.assertTrue('FOO'.isupper())        self.assertFalse('Foo'.isupper())    def test_split(self):        s = 'hello world'        self.assertEqual(s.split(), ['hello', 'world'])        # check that s.split fails when the separator is not a string        with self.assertRaises(TypeError):            s.split(2)if __name__ == '__main__':    unittest.main()Copy the code

Installation method

Here is a suggestion to install directly in the Chrome App Market, address Katalon Recorder

I’ve already downloaded it, in case some of you are not. Public id: Python crawlers and Algorithms advanced, reply: fool

feeling

This is the equivalent of the keystroke wizard, which takes every step of the browser operation and can be used to generate code, just like Postman. That’s why I say Katalon + dumb == Selenium.

For example, to do some automatic login, registration and other parts will be very cool, but the verification code part or need to solve their own.

# ERROR: Caught exception [ERROR: this software does not automatically switch to a newly opened window. Unsupported command [selectWindow | win_ser_1 |]], this step must be manually operation,

Driver.current_window_handle Gets the handle of the current window. Handledriver. Return list List driver.switch_to.window(handle) Switches to the corresponding window driver.close() closes the current windowCopy the code

Test code that opens multiple Windows

# -*- coding: utf-8 -*-from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.support.ui import Selectfrom selenium.common.exceptions import NoSuchElementExceptionfrom selenium.common.exceptions import NoAlertPresentExceptionimport unittest, time, reclass Zhihu(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() self.driver.implicitly_wait(30) self.base_url = "https://www.katalon.com/" self.verificationErrors = [] self.accept_next_alert = True def test_zhihu(self): driver = self.driver driver.get("https://www.zhihu.com/people/cuishite/activities") driver.find_element_by_xpath("//div[@id='ProfileMain']/div/ul/li[2]/a").click() driver.find_element_by_xpath("//div[@id='ProfileMain']/div/ul/li[4]/a/span").click() Driver.find_element_by_link_text (u"Cookies pool solution ").click() # ERROR: Caught exception [ERROR: Unsupported command [selectWindow | win_ser_1 | ]] driver.find_element_by_xpath("//img[contains(@src,'https://pic4.zhimg.com/v2-7ff26e52e6c82c080f62d8e9291e532b_b.jpg')]") .click() driver.find_element_by_link_text(u"Cookies pool solution ").click() # ERROR: Caught exception [ERROR: Unsupported command [selectWindow | win_ser_2 | ]] driver.find_element_by_xpath("//div[@id='js_article']/div[2]").click() def is_element_present(self, how, what): try: self.driver.find_element(by=how, value=what) except NoSuchElementException as e: return False return True def is_alert_present(self): try: self.driver.switch_to_alert() except NoAlertPresentException as e: return False return True def close_alert_and_get_its_text(self): try: alert = self.driver.switch_to_alert() alert_text = alert.text if self.accept_next_alert: alert.accept() else: alert.dismiss() return alert_text finally: self.accept_next_alert = True def tearDown(self): self.driver.quit() self.assertEqual([], self.verificationErrors)if __name__ == "__main__": unittest.main()Copy the code

So only need this to improve the code, at the same time, you can see their official website Katalon-best Automated Testing tool for Web, mobile, API, they mainly provide testing tools, interested can understand