I am trying to run the selenium webdriver sample script from flood.io in my local Intelij. But I keep getting an error:
For input String: "null".
I want to be able to run this and then change the code and upload it to flood.io so I can run the load test with my functional selenium test there.
Any help with this?
Error log:
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();
}
}
These are only applicable when running on Flood - you will need to provide the Host and Port of your local Selenium WebDriver instance to test locally. you could even use instead of remote driver the following to run on your local:
WebDriver driver;