How to create test site structure before each plone.app.robotframework-based test? -



How to create test site structure before each plone.app.robotframework-based test? -

i can't find way having setup , teardown when running plone robot test.

what need create whole site construction before each test. way found create own new robot keyword create construction browser itself, don't want test folder creation. slow downwards tests nothing.

i found promising in robotsuite library: https://github.com/collective/robotsuite/blob/b52000c65ea96b2be697bf899829c397985fc5aa/src/robotsuite/init.py#l217 can't create works: can define empty setup function, no plone context.

how can this?

at first, can define test site construction in setup methods of plone.app.testing based test layer. (see docs plone.app.testing details.)

in add-on that, there @ to the lowest degree few ways build test site construction plone.app.robotframework based selenium tests:

the first passing test setup function setup-keyword argument robottestsuite-class:

class="lang-py prettyprint-override">import unittest import robotsuite plone.testing import layered my.package.testing import my_package_robot_testing zope.component.hooks import getsite transaction import commit def mysetup(testcase=none): site = getsite() # stuff commit() def test_suite(): suite = unittest.testsuite() suite.addtests([ layered( robotsuite.robottestsuite('test_something.robot', setup=mysetup), layer=my_package_robot_testing ), ]) homecoming suite

there should no need explicit teardown, because plone.app.testing's functional test teardown reverts changes made test sandbox.

this feature based on robottestsuite built mimic doctestsuite doctest-module. setup-method takes single argument, test case object, because test layer lost somewhere in test framework, getsite sane way reach portal object.

finally, it's know approach works long robot framework test executed within same process plone test layer built (which case when executing robosuite-wrapped test suites e.g. zope.testrunner).

the sec way split setup function custom local python keyword library. example, in my/package/testing.py have:

class="lang-py prettyprint-override">from plone import api transaction import commit class mypackagekeywords(object): def create_stuff(self, stuff_id): portal = api.portal.get() obj = api.content.create( type='document', title='my stuff', container=portal ) commit() homecoming obj.absolute_url()

and should able utilize like:

*** settings *** ... library my.package.testing.mypackagekeywords *** test cases *** ... ${url} = create stuff stuff_id=my-stuff go  ${url} element should contain css=h1.documentfirstheading stuff

this has same limitation first approach.

the 3rd possible way create content in actual robot framework test suites using content related remote keywords provided in recent plone.app.robotframework releases.

in short, done including remote_library_bundle_fixture in test layer , using create content , fire transition keywords creating required mock content.

class="lang-py prettyprint-override">import unittest import robotsuite plone.app.robotframework.testing import remote_library_bundle_fixture plone.app.testing import plone_fixture plone.testing import layered plone.testing import z2 plone_acceptance_testing = z2.functionaltesting( bases=(remote_library_bundle_fixture, plone_fixture, z2.zserver_fixture), name="acceptance") def test_suite(): suite = unittest.testsuite() suite.addtests([ layered( robotsuite.robottestsuite('test_something.robot'), layer=plone_acceptance_testing ), ]) homecoming suite *** settings *** resource plone/app/robotframework/keywords.robot resource selenium2screenshots/keywords.robot library remote ${plone_url}/robotremote test setup open test browser test teardown close browsers *** test cases *** scenario: view folder contents given contributor , folder , document within folder when @ folder listing can see document title *** variables *** ${folder_id} a-folder ${document_id} a-document *** keywords *** contributor enable autologin contributor folder create content type=folder ... id=${folder_id} ... title=a folder ... description=this folder document within folder create content type=document ... container=/${plone_site_id}/${folder_id} ... id=${document_id} ... title=a document ... description=this document ... text=<p><strong>hello world!</strong></p> @ folder listing go ${plone_url}/${folder_id}/folder_contents element should visible name=foldercontentsform can see document title page should contain document capture , crop page screenshot folder-contents.png css=#content

plese note, create content -keyword may require utilize of enable autologin as -keyword authenticate content creation calls. note, capture , crop page screenshot nowadays in separate bundle robotframework-selenium2screenshots.

content creation keywords not yet perfect , issues may reported @ github. can implement own remote python keywords. methods in simple python classes, wrapped remote_library_bundle_fixture.

finally, see the known versions plone.app.robotframework , friends.

plone robotframework

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -