微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Flood IO - Selenium Script - 无法在 Intelij 中运行示例 Selenium Script 不断获取 For input String Null

如何解决Flood IO - Selenium Script - 无法在 Intelij 中运行示例 Selenium Script 不断获取 For input String Null

我正在尝试在本地 Intelij 中运行来自 flood.io 的 selenium webdriver 示例脚本。但我不断收到错误

对于输入字符串:“null”。

我希望能够运行它,然后更改代码并将其上传到 flood.io,这样我就可以在那里运行带有功能性 selenium 测试的负载测试。

有什么帮助吗?

错误日志:

C:\TestData\java-1.8.0-openjdk-1.8.0.282-1.b08.dev.redhat.windows.x86_64\jre\bin\java.exe "-javaagent:C:\Users\sshiekh\AppData\Local\JetBrains\IntelliJ IDEA Community Edition 2020.3.1\lib\idea_rt.jar=58719:C:\Users\sshiekh\AppData\Local\JetBrains\IntelliJ IDEA Community Edition 2020.3.1\bin" -Dfile.encoding=UTF-8 -classpath   C:\TestData\java-1.8.0-openjdk-1.8.0.282-1.b08.dev.redhat.windows.x86_64\jre\lib\charsets.jar;C:\TestData\java-1.8.0-openjdk-1.8.0.282-1.b08.dev.redhat.windows.x86_64\jre\lib\ext\access-bridge-64.jar;C:\TestData\java-1.8.0-openjdk-1.8.0.282-1.b08.dev.redhat.windows.x86_64\jre\lib\ext\cldrdata.jar;C:\TestData\java-1.8.0-openjdk-1.8.0.282-1.b08.dev.redhat.windows.x86_64\jre\lib\ext\dnsns.jar;C:\TestData\java-1.8.0-openjdk-1.8.0.282-1.b08.dev.redhat.windows.x86_64\jre\lib\ext\jaccess.jar;C:\TestData\java-1.8.0-openjdk-1.8.0.282-1.b08.dev.redhat.windows.x86_64\jre\lib\ext\localedata.jar;C:\TestData\java-1.8.0-openjdk-1.8.0.282-1.b08.dev.redhat.windows.x86_64\jre\lib\ext\nashorn.jar;C:\TestData\java-1.8.0-openjdk-1.8.0.282-1.b08.dev.redhat.windows.x86_64\jre\lib\ext\sunec.jar;C:\TestData\java-1.8.0-openjdk-1.8.0.282-1.b08.dev.redhat.windows.x86_64\jre\lib\ext\sunjce_provider.jar;C:\TestData\java-1.8.0-openjdk-1.8.0.282-1.b08.dev.redhat.windows.x86_64\jre\lib\ext\sunmscapi.jar;C:\TestData\java-1.8.0-openjdk-1.8.0.282-1.b08.dev.redhat.windows.x86_64\jre\lib\ext\sunpkcs11.jar;C:\TestData\java-1.8.0-openjdk-1.8.0.282-1.b08.dev.redhat.windows.x86_64\jre\lib\ext\zipfs.jar;C:\TestData\java-1.8.0-openjdk-1.8.0.282-1.b08.dev.redhat.windows.x86_64\jre\lib\jce.jar;C:\TestData\java-1.8.0-openjdk-1.8.0.282-1.b08.dev.redhat.windows.x86_64\jre\lib\jfr.jar;C:\TestData\java-1.8.0-openjdk-1.8.0.282-1.b08.dev.redhat.windows.x86_64\jre\lib\jsse.jar;C:\TestData\java-1.8.0-openjdk-1.8.0.282-1.b08.dev.redhat.windows.x86_64\jre\lib\management-agent.jar;C:\TestData\java-1.8.0-openjdk-1.8.0.282-1.b08.dev.redhat.windows.x86_64\jre\lib\resources.jar;C:\TestData\java-1.8.0-openjdk-1.8.0.282-1.b08.dev.redhat.windows.x86_64\jre\lib\rt.jar;C:\TestData\demo-selenium\out\test\demo-selenium;C:\TestData\demo-selenium\out\production\demo-selenium;C:\TestData\demo-selenium\test\custom.jar;C:\TestData\demo-selenium\lib\json-simple-1.1.1.jar;C:\TestData\demo-selenium\lib\selenium-server-standalone-3.11.0.jar ChallengeChrome
Exception in thread "main" java.net.MalformedURLException: For input string: "null"
    at java.net.URL.<init>(URL.java:645)
    at java.net.URL.<init>(URL.java:508)
    at java.net.URL.<init>(URL.java:457)
    at ChallengeChrome.main(ChallengeChrome.java:33)
