52
技術社區[雲棲]
自動化測試框架PhoenixAutotest入門
-
介紹
這裏介紹一個基於Selenium實現的一個web自動化測試框架,本框架主要是通過對Selenium的封裝實現降低學習自動化測試框架的難度。
如果,您還對Selenium不了解的話,可以先參考《Selenium學習建議》。
-
入門知識
Java基礎
-
環境
jdk1.8、Eclipse、Maven
-
入門
可以根據您的習慣來新建Java工程或者Maven工程。如果是Maven工程的話,請添加如下依賴:
<dependencies> <dependency> <groupId>com.surenpi.autotest</groupId> <artifactId>autotest.web.framework</artifactId> <version>2.0.0-20170722</version> </dependency> </dependencies>
我推薦使用Maven工程,不建議從Github上clone出工程源碼來直接修改。另外,您需要確保工程使用的JDK版本為1.8及以上。按照如下步驟操作:
創建好的pom.xml內容應該是:
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.surenpi.autotest</groupId> <artifactId>autotest.parent</artifactId> <version>1.0.1-20170618</version> </parent> <groupId>org.suren.demo</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>com.surenpi.autotest</groupId> <artifactId>autotest.web.framework</artifactId> <version>2.0.0-20170722</version> </dependency> </dependencies> </project>
-
測試類
添加下麵是測試類,並運行即可:
package demo;
import java.io.IOException;
import org.suren.autotest.web.framework.annotation.AutoApplication;
import org.suren.autotest.web.framework.annotation.AutoLocator;
import org.suren.autotest.web.framework.annotation.AutoPage;
import org.suren.autotest.web.framework.selenium.WebPage;
import org.suren.autotest.web.framework.settings.Phoenix;
import org.suren.autotest.web.framework.util.ThreadUtil;
import com.surenpi.autotest.webui.core.LocatorType;
import com.surenpi.autotest.webui.ui.Button;
import com.surenpi.autotest.webui.ui.Text;
@AutoApplication
public class BaiduTest
{
public static void main(String[] args) throws IOException
{
Phoenix phoenix = new Phoenix(BaiduTest.class);
phoenix.init();
BaiduPage page = phoenix.getPage(BaiduPage.class);
page.open();
page.getKeyword().fillValue("PhoenixAutotest");
page.getSearchBut().click();
ThreadUtil.silentSleep(3000);
phoenix.close();
}
}
@AutoPage(url = "https://baidu.com", startPage = true)
class BaiduPage extends WebPage
{
@AutoLocator(locator = LocatorType.BY_ID, value = "kw")
private Text keyword;
@AutoLocator(locator = LocatorType.BY_ID, value = "su")
private Button searchBut;
public Text getKeyword()
{
return keyword;
}
public void setKeyword(Text keyword)
{
this.keyword = keyword;
}
public Button getSearchBut()
{
return searchBut;
}
public void setSearchBut(Button searchBut)
{
this.searchBut = searchBut;
}
}
如果啟動報錯的話,可能是您的瀏覽器版本的問題,請在src/main/resources目錄下新建文件engine.properties,並添加如下內容指定瀏覽器的版本號:
chrome.version=46
-
備注
如有感興趣的童鞋可以留言交流(QQ群:52492046)!對本框架感興趣的童鞋加入到框架的開源行動中!
最後更新:2017-08-15 10:02:35




