问题:鼠标右键如何测试?

使用 selenuim2library 如何测试鼠标右键单击?我使用的是smartclient组件

以下面的页面为例

http://smartclient.com/#cellClicks

右键单击表格中第一行,弹出对话框。

执行测试用例的命令行参数如下:

-d out -v WEBSERVERIP:smartclient.com -v WEBSERVERIP_PORT:80 -v BROWSERTYPE:gc  -v BROWSERHUB:10.10.10.10 -v BROWSERHUB_PORT:4444

 

下面是测试用例,始终报 “右键未弹出对话框”

*** Setting ***
Suite Setup 打开浏览器到起始页面
Suite Teardown 关闭所有浏览器
Default Tags smartclient
Library Selenium2Library run_on_failure=Nothing implicit_wait=0
Library Collections
Library OperatingSystem
Library String
Library DatabaseLibrary

*** Variable ***
#${WEBSERVERIP} smartclient.com #被测系统IP
#${WEBSERVERIP_PORT} 80 #被测系统WEB端口
#${BROWSERTYPE} gc #使用的WEB浏览器类型
#${BROWSERHUB} 10.10.10.10 #使用的WEB浏览器集线器
#${BROWSERHUB_PORT} 4444 #使用的WEB浏览器集线器端口
${WEBSERVER} ${WEBSERVERIP}:${WEBSERVERIP_PORT}
${BROWSER} ${BROWSERTYPE}
${REMOTE_URL} http://${BROWSERHUB}:${BROWSERHUB_PORT}/wd/hub
${DESIRED_CAPABILITIES} ${NONE}
${ROOT} http://${WEBSERVER}
${FRONT PAGE} ${ROOT}/#cellClicks
${gtimeout} 5sec

*** Test Cases ***
测试鼠标右键
Wait Until Page Contains Element xpath=//tbody/tr/td/descendant::nobr[contains(text(),”United States”)] 10 超时页面未打开
Click Element xpath=//tbody/tr/td/descendant::nobr[contains(text(),”United States”)]
Open Context Menu xpath=//tbody/tr/td/descendant::nobr[contains(text(),”United States”)]
#Right Click Element xpath=//tbody/tr/td/descendant::nobr[contains(text(),”United States”)]
Wait Until Page Contains Element xpath=//table/tbody/tr/td[starts-with(text(),”Context-clicked”)] ${gtimeout} 右键未弹出菜单

*** Keyword ***
打开浏览器到起始页面
运行在IE?
运行在FireFox?
运行在Chrome?
Open Browser ${FRONT PAGE} ${BROWSER} remote_url=${REMOTE_URL} desired_capabilities=${DESIRED_CAPABILITIES}
Maximize Browser Window

前往起始页面
Go To ${FRONT PAGE}

前往页面 “${relative url}”
Go To ${ROOT}/${relative url}

设置日志级别为${level}
Set Log Level ${level}

验证URL是 “${relative url}”
Location Should Be ${ROOT}/${relative url}

关闭所有浏览器
Unselect Frame
sleep 200milliseconds
Close All Browsers

运行在IE?
${runsInTmp}= Set Variable If “${BROWSER}”.replace(‘ ‘, ”).lower() in [‘ie’, ‘*iexplore’, ‘internetexplorer’] ${TRUE} ${FALSE}
Set Global Variable ${runsInIE} ${runsInTmp}

运行在FireFox?
${runsInTmp}= Set Variable If “${BROWSER}”.replace(‘ ‘, ”).lower() in [‘ff’, ‘*firefox’] ${TRUE} ${FALSE}
Set Global Variable ${runsInFireFox} ${runsInTmp}

运行在Chrome?
${runsInTmp}= Set Variable If “${BROWSER}”.replace(‘ ‘, ”).lower() in [‘gc’, ‘*chrome’, ‘googlechrome’] ${TRUE} ${FALSE}
Set Global Variable ${runsInChrome} ${runsInTmp}

8 Replies to “问题:鼠标右键如何测试?”

  1. 1.打开Python27Libsite-packagesrobotframework_selenium2library-1.2.0-py2.7.eggSelenium2Librarykeywords目录(由于我是通过easy_install安装的)
    2.edit _element.py文件
    3.增加下面这段代码
    def right_click_element(self, locator):
    “””Right click element identified by `locator`.

    Key attributes for arbitrary elements are `id` and `name`. See
    `introduction` for details about locating elements.
    “””
    self._info(“Right-clicking element ‘%s’.” % locator)
    self._element_find(locator, True, True).context_click()

    1. 我使用Selenium2Library 1.2.0版本,相应的selenium用2.33.0

      _element.py文件中 open_context_menu 定义如下:

      def open_context_menu(self, locator):
      “””Opens context menu on element identified by `locator`.”””
      element = self._element_find(locator, True, True)
      ActionChains(self._current_browser()).context_click(element).perform()

      我试了chrome27 ie9,chrome 没有任何反应,ie9上弹出的是浏览器右键菜单

  2. Chrome26,如下的测试运行结果是pass。

    *** Settings ***
    Library Selenium2Library

    *** Test Cases ***
    context
    open browser http://smartclient.com/#cellClicks chrome
    Wait Until Page Contains Element xpath=//tbody/tr/td/descendant::nobr[contains(text(),”United States”)] 60 超时页面未打开
    Click Element xpath=//tbody/tr/td/descendant::nobr[contains(text(),”United States”)]
    Open Context Menu xpath=//tbody/tr/td/descendant::nobr[contains(text(),”United States”)]
    Wait Until Page Contains Element xpath=//table/tbody/tr/td[starts-with(text(),”Context-clicked”)] 5sec 右键未弹出菜单

    1. 经过测试和chrome版本没有关系,问题在chromedriver上,如果使用chromedriver_win_26.0.1383.0版本在chrome26、27都是正确的。使用chromedriver2就有问题,应该是chromedriver故障,不过chromedriver网站上,chromedriver_win_26.0.1383.0版本是不推荐使用,废除状态。

      另一个问题,在IE上始终弹出的是浏览器的右键菜单,我使用的IEDriverServer版本是 2.32.3 和 2.33.0,两个版本都不行,不知道如何解决

发表评论

电子邮件地址不会被公开。 必填项已用*标注