Caused by: java.lang.NumberFormatException: For input string: "null"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:580)
    at java.lang.Integer.parseInt(Integer.java:615)
    at java.net.URLStreamHandler.parseURL(URLStreamHandler.java:222)
    at java.net.URL.<init>(URL.java:640)
    ... 3 more

Process finished with exit code 1


import java.net.URL;
import java.util.concurrent.TimeUnit;
import java.util.List;
import java.util.Random;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WebDriverException;

import org.openqa.selenium.JavascriptExecutor;

import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import org.openqa.selenium.support.ui.Select;

import io.flood.selenium.FloodSump;

public class ChallengeChrome  {

  public static void main(String[] args) throws Exception {
    int iterations = 0;

    // Create a new instance of the html unit driver
    // Notice that the remainder of the code relies on the interface,// not the implementation.
    WebDriver driver =new RemoteWebDriver
            (new URL("http://" +
                    System.getenv("WEBDRIVER_HOST") +
                    ":" +
                    System.getenv("WEBDRIVER_PORT")
                    + "/wd/hub"),DesiredCapabilities.chrome());

    JavascriptExecutor js = (JavascriptExecutor)driver;

    // Create a new instance of the Flood IO agent
    FloodSump flood = new FloodSump();

    // Inform Flood IO the test has started
    flood.started();

    // It's up to you to control test duration / iterations programatically.
    while( iterations < 1000 ) {
      try {

        System.out.println("Starting iteration " +  String.valueOf(iterations));

        driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);

        // And Now use this to visit the target site
        driver.get("https://jriz.io/");
        System.out.println("DEBUG - Navigate to main site at https://jriz.io");

        // Log a passed transaction in Flood IO
        flood.passed_transaction(driver,"The Flood Store - Home");

        //select the accessories section
        driver.findElement(By.cssSelector("img[alt='Accessories']")).click();
        System.out.println("DEBUG - Click Accessories category on the main site");
        flood.passed_transaction(driver,"The Flood Store - Accessories");

        //add item to cart
        Random r = new java.util.Random();
        List <WebElement> links = driver.findElements(By.cssSelector("a[class='button product_type_simple add_to_cart_button ajax_add_to_cart']"));
        WebElement randomElement = links.get(r.nextInt(links.size()));

        int linkListCount = links.size();
        System.out.println("Total Number of link count on page = "  + linkListCount);

        randomElement.click();
        flood.passed_transaction(driver,"The Flood Store - Add Item to Cart");

        //Go to your cart
        driver.get("http://jriz.io/cart/");
        flood.passed_transaction(driver,"The Flood Store - View Cart");

        // Good idea to introduce some form of pacing / think time into your scripts
        Thread.sleep(2000);

        iterations++;

      } catch (WebDriverException e) {
        // Log a webdriver exception in flood
        flood.webdriver_exception(driver,e);
      } catch(InterruptedException e) {
        Thread.currentThread().interrupt();
        String[] lines = e.getMessage().split("\\r?\\n");
        System.err.println("browser terminated early: " + lines[0]);
      } catch(Exception e) {
        String[] lines = e.getMessage().split("\\r?\\n");
        System.err.println("Other exception: " + lines[0]);
      } finally {
        iterations++;
      }
    }

    driver.quit();

    // Inform Flood IO the test has finished
    flood.finished();
  }
}

解决方法

这些仅适用于在 Flood 上运行时 - 您需要提供本地 Selenium WebDriver 实例的主机和端口以进行本地测试。 您甚至可以使用以下代替远程驱动程序在本地运行:

WebDriver 驱动程序;

System.setProperty("PATH-TO-YOUR-CHROMEDRIVER");
driver = new ChromeDriver();

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。