我们希望使用googleappengine每4小时用cron运行Selenium测试(稍后我们可能会更改这个时间)。我们想收到一封包含测试结果的电子邮件。我想知道如何创建第一个测试。{{1}输入我们的扩展名{1},然后输入我们的扩展名^-1,然后输入我们的扩展名^-。问题是我不知道如何设置测试,我必须用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()
我还下载了Selenium(2.44.0)并将其放在libs
目录中,如果我包含以下行:
我能进口硒吗?(from selenium import webdriver
)还是我必须做其他事情?在
我们使用的是Python2.7(尽管我们可以升级到Python3)。在
Selenium让您可以控制浏览器(又名自动化),而且在App Engine实例上,您没有浏览器,也无法安装浏览器。在
App Engine是一个平台(PaaS“平台即服务”),供您编写(服务器端)web应用程序,而不是运行web客户端如浏览器。在
相反,您应该查看基础设施即服务(IaaS)产品:例如,在那个字段中,Google有“Google计算引擎”和使用容器(docker)构建的层。在
补充:除了几个显然只需要驱动firefox的
.so
之外,如果使用selenium严格限制为webdriver.Remote
来驱动远程selenium服务器,那么selenium webdriver python语言绑定看起来确实是纯pythonapp.crossbrowsertesting.com/selenium/run, 正如OP在评论中指出的那样,有可能将这些数据解包到应用程序主目录的子目录中可以让你在GAE上这样做。在我说“可能”,而不是“确定”,因为我无法确认selenium远程协议是否以与AppEngine提供的socket功能子集兼容的方式在这些源中实现。在
确定这是否是逐条代码检查所需的时间远比简单的试验和错误方法要长得多,因此,由于“试验”部分不会破坏任何东西(即使在最坏的情况下,它也只会以例外情况终止),我建议(并让我们都知道!)。在
至于其他的Qs,如果selenium真的起作用,那么将应用程序的一个URL指定给一个加载并运行所有测试的处理程序是完全可行的,如果OP总是希望一起运行所有测试(而不是其中的一个子集),那么这一部分一点也不困难。可能中断的部分(也可能以不可修复的方式中断,这取决于selenium远程协议是如何编码的)是前面的一个,它可以归结为能够使用selenium的远程webdriver进行“hello world”。而且,正如我所说的,试错是最可行的方法。在
相关问题 更多 >
编程相关推荐