Selenium速度Ruby Vs Java

时间:2017-02-22 16:18:35

标签: java ruby selenium

这并不意味着它之间的战争是更快的Java或Ruby,但我总是认为Selenium在Java中的运行速度比Ruby快

Example

Example

我刚刚敲了一个快速而肮脏的测试打开youtube会进行搜索并循环10次。

每次运行时,Ruby都会执行Java。

我没有使用Eclipse或Rubymine只是使用命令行。

Ruby版本:

require 'selenium-webdriver'

test_start  = Time.now
for i in 1..10
beginning_time = Time.now

driver =  Selenium::WebDriver.for :chrome, driver_path:"C:\\ChromeDriver\\chromedriver.exe"
driver.navigate.to "https://www.youtube.com/"

element = driver.find_element(:id, 'masthead-search-term')
element.send_keys "Selenium"
element.submit

puts(driver.title)

driver.quit

end_time = Time.now
puts "Attempt #{i} Seconds: #{(end_time - beginning_time)}"
end

test_end  = Time.now
puts "After 10 attempts the total Seconds: #{(test_end - test_start)}"

Java版:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class SpeedTest {

    public static void main(String[] args) {
        long testStart = System.currentTimeMillis();

        for(int x = 0; x < 10; x++){
            long startTime = System.currentTimeMillis();

            System.setProperty("webdriver.chrome.driver", "C:\\ChromeDriver\\chromedriver.exe");
            WebDriver driver = new ChromeDriver();
            driver.navigate().to("https://www.youtube.com/");

            WebElement element = driver.findElement(By.id("masthead-search-term"));
            element.sendKeys("Selenium");
            element.submit();

            System.out.println(driver.getTitle());

            driver.quit(); 

            long endTime = System.currentTimeMillis();
            System.out.println("Attempt " + x + " seconds:");
            System.out.printf("%.6f%n ", (endTime - startTime)/1e3);
        }

        long testEnd = System.currentTimeMillis();
        System.out.printf("Total seconds for 10 attempts: %.6f%n ", (testEnd - testStart)/1e3);
    }

}

我犯了一个愚蠢的错误,还是Ruby更快进行这种测试?

0 个答案:

没有答案
相关问题