Selenium IDE Python Remote Control 플러그인 포매터에서 내보내는 둘 이상의 Python 테스트 스크립트를 실행하는 데 몇 가지 문제가 있습니다.Selenium IDE Python 스크립트를 테스트 스위트로 실행하려고 시도합니다.
1) 파이썬 스크립트가 완료되면 브라우저 창이 자동으로 닫힙니다. 필자는 Firefox에서 테스트를 실행하고 있습니다.
2) Selenium은 python으로 테스트 스위트를 내보낼 수 없습니다. 파이썬에서 테스트 스위트 기능을 어떻게 복제 할 수 있습니까?
테스트 스크립트 (Testuff) 소프트웨어가 Selenium 테스트 사례 자동화를 실행 한 인접 테스트 케이스를 업데이트하기 위해 API 호출을 허용하기 때문에 테스트 스크립트를 Python으로 실행해야하는 이유가 있습니다.
다음은 API 호출 코드의 예입니다.
감사합니다. 빠른 응답
from selenium import selenium
import unittest, time, re
class python_script(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", 4444, "*chrome", "http://test website url/")
self.selenium.start()
def test_python_script(self):
sel = self.selenium
from selenium import selenium
import unittest, time, re, urllib
class python_script(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", 4444, "*chrome", "http://test website url/")
self.selenium.start()
def test_python_script(self):
sel = self.selenium
sel.open("http://192.168.48.23/labmatrix")
for i in range(60):
try:
if sel.is_element_present("//*[@name='username']"):
break
except: pass
#time.sleep(1)
else:
fields = {"test_id" : "testuff test_id number","status" : "failed"}
result = urllib.urlopen("testuff api url", urllib.urlencode(fields))
print result.read()
self.fail("time out")
sel.type("//*[@name='username']", "username")
for i in range(60):
try:
if sel.is_element_present("//*[@name='password']"): break
except: pass
#time.sleep(1)
else:
fields = {"test_id" : "testuff test_id number","status" : "failed"}
result = urllib.urlopen("testuff api url", urllib.urlencode(fields))
print result.read()
#self.fail("time out")
sel.type("//*[@name='password']", "password")
for i in range(60):
try:
if sel.is_element_present("//*[@id='submitButton']"): break
except: pass
#time.sleep(1)
else:
fields = {"test_id" : "testuff test_id number","status" : "failed"}
result = urllib.urlopen("testuff api url", urllib.urlencode(fields))
print result.read()
self.fail("time out")
sel.click("//*[@id='submitButton']")
#time.sleep(0.1)
for i in range(60):
try:
if sel.is_element_present("//*[@id='loadingDeck'][@selectedIndex='1']"):
fields = {"test_id" : "testuff test_id number","status" : "passed"}
result = urllib.urlopen("testuff api url", urllib.urlencode(fields))
print result.read()
break
except: pass
#time.sleep(1)
else:
self.fail("time out")
def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
감사합니다. 나는이 코드로 jcfollower의 추천을 시도했다 :
from selenium import selenium
import unittest, time, re
class python_script(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", 4444, "*chrome", "Testing Website URL")
self.selenium.start()
def test_python_script_1(self):
sel = self.selenium
def test_python_script_2(self):
sel = self.selenium
sel.open("Testing website URL")
for i in range(60):
try:
if sel.is_element_present("//*[@name='username']"):
break
except: pass
#time.sleep(1)
else:
fields = {"test_id" : "Testuff API Test_id","status" : "failed"}
result = urllib.urlopen("API URL", urllib.urlencode(fields))
print result.read()
self.fail("time out")
sel.type("//*[@name='username']", "username")
for i in range(60):
try:
if sel.is_element_present("//*[@name='password']"): break
except: pass
#time.sleep(1)
else:
fields = {"test_id" : "testuff API test_id","status" : "failed"}
result = urllib.urlopen("testuff API url", urllib.urlencode(fields))
print result.read()
#self.fail("time out")
sel.type("//*[@name='password']", "password")
for i in range(60):
try:
if sel.is_element_present("//*[@id='submitButton']"): break
except: pass
#time.sleep(1)
else:
fields = {"test_id" : "testuff API test_id","status" : "failed"}
result = urllib.urlopen("API URL", urllib.urlencode(fields))
print result.read()
self.fail("time out")
sel.click("//*[@id='submitButton']")
#time.sleep(0.1)
for i in range(60):
try:
if sel.is_element_present("//*[@id='loadingDeck'][@selectedIndex='1']"):
fields = {"test_id" : "testuff API test_id","status" : "passed"}
result = urllib.urlopen("API URL", urllib.urlencode(fields))
print result.read()
break
except: pass
#time.sleep(1)
else:
self.fail("time out")
def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
... 그리고 불행히도, 브라우저 창이 여전히 닫혔다. 다른 제안?
감사합니다.
부분적으로 작동합니다.
제거의 하나
if __name__ == "__main__":
unittest.main()
def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
... 및 제거 :
self.selenium.stop()
나머지 "if __name__
"문 및 파이썬 로그 플러스 브라우저 창에서 열려 남아있다. 그게 올바른 방향으로 한 걸음 씩 있지만 스크립트가 실행 완료되면 로그 창을 닫아야합니다.
다음 단계를 추측하면서 Im은 다른 정지 클래스를 만들고 selenium.py 파일에서 약간 놀아보고 브라우저를 닫기위한 명령을 제거 할 수 있는지 확인합니다.
누군가 다른 의견이 있으면 크게 감사 할 것입니다.
안녕하세요 Yoav, 제안을 시도했지만 Firefox 창이 열리지 않습니다. –
정확히 말하기는 어렵지만 2.7보다 오래된 Python을 실행하고 있거나 unittest2를 설치하지 않았거나 제대로 가져 오지 못했습니다. setUpClass가로드 될 때 실행되는지 확인하십시오. 예 : 각 함수에 print 문을 추가하고 실행 여부를 확인하십시오. – gingerlime
안녕 Yoav, 나는 파이썬 2.7을 사용하고 있습니다. 감사. –