我的应用程序依赖于:
它在开发和生产环境中运行完美,但在使用硒进行测试时则无法运行.
使用weasyprint,我从HTML创建一个PDF,这个库使用urllib下载CSS(例如http:// localhost:8081/static/lib/bootstrap/css/bootstrap.min.css),但它挂起(没有错误,只是打开这些时,卡住了.
如果我在挂起时直接在浏览器中输入此URL,则会显示CSS.
使用的命令:
./manage.py test tests.test_account.HomeNewVisitorTest
Run Code Online (Sandbox Code Playgroud)
测试的相关部分:
from selenium import webdriver
class HomeNewVisitorTest(StaticLiveServerTestCase):
def setUp(self):
if TEST_ENV_FIREFOX:
self.driver = webdriver.Firefox()
else:
self.driver = webdriver.PhantomJS()
self.driver.set_window_size(1440, 900)
def tearDown(self):
try:
path = 'worksites/' + self.worksite_name.lower()
os.rmdir(settings.MEDIA_ROOT + path)
except FileNotFoundError:
pass
super().tearDown()
def test(self):
d = self.driver
d.get(self.get_full_url('home'))
d.find_element_by_css_selector('.btn-success[type=submit]').click()
Run Code Online (Sandbox Code Playgroud)
在我看来:
# Generate PDF for contact directory
template = get_template("pdf/annuaire.html")
context = {"worksite": worksite}
html = template.render(RequestContext(self.request, context))
base_url = self.request.build_absolute_uri("/") …Run Code Online (Sandbox Code Playgroud) 试过这个,但没有运气
editor.addCss(this.path + 'tabber.css');
editor.document.appendStyleSheet(this.path + 'tabber.css');
Run Code Online (Sandbox Code Playgroud)
完整代码
(function () {
CKEDITOR.plugins.add('tabber', {
init: function (editor) {
editor.ui.addButton('addTab', {
command: 'addTab',
icon: this.path + 'icons/tabber.png',
label: Drupal.t('Insert tabs')
});
editor.addCss(this.path + 'tabber.css');
editor.document.appendStyleSheet(this.path + 'tabber.css');
editor.addCommand('addTab', {
exec: function (editor) {
editor.insertHtml('<dl>' +
'<dt>Tab title 1</dt>' +
'<dd><p>Tab content 1.</p></dd>' +
'<dt>Tab title 2</dt>' +
'<dd><p>Tab content 2.</p></dd>' +
'</dl>');
}
});
}
});
})();
Run Code Online (Sandbox Code Playgroud)
在init中解决方案(感谢指出正确方向的答案)
var cssPath = this.path + 'tabber.css';
editor.on('instanceReady', function () {
this.document.appendStyleSheet(cssPath);
});
Run Code Online (Sandbox Code Playgroud)