Appium學習實踐(二)Python簡單腳本以及元素的屬性設置


1.簡單的Python腳本

Appium中的設置與Appium學習實踐(一)簡易運行Appium中的一致

Launch后,執行腳本

#coding:utf-8
import unittest
import os
from selenium import webdriver
from time import sleep

class Dttest(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Remote(
            command_executor='http://127.0.0.1:4723/wd/hub',
            desired_capabilities={
                'platformName': 'iOS',
                'deviceName':'iPhone 5s'
            })

    def tearDown(self):
        self.driver.quit()

    def test_test(self):
        sleep(10)

由於Appium中的iOS Settings中BundleID還有設備的UDID都已經填寫好,所以腳本中就沒有重復填寫

需要注意的是:這里的command_executor要和Appium中的Server Address一致,不然怎么可能連得上。、

Ps:deviceName也是必填的,但是發現name填錯了也沒有任何事情發生

 

tearDown中是用例執行結束后執行的操作

test_test是具體的測試用例,先用一個sleep代替下,后面改成具體的操作加斷言

 

2.元素的屬性設置

個人覺得基於UI的自動化,首先最重要的是要找到你想找的元素,然后你才能對元素進行操作並對結果進行斷言

以app中的分數為例,如果沒有設置ID的話,只能通過xpath進行定位

設置了元素的name屬性后可以通過find_element_by_name("scoreLab")進行定位,這樣找錯元素的幾率也會變小很多

所以這個name屬性在哪里設置呢。、

這里就要麻煩我們的開發了

在storyboard中的Accessibility中加上Identifier屬性

Label對應的是元素的value值

 

以前遇到的坑:

static text的value無法進行獲取,會和name的屬性一致
在UILabel category中添加如下代碼可以實現獲取value屬性
 @interface UIViewController (WarninigBar)

- (void)showTopWarning:(NSString *)warningText;

@end

@interface UILabel (MyAccessibility)
@property(nonatomic, copy) NSString *accessibilityValue;
@end


@implementation UILabel (MyAccessibility)

@dynamic accessibilityValue;

-(NSString *)accessibilityValue {
    // Here we force UIKit to return Label value, not the accessibility label
    return self.text;
}

@end

http://stackoverflow.com/questions/7688311/cant-get-value-of-uiastatictext


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM