Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added context manager for chrome and content #2753

Merged
merged 7 commits into from
Oct 19, 2016

Conversation

cuff-links
Copy link
Contributor

@@ -29,6 +29,8 @@
import socket
import sys

from contextlib import contextmanager
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Move this to line 28 so it's with the other standard library imports.

@davehunt
Copy link
Contributor

This looks fine to me - the Travis CI failures are unrelated. I'd like @AutomatedTester to give feedback though before merging this.

@lukeis
Copy link
Member

lukeis commented Oct 2, 2016

If we want to keep python more in line with java, switching context should be on the 'switch_to' object / class.

@cuff-links
Copy link
Contributor Author

@lukeis I think the we were trying to keep the usage in line with the marionette context manager. @davehunt What do you think?

@davehunt
Copy link
Contributor

davehunt commented Oct 6, 2016

If we want to keep python more in line with java, switching context should be on the 'switch_to' object / class.

We already have set_context in python. This is a 'context manager', which means the context will be switched for the duration of the manager and reset after.

@lukeis I think the we were trying to keep the usage in line with the marionette context manager. @davehunt What do you think?

I'm not too concerned with matching the marionette client. I'm happy with using_context but would also be happy with simply context because the preceeding with retains the readability:

with selenium.context(selenium.CONTEXT_CHROME):
    # interact with chrome

@AutomatedTester
Copy link
Member

This looks fine

capabilities = {'marionette': True}
self.driver = webdriver.Firefox(capabilities=capabilities)

def test_using_context_sets_correct_context_and_returns(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file needs to move to /py/test/selenium/webdriver/marionette and should now use the driver fixture instead of the setup_method and teardown_method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be moved to the marionette directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and done.

@@ -96,6 +98,7 @@ def __init__(self, firefox_profile=None, firefox_binary=None,
:param firefox_options: Instance of ``options.Options``.
:param log_path: Where to log information from the driver.

<<<<<<< 6bb01d6fb21694fbd74c24c6cb4529fd4b5536e5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

self.options = firefox_options or Options()
self.options.binary_location = self.binary if isinstance(self.binary, basestring) else self.binary._start_cmd
self.options.profile = self.profile
capabilities.update(self.options.to_capabilities())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to bring any of this back in - please remove lines 136-146.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

self.CONTEXT_CONTENT = 'content'

# marionette

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this comment and blank line.

def setup_method(self, method):

capabilities = {'marionette': True}
self.driver = webdriver.Firefox(capabilities=capabilities)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the setup_method as these tests are no longer based on unittest.TestCase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

try:
self.driver.quit()
except:
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the teardown_method and instead add driver to your test method signature.

Copy link
Contributor

@davehunt davehunt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of tweaks. I like the new name of simply context but would appreciate @AutomatedTester's approval before we squash and merge this.


class TestUsingContext(object):

def test_using_context_sets_correct_context_and_returns(self, capabilities):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The test name needs updating to reflect the rename from using_context

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the driver fixture instead of capabilities and then your instance will be cleaned up after.

# specific language governing permissions and limitations
# under the License.

from selenium.webdriver import Firefox
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You won't need this if you use the driver fixture.

@davehunt davehunt merged commit 253d188 into SeleniumHQ:master Oct 19, 2016
@cuff-links cuff-links deleted the Using_Context branch December 22, 2016 22:07
@zzhengjian
Copy link

Would other language bindings support this feature, like java and ruby?

@cuff-links
Copy link
Contributor Author

@zzhengjian I don't mind doing a port in Java. I am not that familiar with ruby but I can give it a whirl as well.

@zzhengjian
Copy link

@silne30 that'll be great for java.

@cuff-links
Copy link
Contributor Author

@davehunt Should I file a new issue for the additional bindings for this? Definitely gonna do Java and ruby is a possiblity.

@davehunt
Copy link
Contributor

@silne30 I don't think it's necessary to file an issue, but it won't do any harm. You could just open the pull requests when your patches are ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants