Linux--抓取Appium网站命令
# 获取各命令url地址
curl http://appium.io/docs/en/commands/device/app/is-app-installed/ 2>/dev/null | grep 'href="../../../[a-zA-Z]' | awk -F"\"" '{print $2}' | awk -F"../../.." '{print $2}' | awk -va="http://appium.io/docs/en/commands" '{print a$1}' > command.txt
# 抓取python示例命令
while read line; do curl $line 2>/dev/null | sed ':a ; N;s/\n/ / ; t a ; ' | awk -F "<pre><code class=\"python\">" '{print $2}' | awk -F "</code></pre>" '{print $1}'; done < command.txt > pythoncommand.txt
# 抓取java示例命令
while read line; do curl $line 2>/dev/null | sed ':a ; N;s/\n/ / ; t a ; ' | awk -F "<pre><code class=\"java\">" '{print $2}' | awk -F "</code></pre>" '{print $1}'; done < command.txt > javacommand.txt
java command content:
1 // TODO 2 driver.executeScript("mobile: scroll", ImmutableMap.of("direction", "down")); 3 driver.quit(); 4 driver.back(); 5 File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); 6 String pageSource = driver.getPageSource(); 7 driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS); 8 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 9 driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS); 10 ScreenOrientation orientation = driver.getOrientation(); 11 driver.rotate(ScreenOrientation.LANDSCAPE); 12 driver.setLocation(new Location(49, 123, 10)); // Must be a driver that implements LocationContext 13 Set<String> logTypes = driver.manage().logs().getAvailableLogTypes(); 14 LogEntries logEntries = driver.manage().logs().get("driver"); 15 driver.setSetting(Setting.WAIT_FOR_IDLE_TIMEOUT, Duration.ofSeconds(5)); 16 Map<String, Object> settings = driver.getSettings(); 17 MobileElement elementOne = (MobileElement) driver.findElementByAccessibilityId("SomeAccessibilityID"); MobileElement elementTwo = (MobileElement) driver.findElementByClassName("SomeClassName"); 18 List<MobileElement> elementsOne = (MobileElement) driver.findElementsByAccessibilityId("SomeAccessibilityID"); List<MobileElement> elementsTwo = (MobileElement) driver.findElementsByClassName("SomeClassName"); 19 MobileElement el = driver.findElementByAccessibilityId("SomeId"); el.click(); 20 MobileElement element = (MobileElement) driver.findElementByAccessibilityId("SomeAccessibilityID"); element.sendKeys("Hello world!"); 21 MobileElement element = (MobileElement) driver.findElementByAccessibilityId("SomeAccessibilityID"); element.clear(); 22 MobileElement element = (MobileElement) driver.findElementByClassName("SomeClassName"); String elText = element.getText(); 23 List<MobileElement> element = (MobileElement) driver.findElementByAccessibilityId("SomeAccessibilityID"); String tagName = element.getTagName(); 24 List<MobileElement> element = (MobileElement) driver.findElementByAccessibilityId("SomeAccessibilityID"); String tagName = element.getAttribute("content-desc"); 25 MobileElement element = (MobileElement) driver.findElementByAccessibilityId("SomeAccessibilityID"); boolean isEnabled = element.isEnabled(); 26 List<MobileElement> element = (MobileElement) driver.findElementByAccessibilityId("SomeAccessibilityID"); Rectangle rect = element.getRect(); 27 List<MobileElement> element = (MobileElement) driver.findElementById("SomeId"); String cssProperty = element.getCssValue("style"); 28 // Not supported 29 // Overrides the Java Object .equals method MobileElement elementOne = (MobileElement) driver.findElementByClassName("SomeClassName"); MobileElement elementTwo = (MobileElement) driver.findElementByClassName("SomeOtherClassName"); boolean isEqual = elementOne.equals(elementTwo); 30 String context = driver.getContext(); 31 Set<String> contextNames = driver.getContextHandles(); 32 Set<String> contextNames = driver.getContextHandles(); driver.context(contextNames.toArray()[1]); // ... driver.context("NATIVE_APP"); 33 Actions action = new Actions(driver); action.moveTo(element, 10, 10); action.perform(); 34 Actions action = new Actions(driver); action.moveTo(element); action.click(); action.perform(); 35 Actions action = new Actions(driver); action.moveTo(element); action.doubleClick(); action.perform(); 36 Actions action = new Actions(driver); action.moveTo(element); action.clickAndHold(); action.perform(); 37 Actions action = new Actions(driver); action.moveTo(element); action.clickAndHold(); action.moveTo(element, 10, 10); action.release(); action.perform(); 38 TouchActions action = new TouchActions(driver); action.doubleTap(element); action.perform(); 39 TouchActions action = new TouchActions(driver); action.down(10, 10); action.move(50, 50); action.perform(); 40 TouchActions action = new TouchActions(driver); action.down(10, 10); action.up(20, 20); action.perform(); 41 TouchActions action = new TouchActions(driver); action.longPress(element); action.perform(); 42 TouchActions action = new TouchActions(driver); action.scroll(element, 10, 100); action.perform(); 43 TouchAction action = new TouchAction(driver); action.press(10, 10); action.moveTo(10, 100); action.release(); action.perform(); 44 WebElement source = (MobileElement) driver.findElementsByAccessibilityId("SomeAccessibilityID"); WebElement target = (MobileElement) driver.findElementsByAccessibilityId("SomeOtherAccessibilityID"); Point source = dragMe.getCenter(); Point target = driver.findElementByAccessibilityId("dropzone").getCenter(); PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger"); Sequence dragNDrop = new Sequence(finger, 1); dragNDrop.addAction(finger.createPointerMove(Duration.ofMillis(0), PointerInput.Origin.viewport(), source.x, source.y)); dragNDrop.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg())); dragNDrop.addAction(finger.createPointerMove(Duration.ofMillis(700), PointerInput.Origin.viewport(),target.x, target.y)); dragNDrop.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg())); driver.perform(Arrays.asList(dragNDrop)); 45 driver.switchTo().window("handle"); 46 driver.close(); 47 String windowHandle = driver.getWindowHandle(); 48 Set<String> windowHandles = driver.getWindowHandles(); 49 Dimension windowSize = driver.manage().window().getSize(); 50 driver.manage().window().setSize(new Dimension(10, 10)); 51 Point windowPosition = driver.manage().window().getPosition(); 52 driver.manage().window().setPosition(new Dimension(10, 10)); 53 driver.manage().window().maximize(); 54 driver.get("http://appium.io/"); 55 String url = driver.getCurrentUrl(); 56 driver.back(); 57 driver.forward(); 58 driver.refresh(); 59 Set<Cookie> allcookies = driver.manage().getCookies(); 60 driver.manage().deleteAllCookies(); 61 driver.switchTo().frame(3); 62 driver.switchTo().parentFrame(); 63 ((JavascriptExecutor) driver).executeAsyncScript("window.setTimeout(arguments[arguments.length - 1], 500);"); 64 ((JavascriptExecutor) driver).executeScript("window.setTimeout(arguments[arguments.length - 1], 500);");
python command content:
1 self.driver.execute_script("mobile: scroll", {'direction': 'down'}) 2 desired_caps = desired_caps = { 'platformName': 'Android', 'platformVersion': '7.0', 'deviceName': 'Android Emulator', 'automationName': 'UiAutomator2', 'app': PATH('/path/to/app') } self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) 3 self.driver.quit() 4 desired_caps = self.driver.desired_capabilities() 5 self.driver.set_page_load_timeout(5000) 6 self.driver.implicitly_wait(5000) 7 self.driver.set_script_timeout(5000) 8 orientation = self.driver.orientation() 9 driver.orientation = "LANDSCAPE" 10 self.driver.set_location(49, 123, 10) 11 log_types = driver.log_types(); 12 logs = driver.get_log('driver'); 13 self.driver.get_settings 14 el = self.driver.find_element_by_accessibility_id('SomeAccessibilityID') 15 el = self.driver.find_elements_by_accessibility_id('SomeAccessibilityID') 16 self.driver.find_element_by_accessibility_id('SomeAccessibilityID').send_keys('Hello world!') 17 self.driver.find_element_by_accessibility_id('SomeAccessibilityID').clear() 18 el = self.driver.find_element_by_accessibility_id('SomeAccessibilityID') text = el.text 19 tagName = self.driver.find_element_by_accessibility_id('SomeAccessibilityID').tag_name 20 tagName = self.driver.find_element_by_accessibility_id('SomeAccessibilityID').get_attribute('content-desc') 21 self.driver.find_element_by_accessibility_id('SomeAccessibilityID').is_selected() 22 self.driver.find_element_by_accessibility_id('SomeAccessibilityID').is_enabled() 23 self.driver.find_element_by_accessibility_id('SomeAccessibilityID').is_displayed() 24 location = self.driver.find_element_by_accessibility_id('SomeAccessibilityID').location 25 # Not supported 26 cssProperty = self.driver.find_element_by_accessibility_id('SomeId').value_of_css_property("style") 27 # Not supported 28 el = self.driver.find_element_by_accessibility_id('SomeAccessibilityID') el.submit(); 29 element = driver.switch_to.active_element 30 # TODO Python sample 31 context = driver.current_context # or context = driver.context 32 contexts = driver.contexts 33 webview = driver.contexts[1] driver.switch_to.context(webview) # ... driver.switch_to.context('NATIVE_APP') 34 actions = ActionChains(driver) actions.move_to_element(element) actions.click() actions.perform() 35 actions = ActionChains(driver) actions.move_to_element(element) actions.double_click() actions.perform() 36 actions = ActionChains(driver) actions.move_to_element(element) actions.click_and_hold() actions.perform() 37 from appium.webdriver.common.touch_action import TouchAction # ... actions = TouchAction(driver) actions.tap(element) actions.perform() 38 from appium.webdriver.common.touch_action import TouchAction # ... actions = TouchAction(driver) actions.double_tap(element) actions.perform() 39 from appium.webdriver.common.touch_action import TouchAction # ... actions = TouchAction(driver) actions.tap_and_hold(element) actions.move(50, 50) actions.perform() 40 from appium.webdriver.common.touch_action import TouchAction # ... actions = TouchAction(driver) actions.tap_and_hold(20, 20) actions.release(50, 50) actions.perform() 41 from appium.webdriver.common.touch_action import TouchAction # ... actions = TouchAction(driver) actions.long_press(element) actions.perform() 42 from appium.webdriver.common.touch_action import TouchAction # ... actions = TouchAction(driver) actions.scroll_from_element(element, 10, 100) actions.scroll(10, 100) actions.perform() 43 from appium.webdriver.common.touch_action import TouchAction from appium.webdriver.common.multi_action import MultiAction # ... a1 = TouchAction() a1.press(10, 20) a1.move_to(10, 200) a1.release() a2 = TouchAction() a2.press(10, 10) a2.move_to(10, 100) a2.release() ma = MultiAction(self.driver) ma.add(a1, a2) ma.perform() 44 from appium.webdriver.common.touch_action import TouchAction // ... actions = TouchAction(driver) actions.tap_and_hold(20, 20) actions.move_to(10, 100) actions.release() actions.perform() 45 self.driver.switch_to.window("handle") 46 self.driver.close() 47 window_handle = self.driver.current_window_handle() 48 window_handles = self.driver.window_handles() 49 handle_one_size = self.driver.get_window_size() handle_two_size = self.driver.get_window_size("handleName") 50 self.driver.set_window_size(10, 10) 51 url = self.driver.current_url() 52 self.driver.forward() 53 self.driver.refresh() 54 cookies = self.driver.get_cookies() 55 self.driver.add_cookie({name: 'foo', value: 'bar'}) 56 self.driver.delete_all_cookies() 57 self.driver.switch_to.frame(3) 58 self.driver.switch_to.parent() 59 self.driver.execute_async_script(‘document.title’) 60 self.driver.execute_script(‘document.title’)