1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
| package demo;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
public class SeleniumDemo {
public static void main(String[] args) throws InterruptedException {
// 创建一个 Selenium 实例
Selenium selenium = new DefaultSelenium("localhost", 4444, \
"*firefox", "https://apps.na.collabserv.com/");
// 启动 selenium session
selenium.start();
// 打开测试网页
selenium.open("https://apps.lotuslive.com/");
// 输入用户名,密码
selenium.type("//input[@id='username']", \
"autouser01@e3yunmail.mail.lotuslive.com");
selenium.type("//input[@id='password']", "test");
// 登录
selenium.click("//input[@id='submit_form']");
// 等待直到页面出现 Mail 链接
int count = 60;
while(count > 0){
if(selenium.isElementPresent("//a[contains(text(),'Mail')]")){
break;
}else{
Thread.sleep(1000);
count--;
}
}
// 登出
selenium.click("//a[contains(text(),'Log Out')]");
// 测试结束后,终止 selenium session
selenium.stop();
}
}
|