ListViewの内容があっているかテストするコードのメモ。
ListViewにはアイテムが100個、要素それぞれがアイテム番号とスコアを入れるTextViewを持っている。
test_list.py
def test(self, flat_case)
counter=100 #要素数は既知
while(counter>0):
# ListViewの一行分レイアウト内の、全体を囲む要素のidを指定。ここではLinearLayoutだった
elements = self.driver.find_elements_by_id("app_id:id/linear_whole")
print("counter=",counter)
for el in elements:
try:
#もう一段階LinearLayoutがあった
els=el.find_elements_by_id("app_id:id/linear_id")
for e in els:
try:
#目的の要素のアイテム番号を保持しているTextView
txt_id=e.find_element_by_id("app_id:id/text_id")
print("text_id=",txt_id.text, "counter=", counter)
if str(txt_id.text)==str(counter):
#スコアが入ったTextViewを指定
score=el.find_element_by_id("app_id:id/text_score")
score=str(score.text).strip()
#flat_caseは全要素分の正解scoreが入ったリスト。
print("score=",score, "ans=",flat_case[counter-1])
#正しい値であることを確認
self.assertEqual(score, str(flat_case[counter-1]))
#ListViewには100->1まで逆順に並んでいたのでcounterはデクリメントする
counter=counter-1
except NoSuchElementException:
continue
except NoSuchElementException:
continue
#スクロール
self.driver.swipe(0,0,0,500,300)