Selenium2Library 1.0 - Suite Teardown/Test Teardown problem using chrome/win7

3,393 views
Skip to first unread message

ElizaLeong

unread,
Jun 25, 2012, 11:54:46 PM6/25/12
to robotframe...@googlegroups.com
Hi,

I've been baffled by why this simple setup is failing on me, hope someone here can shed some light. 

My goal is to be able to run all the testcases in every test suite, and if a testcase fails in one suite, RF should allow the other tests and any subsequent test suites to run with a fresh browser session.  My test teardown is not working correctly when one testcase fails (both Close All Browsers and Close Browser did not work for me).  Log and code samples attached below.

My test structure is this:

keywords/
        common.txt
test_scripts/
        __init__.txt
        feature1/
               testsuite1/
                      testcase1.txt
               testsuite2/
                      testcase2.txt
------------------------------------------------------------------
common.txt contains this:

*Settings*  
Library         Selenium2Library

*Keyword *      
My Test Setup 
            Log My Test Setup
            Open Browser  http://www.cnn.com  browser=gc
            Maximize Browser Window
            Delete All Cookies
            Sleep 5
My Test Teardown
            Sleep 5
            Close Browser
------------------------------------------------------------------
__init__.txt contains this:
*** Settings***              
Resource            ${CURDIR}/../../keywords/common.txt
Suite Setup        My Suite Setup
Suite Teardown   My Suite Teardown
Test Setup         My Test Setup
Test Teardown    My Test Teardown

*** Variables ***      
${GOTO}           http://www.cnn.com

*Keyword*
My Suite Setup
              Log my suite setup
              Set Selenium Timeout 60
My Suite Teardown
              Log my suite tear down
              Close All Browsers

--------------------------------------------------
All the testcase*.txt have similar content (I purposely cause failures to force the test teardown/suite teardown problem):

*Settings*
Resource           ${CURDIR}/../../../keywords/common.txt
Test Setup         My Test Setup
Test Teardown   My Test Teardown

*Test Cases*
Simple Test 1.1
           Page Should Contain Loan
           Sleep 2
Simple Test 1.2
           Page Should Contain Weather
          Sleep 2

-------------------------------------------
I ran the test with loglevel set to trace.  The page does not contain the word 'Loan' and it fails as I had intended.
Robot tries to capture page screenshot because the page does not contain 'Loan', but it cannot take screenshot, and then close browser call also fails.
Why is it doing that?

20:01:13.582 DEBUG Closing browser with session id 83a06c543af1f09c208982d1ec1de7ae
20:01:13.582 DEBUG DELETE http://127.0.0.1:49592/session/83a06c543af1f09c208982d1ec1de7ae {"sessionId": "83a06c543af1f09c208982d1ec1de7ae"}
20:02:08.942 WARN Keyword 'Capture Page Screenshot' could not be run on failure: URLError: <urlopen error [Errno 10061] No connection could be made because the target machine actively refused it>
20:02:08.952 FAIL WindowsError: [Error 5] Access is denied
20:02:08.952 DEBUG Traceback (most recent call last):
  File "<string>", line 2, in close_browser
  File "C:\Python27\lib\site-packages\Selenium2Library\keywords\keywordgroup.py", line 12, in _run_on_failure_decorator
    return method(*args, **kwargs)
  File "C:\Python27\lib\site-packages\Selenium2Library\keywords\_browsermanagement.py", line 50, in close_browser
    self._cache.close()
  File "C:\Python27\lib\site-packages\Selenium2Library\utils\browsercache.py", line 23, in close
    browser.quit()
  File "C:\Python27\lib\site-packages\selenium-2.20.0-py2.7.egg\selenium\webdriver\chrome\webdriver.py", line 76, in quit
    self.service.stop()
  File "C:\Python27\lib\site-packages\selenium-2.20.0-py2.7.egg\selenium\webdriver\chrome\service.py", line 94, in stop
    os.kill(self.process.pid, signal.SIGTERM)


rob@tm

unread,
Jun 27, 2012, 2:02:20 AM6/27/12
to robotframe...@googlegroups.com

I have been encountering the very same issue, but only sporadically - I can't reproduce it on demand. Attached file contains part of output captured via debug option -b. This only ever occurs in Chrome (currently using version 20.0.1132.43 with Chromedriver 20.0.1133) and only on the teardown step after a test has failed. I am currently using 2.7.1 with Selenium2Library version 1.0.1. There does not appear to be any pattern that causes this to occur - it happens in different tests and in different suites. 

Keyword 'Capture Page Screenshot' could not be run on failure: URLError: <urlopen error [Errno 10061] No connection could be made because the target machine actively refused it>
WindowsError: [Error 5] Access is denied
Traceback (most recent call last):
  File "<string>", line 2, in close_browser
  File "C:\Python27\lib\site-packages\robotframework_selenium2library-1.0.1-py2.7.egg\Selenium2Library\keywords\keywordgroup.py", line 12, in _run_on_failure_decorator
    return method(*args, **kwargs)
  File "C:\Python27\lib\site-packages\robotframework_selenium2library-1.0.1-py2.7.egg\Selenium2Library\keywords\_browsermanagement.py", line 50, in close_browser
    self._cache.close()
  File "C:\Python27\lib\site-packages\robotframework_selenium2library-1.0.1-py2.7.egg\Selenium2Library\utils\browsercache.py", line 23, in close
    browser.quit()
  File "C:\Python27\lib\site-packages\selenium-2.23.0-py2.7.egg\selenium\webdriver\chrome\webdriver.py", line 82, in quit
    self.service.stop()
  File "C:\Python27\lib\site-packages\selenium-2.23.0-py2.7.egg\selenium\webdriver\chrome\service.py", line 94, in stop
    os.kill(self.process.pid, signal.SIGTERM)
