在工作中,我们正在远程位置(BrowserStack)上运行自动化的Selenium测试。远程web驱动程序就是这样实例化的,这些测试也使用testNG,而项目的设置方式是每个测试都将一个行号传递给这个DriverInit构造函数,然后测试该行上的内容(该部分在代码中没有显示)。问题是我们没有钱在BrowserStack上运行100个并行测试,而且我们都不熟悉这一点。
在阅读完之后,AWS ec2似乎是一个很好的选择,但我不知道它是如何工作的,即使在它上看了视频。ec2有能力接受这样的项目并运行testNG套件吗?做这件事最简单的方法是什么?我们不需要BrowserStack或SaucyLabs拥有的任何花哨的东西。我们只需要在后台运行浏览器测试,但我们不需要有视频记录或任何测试信息。我们确实需要CPU的能力来远程运行许多并行测试。
理想情况下,我们希望能够用另一个url替换URL,并在可能的情况下运行类似的测试。
public class DriverInit{
public WebDriver driver;
public ChromeOptions chromeOptions;
public DesiredCapabilities caps;
public static final String USERNAME = "my_name";
public static final String AUTOMATE_KEY = "blah_blah_blah";
public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
DriverInit(int row) throws MalformedURLException {
// for BrowserStack testing
caps = new DesiredCapabilities();
caps.setCapability("os", "Windows");
caps.setCapability("os_version", "10");
caps.setCapability("browser", "Chrome");
caps.setCapability("browser_version", "80.0 beta");
caps.setCapability("browserstack.local", "false");
caps.setCapability("browserstack.selenium_version", "3.5.2");
caps.setCapability("name", "selenium test for row " + row);
this.driver = new RemoteWebDriver(new URL(URL), caps);
this.chromeOptions = new ChromeOptions();
String chromeDriverPath = "resources/chromedriver.exe";
System.setProperty("webdriver.chrome.driver", chromeDriverPath);
}发布于 2020-09-04 11:14:22
要在AWS或其他远程机器上远程运行,
确保在您的machine.
这应该能胜任你的工作。下面的代码应该可以工作。
try {
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions chromOpt = new ChromeOptions();
chromOpt.addArguments("Proxy","null");
chromOpt.setExperimentalOption("useAutomationExtension", false);
chromOpt.addArguments("--disable-dev-shm-usage");
chromOpt.addArguments("--headless");
chromOpt.addArguments("--no-sandbox");
capabilities.setCapability(ChromeOptions.CAPABILITY,chromOpt );
driver = new RemoteWebDriver(new URL("http://" + AWS_SERVER_URL + ":" + AWS_SERVER_PORT + "/wd/hub"),
capabilities);
} catch (Exception e) {
e.printStackTrace();
}
或者,您也可以使用Selenium Grid。在您的计算机上启动Selenium作为集线器,在AWS机器上启动服务器作为节点。然后运行它。代码将与我粘贴的代码相似。
https://stackoverflow.com/questions/63731790
复制相似问题