Skip to content

Reusable session - #783

Closed
yahman72 wants to merge 9 commits into
robotframework:masterfrom
yahman72:reusable_session
Closed

yahman72 wants to merge 9 commits into
robotframework:masterfrom
yahman72:reusable_session

Conversation

@yahman72

Copy link
Copy Markdown

PR for #690

@aaltat aaltat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did only has time to do partial review, but there is few things where you can proceed already.

@@ -1,13 +1,20 @@
import os
import os, signal

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. The master have moved forward and there are quite many conflicts which you must resolve.
  2. Write:
    import os
    import signal
  3. Fix, in the code you did write, all the pep8 related errors. Example line length must be followed.
    The only default rule are the keyword examples which can exceed the line length.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

import os, signal
import robot
from robot.errors import DataError
from robot.api import logger

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We do not use robot logger directly. There are logging methods in the library instance, like self.info

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

}

class _ReusableDriver(webdriver.Remote):
def __init__(self, command_executor, sid, keep_alive=False, file_detector=None):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Empty line after class definition

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

from keywordgroup import KeywordGroup
from selenium.common.exceptions import NoSuchWindowException

from selenium.webdriver.remote.errorhandler import ErrorHandler

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove the imports that are not used.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

'edge': "_make_edge"
}

class _ReusableDriver(webdriver.Remote):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two empty lines before the class definition.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

file_detector=file_detector)

def stop_client(self):
if self.pid is not None and self.pid != '':

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would: if self.pid: work too? At least it would be more Pythonic way to write the code.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Unfortunately not, because the selenium implementation is not consistent for different browsers.
Some of them use pid=None and some of them use pid=''.

logger.info("Stopping driver for session '%s' with PID: %s" % (self.session_id, self.pid))
try:
os.kill(int(self.pid), signal.SIGTERM)
except Exception:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. If the pid does not exist then the different OS will raise different types of errors. In Windows 10 it is WindowsError and in Linux is it OSError. But both exceptions are based on the same error: EnvironmentError. Perhaps it would be best to do: expect EnvironmentError
  2. If we can not kill the driver executable, is there any reason to continue? Should we just let the exception raise and just stop the test execution?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

1 done
2 I'd say no. The side-effect is that the affected browser just stays open and is not anymore "reachable" via Selenium and must be closed manually. IMHO this is okay when considering the use cases for these KW's = TC development i.e. not for production use.

def save_webdriver(self, file=''):
"""Stores the current web-driver session.

This KW makes the WebDriver sessions persistent. I.e. you can store the session(s) and leave the browser

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. Write that this is only for purposed for test development and is not for production use.

  2. The documentation need some reformatting. But lets discuss that later.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

some updates included

@yahman72

Copy link
Copy Markdown
Author

quick one:
my focus was purely on the functionality, that's why there are plenty of those PEP-8 issues and other conventions related stuff, for the same reason I did not resolve the merge conflicts in the first place

But of course I'll update the PR accordingly as soon as I can (in 2 weeks hopefully) - now pretty busy with other stuff and easter holidays

@aaltat

aaltat commented Apr 12, 2017

Copy link
Copy Markdown
Contributor

Ah ok. I will try to do functionality review and let's see after that.

@aaltat

aaltat commented May 17, 2017

Copy link
Copy Markdown
Contributor

Sorry that I haven't found time to look on the PR. I have been busy with the new architecture and other real life stuff... I will try to take a look as soon as possible.

@aaltat

aaltat commented Apr 22, 2019

Copy link
Copy Markdown
Contributor

@yahman72 are you still planning to do something with the PR or can we close it?

@aaltat

aaltat commented May 21, 2019

Copy link
Copy Markdown
Contributor

Closing due inactivity.

@aaltat aaltat closed this May 21, 2019
@yahman72

Copy link
Copy Markdown
Author

sorry, forgot to answer - still planning to update this, but at the moment I don't need this = no idea when I would do this.

In short: better to close this, I can create a new PR/issue when I start working on this again

@aaltat

aaltat commented May 21, 2019

Copy link
Copy Markdown
Contributor

No worries, I am just doing spring cleaning and closing old issues and PR. And if code is needed, then it can be found from the GitHub.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants