Ejemplo n.º 1
0
 def setUpClass(cls):
     cls.driver = webdriver.WebDriver(
         command_executor='http://selenium:4444/wd/hub',
         desired_capabilities=DesiredCapabilities.CHROME)
     cls.driver.implicitly_wait(0.3)
     cls.wait = WebDriverWait(cls.driver, 1)
     super().setUpClass()
Ejemplo n.º 2
0
    def setUp(self):

        self.driver = \
            webdriver.WebDriver(command_executor="http://10.0.0.4:4444/wd/hub",desired_capabilities=DesiredCapabilities.FIREFOX)
        self.driver.get('http://demo-store.seleniumacademy.com/')
        self.driver.implicitly_wait(30)
        self.driver.maximize_window()
Ejemplo n.º 3
0
 def _setUp(self):
     self.expectPort(self.allocatePort())
     self.addDataDir()
     super(PhantomJS, self)._setUp()
     url = "http://localhost:%d/wd/hub" % self.protocol.expectedPort
     self.webdriver = webdriver.WebDriver(
         command_executor=url,
         desired_capabilities=self.desiredCapabilities)
Ejemplo n.º 4
0
def create_webdriver():
    if WEBDRIVER_TYPE == 'CHROME':
        return chrome.WebDriver()

    if WEBDRIVER_TYPE == 'REMOTE_CHROME':
        return remote.WebDriver(command_executor='http://selenium:4444/wd/hub',
                                options=webdriver.ChromeOptions())

    raise Exception(f"bad webdriver type {WEBDRIVER_TYPE}")
Ejemplo n.º 5
0
def new_webdriver_session(capabilities={}):
  """Provisions a new WebDriver session.

  Args:
    capabilities: a dict with the json capabilities desired for this browser
      session.

  Returns:
    A new WebDriver connected to a browser defined by the web test
    environment.
  """
  address = os.environ['WEB_TEST_WEBDRIVER_SERVER'].rstrip('/')

  # Set the timeout for WebDriver http requests so that the socket default
  # timeout is not used.
  remote_connection.RemoteConnection.set_timeout(450)

  return webdriver.WebDriver(address, desired_capabilities=capabilities)
Ejemplo n.º 6
0
    def new_session(self, capabilities=None):
        """Provisions a new WebDriver session.

    Args:
      capabilities: a dict with the json capabilities desired for this browser
        session.

    Returns:
      A new WebDriver connected to a browser defined by the web test
      environment.
    """
        if capabilities:
            desired = capabilities.copy()
        else:
            desired = {}

        # Set the timeout for WebDriver http requests so that the socket default
        # timeout is not used.
        remote_connection.RemoteConnection.set_timeout(450)
        return webdriver.WebDriver("http://%s/wd/hub" % self._address,
                                   desired_capabilities=desired)
def remote_webdriver(desired_capabilities, implicit_wait=15):
    command_executor_url = get_command_executor_url(
        host=os.environ.get('SELENIUM_HOST', 'localhost'),
        path=os.environ.get('SELENIUM_PATH', 'wd/hub'),
        port=int(os.environ.get('SELENIUM_PORT', '4444')),
        user=os.environ.get('SELENIUM_USER', 'nobody'),
        passwd=os.environ.get('SELENIUM_PASSWORD', 'password'))

    proxy_capabilities(desired_capabilities, PROXY_URL)

    driver = webdriver.WebDriver(
        desired_capabilities=desired_capabilities,
        command_executor=command_executor_url,
    )

    driver.implicitly_wait(implicit_wait)

    try:
        yield driver
    finally:
        driver.quit()
Ejemplo n.º 8
0
def before_all(context):
    context.browser = webdriver.WebDriver(
        WEBDRIVER_URL, desired_capabilities=DESIRED_CAPABILITIES)
Ejemplo n.º 9
0
from selenium.webdriver.remote import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.common.exceptions import  TimeoutException

wd=webdriver.WebDriver(command_executor="http://192.168.31.110:4444/wd/hub",desired_capabilities=DesiredCapabilities.CHROME)

wd.get('https://www.baidu.com')
div=wd.find_element_by_class_name('s_form_wrapper')
subdiv=div.find_element_by_id('lg')
form=div.find_element_by_css_selector('#form')
print(div.get_attribute('name'))
print(div.id)
print(div.is_displayed())
print(div.is_enabled())
if subdiv.parent==form.parent:
    print("same")
else:
    print("not same")
print(div.text)

kw=wd.find_element_by_id('kw')
kw.send_keys("selenium")
print(kw.get_attribute('value'))

wd.get("file:///C:/Users/tud/GitHub/selenium/list.html")
selectLang=wd.find_element_by_css_selector('#lang')
options=selectLang.find_elements_by_tag_name('option')
Ejemplo n.º 10
0
 def setUpClass(cls):
     cls.driver = webdriver.WebDriver(
         command_executor='http://selenium:4444/wd/hub',
         desired_capabilities=DesiredCapabilities.CHROME)
     super().setUpClass()