Uri*_*Uri 2 python cron google-app-engine selenium
我们希望使用Google App Engine每4小时使用cron运行Selenium测试(稍后我们可能会更改此小时数).我们希望收到一封包含测试结果的电子邮件.我想知道我是如何创建第一个测试的.我想通过我们的Google Chrome扩展程序测试https://inbox.google.com/ - 进入我们的网站,登录,点击"保存更改",安装扩展程序,然后输入https://inbox.google.com/,登录并检查扩展是否有效.问题是我不知道如何设置测试,我是否必须使用URL设置它们,我该怎么做?我是否必须为每个测试提供不同的URL,或者我可以使用一个URL运行所有测试吗?以下是我从http://app.crossbrowsertesting.com/selenium/run收到的代码:
# Please visit http://selenium-python.readthedocs.org/en/latest/index.html for detailed installation and instructions
import unittest
from selenium import webdriver
class SeleniumCBT(unittest.TestCase):
def setUp(self):
caps = {}
caps['name'] = 'Chrome Inbox Test'
caps['build'] = '1.0'
caps['browser_api_name'] = 'Chrome39x64'
caps['os_api_name'] = 'Win8.1'
caps['screen_resolution'] = '1280x1024'
caps['record_video'] = 'true'
caps['record_network'] = 'true'
caps['record_snapshot'] = 'true'
#start the remote browser on our server
self.driver = webdriver.Remote(
desired_capabilities=caps,
command_executor="http://[username]:[password]@hub.crossbrowsertesting.com:80/wd/hub"
)
self.driver.implicitly_wait(20)
def test_CBT(self):
#load the page url
print('Loading Url')
self.driver.get('http://crossbrowsertesting.github.io/selenium_example_page.html')
#maximize the window
print('Maximizing window')
self.driver.maximize_window()
#check the title
print('Checking title')
self.assertTrue("Selenium Test Example Page" in self.driver.title)
def tearDown(self):
print("Done with session %s" % self.driver.session_id)
self.driver.quit()
if __name__ == '__main__':
unittest.main()
Run Code Online (Sandbox Code Playgroud)
我还下载了Selenium(2.44.0)并将其放在libs目录中,如果我包含以下行:
import sys
sys.path.insert(0, 'libs')
Run Code Online (Sandbox Code Playgroud)
我可以进口硒吗?(from selenium import webdriver)或者我还要做别的事吗?
我们使用的是Python 2.7(虽然我们可以升级到Python 3).
硒可以让您控制(AKA 自动)浏览器-和,在一个App Engine实例,你不要有一个浏览器,也无法安装一个.
App Engine是一个平台(PaaS - "平台即服务"),您可以编写(服务器端)Web应用程序,而不是运行Web 客户端(如浏览器).
相反,您应该将基础架构视为服务(IaaS)产品:例如,在该领域,Google拥有"Google Compute Engine",并使用容器(docker)在其上构建层.
补充:除了几个.so显然只需要驱动firefox之外,selenium webdriver python语言绑定看起来似乎是纯Python - 如果使用Selenium严格限制webdriver.Remote为驱动远程Selenium服务器,如app. crossbrowsertesting.com/selenium/run,由OP的评论指出,这可能是开箱很多到您的应用程序的主目录的子目录将让你这样做的GAE.
我说"可能",而不是"确定",因为我无法确认selenium远程协议是以与App Engine提供的套接字功能子集兼容的方式在这些源中实现的.
通过代码检查确定是否是这种情况需要比简单的试错方法更长的时间 - 因此,因为"试验"部分不会破坏任何东西(即使在最坏的情况下,它将以异常终止) ,我会建议那个(让我们都知道!).
至于其他Qs,如果selenium确实有效,如果OP总是希望一起运行所有测试(从不仅仅是其中的一部分),那么将应用程序的单个URL专用于加载和运行所有测试的处理程序将是完全可行的. - 那部分并不困难.可能会破坏的部分(并且可能以不可修复的方式破坏,取决于硒远程协议编码的细节)是前一个 - 归结为能够使用selenium的远程执行"hello world"的webdriver.并且确定,正如我所说,反复试验是最可行的方法.
| 归档时间: |
|
| 查看次数: |
4127 次 |
| 最近记录: |