Robot Framework SeleniumLibrary
librarycomponent.py
Go to the documentation of this file.
1 # Copyright 2008-2011 Nokia Networks
2 # Copyright 2011-2016 Ryan Tomac, Ed Manlove and contributors
3 # Copyright 2016- Robot Framework Foundation
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 import os
18 
19 from robot.api import logger
20 from robot.libraries.BuiltIn import BuiltIn, RobotNotRunningError
21 
22 from SeleniumLibrary.utils import is_noney, timestr_to_secs
23 
24 from .context import ContextAware
25 from .robotlibcore import PY2
26 
27 
29 
30  def info(self, msg, html=False):
31  logger.info(msg, html)
32 
33  def debug(self, msg, html=False):
34  logger.debug(msg, html)
35 
36  def log(self, msg, level='INFO', html=False):
37  if not is_noney(level):
38  logger.write(msg, level.upper(), html)
39 
40  def warn(self, msg, html=False):
41  logger.warn(msg, html)
42 
43  def log_source(self, loglevel='INFO'):
44  self.ctxctx.log_source(loglevel)
45 
46  def assert_page_contains(self, locator, tag=None, message=None,
47  loglevel='TRACE'):
48  if not self.find_elementfind_element(locator, tag, required=False):
49  self.log_sourcelog_source(loglevel)
50  if is_noney(message):
51  message = ("Page should have contained %s '%s' but did not."
52  % (tag or 'element', locator))
53  raise AssertionError(message)
54  logger.info("Current page contains %s '%s'."
55  % (tag or 'element', locator))
56 
57  def assert_page_not_contains(self, locator, tag=None, message=None,
58  loglevel='TRACE'):
59  if self.find_elementfind_element(locator, tag, required=False):
60  self.log_sourcelog_source(loglevel)
61  if is_noney(message):
62  message = ("Page should not have contained %s '%s'."
63  % (tag or 'element', locator))
64  raise AssertionError(message)
65  logger.info("Current page does not contain %s '%s'."
66  % (tag or 'element', locator))
67 
68  def get_timeout(self, timeout=None):
69  if is_noney(timeout):
70  return self.ctxctx.timeout
71  return timestr_to_secs(timeout)
72 
73  @property
74  log_dir = property
75 
76  def log_dir(self):
77  try:
78  logfile = BuiltIn().get_variable_value('${LOG FILE}')
79  if logfile == 'NONE':
80  return BuiltIn().get_variable_value('${OUTPUTDIR}')
81  return os.path.dirname(logfile)
82  except RobotNotRunningError:
83  return os.getcwdu() if PY2 else os.getcwd()
def find_element(self, locator, tag=None, required=True, parent=None)
Find element matching locator.
Definition: context.py:72
def assert_page_not_contains(self, locator, tag=None, message=None, loglevel='TRACE')
def log(self, msg, level='INFO', html=False)
def assert_page_contains(self, locator, tag=None, message=None, loglevel='TRACE')