debuglines.txt

ElizaLeong

unread,
Jun 27, 2012, 12:32:14 PM6/27/12
to robotframe...@googlegroups.com
I trimmed down the problem to just this one test.txt and Suite Teardown always fails.  The website URL appears to make a difference as some website work fine all the time while others fail all the time.

If browser=chrome is changed to browser=firefox then Close All Browsers work correctly.

Conclusion: this appears to be a chromedriver bug
 
(I ran this with pybot --loglevel trace test.txt)

| *Settings* | *Value* |
| Library     | Selenium2Library | timeout=10 | run_on_failure=Nothing |
| Test Setup    | My Test Setup |
| Test Teardown | My Test Teardown |
| Suite Setup | My Suite Setup |
| Suite Teardown | My Suite Teardown |

| *Keyword* | *Action* | *Argument* |
| My Test Setup |
| |  Log |  My Test setup |

| My Test Teardown |
| |  Log | My Test Teardown |


| My Suite Setup |
| |  Log | My Suite Setup ran |
| |  Set Selenium Timeout | 10 |
| |  Open Browser |  http://www.nytimes.com  |  browser=chrome |
| |  Maximize Browser Window |
| |  Delete All Cookies |

| My Suite Teardown |
| | Log | My Suite Teardown ran |
| | Close All Browsers  |

| ***Testcases*** |
| Simple Test 1.1 |
| | Page Should Contain | BART |


| Simple Test 1.2 |
| | Log | Current directory is ${CURDIR} |
| | Page Should Contain | Weather |

rob@tm

unread,
Jun 27, 2012, 9:30:49 PM6/27/12
to robotframe...@googlegroups.com
Have you checked your Chromedriver file properties? I noticed that I was only getting this failure on my testing rig. When I looked at the chromedriver.exe file properties (General tab) there was an Unblock button present that wasn't there on my desktop machine. I had copied chromedriver.exe onto the test box on a usb stick and it seems that Windows 7 had put some sort of block on it. I ran my test suite after unblocking chromedriver, and it ran without incident. 

ElizaLeong

unread,
Jul 10, 2012, 11:13:06 PM7/10/12
to robotframe...@googlegroups.com

To update this thread with some recent investigation:

I unblocked chromedriver.exe, but Close All Browsers still didn't pass consistantly.

By the way I'm testing on a Win7 VM (host is MAC OSX), not sure if that makes a difference.

Since ACCESS DENIED may be a permission related issue, I also made 2 changes:
- changed chromedriver.exe to run as administrator (applied it to all users.)
- lowered User Account Control setting (UAC) on my Win7, + unchecked the security messages for UAC.

How are other users configuring their Win7 VMs to run with robot framework in chromedriver?   

Mariya Nikolova

unread,
Jul 11, 2012, 7:03:38 AM7/11/12
to elc....@gmail.com, robotframe...@googlegroups.com
Hi

I had the same problem, but only when I run my test suite via Jenkins. The os on the machine is Win28k. When I run my suite locally I don't have the problem.

By searching the reason for this I have found that in the method stop in service.py for chrome browser there is this code:
#Tell the Server to properly die in case
        try:
            if self.process:
                os.kill(self.process.pid, signal.SIGTERM)
                os.wait()
        except AttributeError:
            # kill may not be available under windows environment
            pass


Line 91-98

I have changed this code to differentiate between posix and other os like this:

#Tell the Server to properly die in case
            if (os.name == "posix"):
                try:
                    if self.process:
                        #os.kill(pid, signal.SIGKILL)
                        os.kill(self.process.pid, signal.SIGTERM)
                        os.wait()
                except AttributeError:
                    # kill may not be available under windows environment
                    pass
            else:

                # windows
                try:
                   if self.process:
                        handle = subprocess.Popen(self.process.pid, shell=False)
                        subprocess.Popen("taskkill /F /T /PID %i"%handle.pid , shell=True)
                except AttributeError:
                    # kill may not be available under windows environment
                    pass
              
and the problem is solved.

As I a new in Python I just flicker the code. So if someone has better idea, please share. Also to differ more os types can be added if wished.

Regards

Mariya

2012/7/11 ElizaLeong <elc....@gmail.com>
--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/robotframework-users/-/yrxCS_bAcLUJ.

To post to this group, send email to robotframe...@googlegroups.com.
To unsubscribe from this group, send email to robotframework-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/robotframework-users?hl=en.

ElizaLeong

unread,
Jul 13, 2012, 2:19:10 PM7/13/12
to robotframe...@googlegroups.com

Thanks for everyone's help. I'm on Python 27 which is supposed to support os.kill for Windows, and there are 2 Windows specific signals that Python2.7 introduced for this.  Passing in UNIX type of signal.SIGTERM caused the problem for me.

So, I got it to work by fixing selenium\webdriver\chrome\service.py to send in signal.CTRL_BREAK_EVENT when the os.name=="nt".

I did not need to change any permissions, just took the default settings.

Someone else arrived at the same solution for IE driver with Python binding.

Kuldeep Khandelwal

unread,
Sep 25, 2013, 5:29:34 AM9/25/13
to robotframe...@googlegroups.com
Hi

I am observing this same error with Firefox 19 (which is very well supported with Robot Framework). It is not consistent but fails the suite teardown when browser instance 1 is not accessed for a long with automation suite.

Is there any fixes on this  ?

Python 2.7 on win 32 and Robot framework 2.8 rc1

Thanks,
kuldeep
Reply all
Reply to author
Forward
0 new messages