2012-06-26 12 views
5

क्या कोई मुझे सेलेनियम के साथ कस्टम लाइफरे पोर्टलों को लिखने और परीक्षण करने के तरीके के बारे में जानकारी के साथ एक लिंक/दस्तावेज़ प्रदान कर सकता है।कस्टम पोर्टल के लिए सेलेनियम परीक्षण

मैं Liferay 6.1EE

धन्यवाद अन्य परीक्षणों के साथ के रूप में

+2

http://www.liferay.com/community के रूप में चलाना चाहते हैं/विकी/-/विकी/मुख्य/कैसे + रन + रन + सेलेनियम + टेस्ट –

+2

http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Selenium+Testing –

उत्तर

0

ही उपयोग कर रहा हूँ, आप यह सोचते हैं JUnit परीक्षण

package org.ood.selenium.test; 
import com.gargoylesoftware.htmlunit.BrowserVersion; 
import com.gargoylesoftware.htmlunit.IncorrectnessListener; 
import com.gargoylesoftware.htmlunit.ScriptException; 
import com.gargoylesoftware.htmlunit.WebClient; 
import com.gargoylesoftware.htmlunit.html.HtmlButton; 
import com.gargoylesoftware.htmlunit.html.HtmlPage; 
import com.gargoylesoftware.htmlunit.javascript.JavaScriptErrorListener; 
import com.thoughtworks.selenium.SeleneseTestBase; 
import com.thoughtworks.selenium.Selenium; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.htmlunit.HtmlUnitDriver; 
import org.openqa.selenium.remote.DesiredCapabilities; 
import org.openqa.selenium.By; 
import org.openqa.selenium.OutputType; 
import org.openqa.selenium.TakesScreenshot; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebDriverBackedSelenium; 
import org.apache.commons.io.FileUtils; 
import org.apache.commons.logging.LogFactory; 
import org.junit.After; 
import org.junit.Before; 
import org.junit.Test; 

import java.io.File; 
import java.net.MalformedURLException; 
import java.net.URL; 
import java.util.logging.Level; 
import java.util.regex.Pattern; 

public class MyTest extends SeleneseTestBase { 
    WebDriver driver =null; 
    @Before 
    public void setUp() throws Exception { 
     DesiredCapabilities dc = DesiredCapabilities.firefox(); 
     // dc.setCapability(FirefoxDriver.BINARY, new 
     //File("C:/Program Files (x86)/Mozilla Firefox/firefox.exe").getAbsolutePath()); 
     dc.setJavascriptEnabled(true); 
     // driver= new HtmlUnitDriver(true);//Not properly working 
     driver = new FirefoxDriver(dc); 
     String baseUrl = "http://localhost:8080/web/guest/home"; 
     selenium = new WebDriverBackedSelenium(driver, baseUrl); 
    } 

    /* @Test 
    public void homePage() throws Exception { 
     final WebClient webClient = new WebClient(); 
      //HTMLUNit throws lots of errors 
     webClient.setJavaScriptEnabled(true); 
     webClient.setJavaScriptErrorListener(new JavaScriptErrorListener() { 

      public void timeoutError(HtmlPage htmlPage, long allowedTime, 
        long executionTime) { 
       // TODO Auto-generated method stub 

      } 

      public void scriptException(HtmlPage htmlPage, 
        ScriptException scriptException) { 
       System.out.println(scriptException.getMessage()); 

      } 

      public void malformedScriptURL(HtmlPage htmlPage, String url, 
        MalformedURLException malformedURLException) { 
       System.out.println(url); 

      } 

      public void loadScriptError(HtmlPage htmlPage, URL scriptUrl, 
        Exception exception) { 
       // TODO Auto-generated method stub 

      } 
     }); 
     //webClient.setThrowExceptionOnFailingStatusCode(false); 
     webClient.setThrowExceptionOnScriptError(false); 
     final HtmlPage page = webClient.getPage("http://localhost:8080/web/guest/home"); 
     webClient.getCache().clear(); 

     page.getElementById("sign-in").click(); 
     page.getElementById("_58_login").type("[email protected]"); 
     page.getElementById("_58_password").type("[email protected]"); 
     final HtmlButton submit = (HtmlButton)page.getByXPath("//input").get(0); 
     submit.click(); 


     //assertEquals("HtmlUnit - Welcome to HtmlUnit", page.getTitleText()); 

     System.out.println("Title= " +page.getTitleText()); 
     final String pageAsXml = page.asXml(); 
     // assertTrue(pageAsXml.contains("<body class=\"composite\">")); 
     System.out.println("pageAsXml=" +pageAsXml); 

     final String pageAsText = page.asText(); 
     //assertTrue(pageAsText.contains("Support for the HTTP and HTTPS protocols")); 

     System.out.println("pageAsText="+pageAsText); 
     webClient.closeAllWindows(); 
    }*/ 

    @Test //Using Graphical GUI 
    public void testMytest() throws Exception { 

     //driver.get("http://localhost:8080/web/guest/home"); 

     selenium.open("/"); 
     //selenium.click("id=sign-in"); 
     driver.findElement(By.id("sign-in")).click(); 
     driver.findElement(By.name("_58_login")).clear(); 
     driver.findElement(By.name("_58_login")).sendKeys("[email protected]"); 
     driver.findElement(By.name("_58_password")).sendKeys("123"); 
     //driver.findElement(By.name("_58_login")).sendKeys("[email protected]"); 
     //driver.findElement(By.name("_58_password")).sendKeys("test"); 
     driver.findElement(By.className("aui-button-input-submit")).submit(); 
     //selenium.setSpeed("1000"); 
     //selenium.waitForPageToLoad("5000"); 
     //Select a nested div(the NodeTree) 
     driver.findElement(By.xpath("//div[contains(@class,'aui-tree-node-content')" + 
       " and (contains(.,'TreeNodeX'))]//div[contains(@class,'aui-tree-hitarea')]")) 
       .click(); 
     //selenium.captureScreenshot("d:/_del/sel_screen.png");//this throws an error 
     //workaround 
     File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); 
     FileUtils.copyFile(scrFile, new File("d:/_del/sel_screen.png")); 

     System.out.println("Bodytex=[" +selenium.getBodyText() +"]End Body Text"); 

     String[] titles= selenium.getAllWindowTitles(); 
     System.out.println("Titles Start-"); 
     for (int i = 0; i < titles.length; i++) { 
      System.out.println(titles[i]); 
     } 
     System.out.println("Titles End"); 
     verifyEquals(true, selenium.getBodyText().contains("Site View")); 
    } 

    @After 
    public void tearDown() throws Exception { 
     selenium.stop(); 
    } 


} 
संबंधित मुद्दे