Create Your own UI modules and Test Cases
Tellurium provides TrUMP for you to automatically create UI modules. TrUMP can be download from Tellurium project site
http://code.google.com/p/aost/downloads/list
Choose the Firefox 2 or Firefox 3 version depending on your Firefox version. Or you can download the Firefox 3 version directly from Firefox addons site at
https://addons.mozilla.org/en-US/firefox/addon/11035
Once you install it and restart Firefox, you are ready to record your UI modules by simply clicking on the UI element on the web and then click the "generate" button. You may like to customize your UI a bit by clicking the "Customize" button. More detailed TrUMP introductions can be found at
http://code.google.com/p/aost/wiki/TrUMP
and
http://code.google.com/p/aost/wiki/HowTrUMPWorks
In our example, we open up Tellurium download page
http://code.google.com/p/aost/downloads/list
and record the download search module as follows
LRuVAwbLjuTZtSqonpmmrv0I-p7nCVZQmP65Tb_vjspK02CR95VRrtmeQ&gsc=r5ESUAsAAAB_6XgBAY-OTO2KhvY2ZJUe">
After we customize the UI module, we export it as the module file NewUiModule.groovy to the demo project and add couple methods to the class.
class NewUiModule extends DslContext {
public void defineUi() {
ui.Form(uid: "TelluriumDownload", clocator: [tag: "form", method: "get", action: "list"], group: "true") {
Selector(uid: "DownloadType", clocator: [tag: "select", name: "can", id: "can"])
InputBox(uid: "Input", clocator: [tag: "input", type: "text", name: "q", id: "q"])
SubmitButton(uid: "Search", clocator: [tag: "input", type: "submit", value: "Search"])
}
}
//Add your methods here
public void searchDownload(String keyword) {
keyType "TelluriumDownload.Input", keyword
click "TelluriumDownload.Search"
waitForPageToLoad 30000
}
public String[] getAllDownloadTypes() {
return getSelectOptions("TelluriumDownload.DownloadType")
}
public void selectDownloadType(String type) {
selectByLabel "TelluriumDownload.DownloadType", type
}
}
Then, create a new Tellurium test case NewTestCase by extending TelluriumJavaTestCase class.
public class NewTestCase extends TelluriumJavaTestCase {
private static NewUiModule app;
@BeforeClass
public static void initUi() {
app = new NewUiModule();
app.defineUi();
}
@Before
public void setUpForTest() {
connectUrl("http://code.google.com/p/aost/downloads/list");
}
@Test
public void testTelluriumProjectPage() {
String[] allTypes = app.getAllDownloadTypes();
assertNotNull(allTypes);
assertTrue(allTypes[1].contains("All Downloads"));
app.selectDownloadType(allTypes[1]);
app.searchDownload("TrUMP");
}
}
Compile the project and run the new test case.
Tellurium TestNG Project
If you want to create a new Tellurium TestNG project, simply use a different Maven archetype as follows,
mvn archetype:create -DgroupId=example -DartifactId=demo -DarchetypeArtifactId=tellurium-testng-archetype -DarchetypeGroupId=tellurium -DarchetypeVersion=1.0-SNAPSHOT
and the new Tellurium test case should extend TelluriumTestNGTestCase class. The rest are the same as the JUnit ones.
Resources
The slides for this tutorial is available at
http://aost.googlecode.com/files/Ten.Minutes.To.Tellurium.pdf
The Screencast video is available at
http://aost.googlecode.com/files/TenMinutesToTellurium.ogg
Here is the online version
The generated Demo project can be downloaded from here or check it out from Subversion
http://aost.googlecode.com/svn/branches/ten-minutes-to-tellurium/
文章来源于领测软件测试网 https://www.ltesting.net/