0
votes

I am using docker to set up a selenium testing environment. So far i have successfully downloaded and installed: selenium/hub, selenium/node-chrome and selenium/node-firefox.

Once started i can see the hub and the nodes running at 192.168.99.100:4444
So far so good.

I am then using the official python image to create a test container. This is my dockerfile:

FROM python:latest  
MAINTAINER mynanme  
RUN pip install selenium  
COPY    . /usr/src  
WORKDIR /usr/src  
ENTRYPOINT bash  

I have also recorded a python script through the IDE and i am then trying to run it:

from selenium import selenium
import unittest, time, re
class test2(unittest.TestCase):
def setUp(self):
    self.verificationErrors = []
    self.selenium = selenium("http://192.168.99.100", 4444, "*chrome", "https://www.google.at/")
    self.selenium.start()

def test_test2(self):
    sel = self.selenium
    sel.open("/?gws_rd=ssl")
    sel.type("id=lst-ib", "test2")
    sel.click("name=btnG")

def tearDown(self):
    self.selenium.stop()
    self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
unittest.main()

The only problem is that this script just doesnt work. When i run it get the following error:

Traceback (most recent call last):
File "testRC.py", line 8, in setUp
self.selenium = selenium("http://192.168.99.100", 4444, "*chrome", "https://www.google.at/")
TypeError: 'module' object is not callable

Did i miss to install something?

2
You are trying to use the selenium module incorrectly. The docs for python-selenium have a walkthrough for using it with a remote webDriver.Kevan Ahlquist
Ok i see what you mean. But as our QAT cant write python we are relying on the script the IDE creates. How would i make the script from the IDE work.user2316219
Modify the IDE so it generates a script that works? The easier path here is to learn python and follow the docs for the module you're trying to use.Kevan Ahlquist
Sorry but this is not an option for us. If the recording feature cant produce an outcome that we cant just save and rerun on the server then we cant use selenium.user2316219
you may check this https://windsooon.github.io/2017/06/14/How%20to%20use%20selenium%20with%20docker/Windsooon

2 Answers

0
votes

from http://selenium-python.readthedocs.org/getting-started.html#using-selenium-to-write-tests

import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

class PythonOrgSearch(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Firefox()

    def test_search_in_python_org(self):
        driver = self.driver
        driver.get("http://www.python.org")
        self.assertIn("Python", driver.title)
        elem = driver.find_element_by_name("q")
        elem.send_keys("pycon")
        elem.send_keys(Keys.RETURN)
        assert "No results found." not in driver.page_source


    def tearDown(self):
        self.driver.close()

if __name__ == "__main__":
    unittest.main()
0
votes

Ok thanks for pointing me to the right direction. I think i found the solution. I should have used the webdriver version to export and not the remote control.

Then i had to change the format of the python header under the options to look like this:

 from selenium import webdriver
 from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
 from selenium.webdriver.common.by import By
 from selenium.webdriver.common.keys import Keys
 from selenium.webdriver.support.ui import Select
 from selenium.common.exceptions import NoSuchElementException
 from selenium.common.exceptions import NoAlertPresentException
 import unittest, time, re

 class ${className}(unittest.TestCase):
def setUp(self):
    self.driver =      webdriver.Remote(command_executor='http://192.168.99.100:4444/wd/hub',   desired_capabilities=DesiredCapabilities.CHROME)

Now i can export my testsuites from the IDE and run them in a docker container to access the selenium grid.