SeleniumHQ / selenium-google-code-issue-archive

Archive, please see main selenium repo
https://github.com/seleniumhq/selenium
346 stars 194 forks source link

In Selenium IDE, User Format exports sendKeys ${KEY_ENTER} into Java code of which javac complains "ENTER cannot be resolved to a variable" #7118

Open lukeis opened 8 years ago

lukeis commented 8 years ago

Originally reported on Google Code with ID 7118

Description
===========
With Selenium IDE 2.5.0, I created a User Format by copy-and-pasting the source of
the Java/JUnit4/WebDriver Plugin Format. Also I created a testcase which invokes selenese
sendKeys command with an argument which contains ${KEY_ENTER} symbol. I exported my
testcase using the User Format to get a Java/JUnit4/WebDriver source. But the javac
failed to compile the exported source complaining that "ENTER cannot be resolved to
a variable". I want my User Format to speak valid Java. I want it to emit Keys.ENTER
for the selenese ${KEYS_ENTER} symbol, rather than emitting invalid ENTER. 

Steps to reproduce
==================
I use Selenium IDE 2.5.0 on Firefox 28.0 on Mac OS X 10.9.2. I use Eclipse Kepler Service
Release 2 as Java IDE.  The source code I created in selenese is as follows:

----------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://www.yahoo.co.jp/" />
<title>TopPageTest</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">TopPageTest</td></tr>
</thead><tbody>
<tr>
    <td>setTimeout</td>
    <td>5000</td>
    <td></td>
</tr>
<tr>
    <td>open</td>
    <td>/</td>
    <td></td>
</tr>
<tr>
    <td>waitForTitle</td>
    <td>Yahoo! JAPAN</td>
    <td></td>
</tr>
<tr>
    <td>assertElementPresent</td>
    <td>id=srchtxt</td>
    <td></td>
</tr>
<tr>
    <td>sendKeys</td>
    <td>id=srchtxt</td>
    <td>selenium${KEY_ENTER}</td>
</tr>
<tr>
    <td>waitForTitle</td>
    <td>*selenium*</td>
    <td></td>
</tr>
<tr>
    <td>waitForElementPresent</td>
    <td>css=div#WS2m</td>
    <td></td>
</tr>
<tr>
    <td>assertText</td>
    <td>css=div#WS2m a</td>
    <td>*Web Browser Automation*</td>
</tr>
<tr>
    <td>close</td>
    <td></td>
    <td></td>
</tr>
</tbody></table>
</body>
</html>

Also I created a User Format, which has just the same source code as the Java/JUnit4/WebDriver
Plugin Format. 

Expected
========
Exporting the testcase with my User Format should emit a valid Java code for sendKeys
command. It should be like:

    -------------------------------------------------------------------------
    driver.findElement(By.id("srchtxt")).sendKeys("selenium" + Keys.ENTER);

Actual
======
My User Format generated the follwoing source:

    -------------------------------------------------------------------------
    driver.findElement(By.id("srchtxt")).sendKeys("selenium" + ENTER);
                                                               ^^^^^

The java compiler fails complaining that "ENTER cannot be resolved to a variable".

My Analysis
===========
I downloaded the Selenium project from the Git repository and studied it trying to
find the cause of my problem.

In the git/ide/plugins/java-format/src/content/formats/webdriver-junit4.js I found
this:

    -----------------(line 153)----------------
    function keyVariable(key) {
        return "Keys." + key;
    }

On the otherhands, in the git/ide/main/src/content/formats/webdriver.js I found the
following:

    -----------------(line 254)----------------
    function keyVariable(key) {
        return variableName(key);
    }

    -----------------(line 362)----------------    
    function variableName(value) {
        return value;
    }

This difference seems to be the cause of my "ENTER cannot be resolved to a variable"
problem.

What I tried
============

I wanted to prove my idea, so I editted the git/ide/main/src/content/formats/webdriver.js
to make its keyVariable function same as webdriver-junit4.js. I tried to build by:

> cd {dir_cloned_from_the_project_repository}
> ./go

Unfortunately I got the "go" script aborted as follows.

-------------------------------------------------
...
Testing: //javascript/atoms:test_ff 
Testing: //javascript/atoms:test_safari 
go aborted!
org.apache.tools.ant.BuildException: Test org.openqa.selenium.javascript.ClosureTestSuite
failed

(See full trace by running task with --trace)
-------------------------------------------------

I could not fix this abortion due to my lack of experience.

Also I tried to manually patch the Selenium IDE xpi file installed in the  FireFox.
But I could not start the patched Selenium IDE because the starter button was not shown
in the Firefox command bar. 

I gave it up.

kazurayam (kazuaki,MATSUHASHI)

Reported by kazuaki.urayama on 2014-03-23 01:26:18

lukeis commented 8 years ago

Reported by luke.semerau on 2014-03-23 21:34:01

lukeis commented 8 years ago

Reported by luke.semerau on 2015-09-17 17:46:33