동료와 나는 Selenium이 groovy로 작업하기 위해 며칠 동안 노력했다. 전혀 성공하지 못했다. 우리는 자바와 아무런 문제가없는 복잡한 테스트를 할 수있다. 그러나 아무 것도 그루비 (groovy)에서 작동하지 않는다. 우리는 끔찍한 컴파일 오류가 발생합니다 ..... 우리는 모든 종류의 "잡아"및 "가져 오기"구문을 시도했지만 아무것도 작동하지 않습니다.groovy로 작업 할 셀렌을 얻을 수 없다
특히 :
패키지 test_groovy_project
@Grab(group='org.springframework', module='spring-orm', version='3.2.5.RELEASE')
import org.springframework.jdbc.core.JdbcTemplate
import groovy.grape.Grape
// @Grab(group="org.seleniumhq.selenium", module="selenium-java", version="2.53.0")
@Grab(group="org.seleniumhq.selenium", module="selenium-java", version="2.53.0")
@Grab(group="org.seleniumhq.selenium", module="selenium-firefox-driver", version="2.53.0")
@Grab(group="org.seleniumhq.selenium", module="selenium-support", version="2.53.0")
//@Grab(group:"org.seleniumhq.selenium", module:"selenium-firefox-driver", version:"2.53.0")
//@Grab(group:"org.seleniumhq.selenium", module:"selenium-support", version:"2.53.0")
@Grab('org.seleniumhq.selenium:selenium-java:2.53.0')
import org.openqa.selenium.*
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebDriver.*
import org.openqa.selenium.By
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxDriver.*
class Groovy_test_class {
static main(args) {
System.setProperty("webdriver.firefox.bin","C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
// System.setProperty("webdriver.firefox.bin","C:\\Users\\Shamsur.Masum\\AppData\\Local\\Mozilla Firefox\\firefox.exe");
WebDriver driver= new FirefoxDriver();
driver.get("http://www.google.com/");
driver.findElement(by.name("ctl00$cphMainContent$txtUserName")).sendKeys("");
}
}
예 결과 :
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
C:\Users\charles\workspace\test_groovy_project\src\test_groovy_project\Groovy_test_class.groovy: 32: Apparent variable 'by' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
You attempted to reference a variable in the binding or an instance variable from a static context.
You misspelled a classname or statically imported field. Please check the spelling.
You attempted to use a method 'by' but left out brackets in a place not allowed by the grammar.
@ line 32, column 22.
driver.findElement(by.name("ctl00$cphMainContent$txtUserName")).sendKeys("");
^
C:\Users\charles\workspace\test_groovy_project\src\test_groovy_project\Groovy_test_class.groovy: 32: Apparent variable 'cphMainContent' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
You attempted to reference a variable in the binding or an instance variable from a static context.
You misspelled a classname or statically imported field. Please check the spelling.
You attempted to use a method 'cphMainContent' but left out brackets in a place not allowed by the grammar.
@ line 32, column 37.
driver.findElement(by.name("ctl00$cphMainContent$txtUserName")).sendKeys("");
^
두 번째 오류는 Groovy 보간 문자열을 이해하지 못하기 때문에 발생합니다. "$ cphMainContent"부분 문자열은 해당 이름으로 변수를 찾으려고합니다. 이중 따옴표를 작은 따옴표로 바꾸면 해제 할 수 있습니다. 어떤 경우라도 일반적으로 Groovy의 Selenium을 "geb"로 사용합니다. –
첫 번째로'by'는 대문자'B'를 필요로합니다 –
FYI 그루비'$'안에''''는 코드 나 변수를 주소 지정하는 데 사용됩니다 ... 그래서 요소 이름에'$'... 'ctl00 \ "$ cphMainContent \"$ txtUserName' ... 두 번째로'by.name'을'By.name'으로 사용합니다 .. –