我一直在尝试使用Unix运行selenium测试(已在Windows上运行良好),但没有运气。任何人都可以帮助我如何配置套件,使其在Unix上运行..?
此外,如果在Unix上运行,我们如何看待结果,因为根据我的理解,浏览器可能会在运行时隐藏。
非常感谢任何帮助。感谢
答案 0 :(得分:1)
在linux / unix上你将无法在UI模式下运行selenium测试我建议你使用以下技术stacK: 1)使用maven作为项目构建管理器 2)使用Selenium Ghost Driver - 使用PhantomJS作为后端的远程WebDriver
linux / unix的设置(在Linux上实际上对我很有用):
POM.xml
(包含依赖项的文件):
.....
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.41.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>2.41.0</version>
</dependency>
<!--substituting phanbedder with local Phanbedder implementation-->
<dependency>
<groupId>net.anthavio</groupId>
<artifactId>phanbedder-1.9.7</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.github.detro.ghostdriver</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.1.0</version>
</dependency>
.....
也是一个重要的注意事项: 1)例如在Linux上将有一个selenium server UP并作为中心角色运行 2)并且在同一台机器上或者在另一台机器上连接到集线器的硒节点也应该启动并运行。在这台机器上,预计还会提取phantomjs
启动中心:
java -jar selenium-server-standalone-2.41.0.jar -role hub
启动节点:
phantomjs --webdriver=8080 --webdriver-selenium-grid-hub=http://localhost:4444
我项目的代码示例:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.PageFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import net.anthavio.phanbedder.Phanbedder;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
/**
* Created by dell on 03.06.2014.
*/
public class BrowserOneInstance extends BaseMethodsForMultipleBrowsers {
private WebDriver driver;
private final static Logger log = LoggerFactory.getLogger(BrowserOneInstance.class);
public static LoginPage loginPage;
public static FacebookUserPage homePage;
FileOperations fileManipulator = new FileOperations();
// hub - nodes model (on local WIN machine) over GhostDriver- pHantomJS
@BeforeClass
public void seleniumGrridUponGhostDriver() throws MalformedURLException {
// either using Phanbedder - CROSS platfrom solution
// File phantomjs = Phanbedder.unpack(); //Phanbedder to the rescue!
// OR point path to phantomJs explicitly
File phantomjs = new File(System.getProperty("java.io.tmpdir")+File.separator+"phantomjs-1.9.7");
DesiredCapabilities dcaps = new DesiredCapabilities();
dcaps.setCapability("takesScreenshot", true);
dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjs.getAbsolutePath());
// !!!!! hardCoded initizliations of GhostDriver node
// driver = new RemoteWebDriver(new URL("http://localhost:8080"), dcaps);
// driver initialization using method providing IP of running Ghost node connected to running hub
// this.driver= new RemoteWebDriver(new URL("http://"+getGhostNodesIp()+":8080"),dcaps);
// node connected to linux hub:
this.driver = new RemoteWebDriver(new URL("http://162.243.175.134:8080"), dcaps);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
//page instances init()
loginPage = PageFactory.initElements(driver, LoginPage.class);
homePage = PageFactory.initElements(driver, FacebookUserPage.class);
}
希望这会对你有所帮助。
答案 1 :(得分:0)
如果使用Maven配置您的项目,那么您正在使用&#34; maven标准目录布局&#34;无论您使用什么平台,Maven都可以执行您的构建+测试。