我们想使用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()
libs
如果包括以下几行,我还下载了Selenium(2.44.0)并将其放在目录中:
import sys
sys.path.insert(0, 'libs')
我可以进口硒吗?(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的几个s之外,selenium webdriver python语言绑定的确是纯Python -如果严格限制使用Seleniumwebdriver.Remote
来驱动诸如app之类的远程Selenium服务器。 crossbrowsertesting.com/selenium/run,由OP的评论指出,这可能是开箱很多到您的应用程序的主目录的子目录将让你这样做的GAE。
我说的是“可能”,而不是“某些”,因为我无法确认硒远程协议是在那些源中实现的,并且与App Engine提供的套接字功能的子集兼容。
通过代码检查确定是否是这种情况比简单的尝试和错误方法要花费更长的时间-因此,由于“试用”部分不会破坏任何内容(即使在最坏的情况下,它也会终止并带有异常) ,我会为此建议(并让我们所有人知道!)。
至于其他Q,如果硒确实起作用,那么如果OP始终希望一起运行所有测试(永远不要只运行它们的一个子集),那么将应用程序的单个URL分配给加载并运行所有测试的处理程序将是完全可行的。 -这部分并不难。可能会破坏的部分(可能会以无法修复的方式破坏,这取决于硒远程协议的编码方式的细节)是上一部分-归结为能够使用硒的远程设备做一个“ hello world”网络驱动程序。就像我说的那样,确定这一点是最可行的方法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句