#眉標=Ajax #副標=AJAX開發工具(4) #大標=AJAX網頁測試自動化 #作者=文/沈炳宏 ==程式1 =========== dom=document.forms['myForm'].myDropdown dom=document.images[56] ================ ==程式2 =========== xpath=//img[@alt='The image alt text'] xpath=//table[@id='table1']//tr[4]/td[2] xpath=//div[@id='workflowMenu']//a [@id='goToPreviousStatus']/ ================ ==程式3 =========== test
test
open /index.aspx
clickAndWait link=回首頁
clickAndWait //tr[8]/td[2]/a/span
assertTextPresent 編輯
================ ==程式4 ===========
Test Suite
test for run!pc
================ ==程式5 =========== package com.runpc.ajax; import org.openqa.selenium.server.SeleniumServer; import com.thoughtworks.selenium.DefaultSelenium; import com.thoughtworks.selenium.SeleneseTestCase; import com.thoughtworks.selenium.Selenium; public class HelloWorldTest extends SeleneseTestCase { … } ================ ==程式6 =========== private Selenium selenium; public void setUp() throws Exception { String url = "http://localhost:9999"; selenium = new DefaultSelenium("localhost", SeleniumServer.getDefaultPort(), "*firefox", url); selenium.start(); } public void tearDown() throws Exception { selenium.stop(); } ================ ==程式7 =========== public void testHelloButton() throws Exception { selenium.open( "/com.runpc.gwt.HelloGWT/HelloGWT.html"); selenium.click("link=index"); selenium.waitForPageToLoad("30000"); selenium.click("//button[@type='button']"); String script = "var value = selenium.getText( \"//table/tbody/tr/td[@id='slot2']/div\"); value == \"Hello World!\""; selenium.waitForCondition(script, "30000"); } ================