Im trying to open a page using java and selenium on port 8080. Ive tried using the page and :8080 but the page continually keeps opening on a different port. Im basically trying to use zap and it configured to use firefox on port 8080. ANy help appreciated. Ive added my test and my class thats added to the test below, i think somewhere int he driver part it must call a different port but i cant see how this is happening
Test:
public class ZapScanTest {
static Logger log = Logger.getLogger(ZapScanTest.class.getName());
private final static String ZAP_PROXYHOST = "127.0.0.1";
private final static int ZAP_PROXYPORT = 8080;
private final static String ZAP_APIKEY = null;
// Change this to the appropriate driver for the OS, alternatives in the
drivers directory
private final static String FIREFOX_DRIVER_PATH =
"drivers/geckodriver.exe";
private final static String MEDIUM = "MEDIUM";
private final static String HIGH = "HIGH";
private ScanningProxy zapScanner;
private Spider zapSpider;
private WebDriver driver;
private Dec myApp;
private final static String[] policyNames = {"directory-browsing","cross-
site-scripting","sql-injection","path-traversal","remote-file-
inclusion","server-side-include",
"script-active-scan-rules","server-side-code-injection","external-
redirect","crlf-injection"};
int currentScanID;
#Before
public void setup() {
zapScanner = new
ZAProxyScanner(ZAP_PROXYHOST,ZAP_PROXYPORT,ZAP_APIKEY);
zapScanner.clear(); //Start a new session
zapSpider = (Spider)zapScanner;
log.info("Created client to ZAP API");
driver = DriverFactory. createProxyDriver("firefox",createZapProxyConfigurationForWebDriver(), FIREFOX_DRIVER_PATH);
myApp = new Dec(driver);
//myApp.registerUser(); //Doesn't matter if user already exists, bodgeit just throws an error
}
#After
public void after() {
driver.quit();
}
#Test
public void testSecurityVulnerabilitiesBeforeLogin()throws Exception {
myApp.login();
log.info("Spidering...");
spiderWithZap();
log.info("Spider done.");
setAlertAndAttackStrength();
zapScanner.setEnablePassiveScan(true);
scanWithZap();
List<Alert> alerts = filterAlerts(zapScanner.getAlerts());
logAlerts(alerts);
assertThat(alerts.size(), equalTo(0));
}
Dec class:
public class Sportdec {
WebDriver driver;
final static String BASE_URL = "https://web-game-stage.dec.com/games:8080";
final static String USERNAME = "dec2009#hotmail.com";
final static String PASSWORD = "tables";
public Dec(WebDriver driver) {
this.driver = driver;
this.driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
this.driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
}
public void login()throws Exception {
driver.get(BASE_URL);
Header header = new Header();
header.guest_select_login();
Pages.Login login = new Pages.Login();
login.login_with_empty_fields();
login.login_with_invalid_email();
login.email_or_password_incorrect();
login.login_open_and_close();
}
By any chance have you tried using this
final static String BASE_URL = "https://web-game-stage.dec.com:8080/games";
instead of this
final static String BASE_URL = "https://web-game-stage.dec.com/games:8080";
You are adding port number to the games directory instead of the host
Related
My application.yml file looks something like:
spring:
profiles: environment
jpa:
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
hibernate:
ddl-auto: none
datasource:
url: jdbc:mysql://myUrl
username: master
driver-class-name: "com.mysql.cj.jdbc.Driver"
My DatabaseConnection class looks something like:
#Component
public class DatabaseManager {
public static final String CONTEXT_KEY = "context";
public static final String CONTEXT_VALUE = "myContext";
public static final String TABLE_NAME = "my-credential-store";
public static final String CREDENTIAL = "mydb.password";
public static final String WRITE_ENDPOINT_OUTPUT = "mydbwriteendpoint";
public static final String DATASOURCE_URL = "spring.datasource.url";
public static final String DATASOURCE_PASSWORD = "spring.datasource.password";
public static void createConnection() throws Exception {
JCredStash jCredStash = null;
try {
Map<String, String> context = new HashMap<>();
context.put(CONTEXT_KEY, CONTEXT_VALUE);
jCredStash = new JCredStash(TABLE_NAME);
String secret = jCredStash.getSecret(CREDENTIAL, context);
String writeEndpoint = jCredStash.getSecret(WRITE_ENDPOINT_OUTPUT, context);
System.setProperty(DATASOURCE_URL,
"jdbc:mysql://" + writeEndpoint + ":port/mydb");
System.setProperty(DATASOURCE_PASSWORD, secret);
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
if (jCredStash != null)
jCredStash.close();
}
}
}
Here, I am getting the DB password from AWS Cred Stash. Everything is working fine for "mydb" database. Now I have created another database named "mydb1" inside the same URL instance with the same username and password. I have tried a couple of options like creating another data source, but nope of them worked for me. Can anyone guide me how can I create the connection with "mydb1" along with "mydb"? Thanks
Im trying to set up selenium tests using zap, the webdriver should be firefox and the port 8080. But when it opens up the port is always a different number.
This is the test below, I dont know how o open the browser under the port 8080 anfd firefox browser, the browser does actually open but nothing appears.
public class Sport {
WebDriver driver;
final static String BASE_URL = "https://web-test.com/";
final static String USERNAME = "test#hotmail.com";
final static String PASSWORD = "tables";
public Sport(WebDriver driver) {
this.driver = driver;
this.driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
this.driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
}
public void login()throws Exception {
driver.get(BASE_URL);
Header header = new Header();
header.guest_select_login();
Pages.Login login = new Pages.Login();
login.login_with_empty_fields();
login.login_with_invalid_email();
login.email_or_password_incorrect();
login.login_open_and_close();
}
The Client zap api is working and starting it seems but the browser doesnt seem to open correctly to port 8080
public class ZapScanTest {
static Logger log = Logger.getLogger(ZapScanTest.class.getName());
private final static String ZAP_PROXYHOST = "127.0.0.1";
private final static int ZAP_PROXYPORT = 8080;
private final static String ZAP_APIKEY = null;
// Change this to the appropriate driver for the OS, alternatives in the
drivers directory
private final static String FIREFOX_DRIVER_PATH = "drivers/geckodriver.exe";
private final static String MEDIUM = "MEDIUM";
private final static String HIGH = "HIGH";
private ScanningProxy zapScanner;
private Spider zapSpider;
private WebDriver driver;
private Sportdec myApp;
private final static String[] policyNames = {"directory-browsing","cross-
site-scripting","sql-injection","path-traversal","remote-file-
inclusion","server-side-include",
"script-active-scan-rules","server-side-code-injection","external-
redirect","crlf-injection"};
int currentScanID;
#Before
public void setup() {
zapScanner = new ZAProxyScanner(ZAP_PROXYHOST,ZAP_PROXYPORT,ZAP_APIKEY);
zapScanner.clear(); //Start a new session
zapSpider = (Spider)zapScanner;
log.info("Created client to ZAP API");
driver = DriverFactory.createProxyDriver ("firefox",createZapProxyConfigurationForWebDriver(), FIREFOX_DRIVER_PATH);
myApp = new Sportdec(driver);
//myApp.registerUser();
}
#After
public void after() {
driver.quit();
}
#Test
public void testSecurityVulnerabilitiesBeforeLogin()throws Exception {
myApp.login();
log.info("Spidering...");
spiderWithZap();
log.info("Spider done.");
setAlertAndAttackStrength();
zapScanner.setEnablePassiveScan(true);
scanWithZap();
List<Alert> alerts = filterAlerts(zapScanner.getAlerts());
logAlerts(alerts);
assertThat(alerts.size(), equalTo(0));
}
I have written some code to automate a certain task I want to perform and it works fine on my computer. Since this task has to be executed every hour, I am running it on my VPS (Amazon).
But running the code on my VPS gives me most of the times errors that I can't reproduce on my own computer. On my own computer I can run it as many time as I want and every time it works correctly.
Can anyone think of a possible reason why this is happening?
My code is:
public final class Test {
// XPath elements
private static final String USERNAME_FIELD = "//*[#id=\"username\"]";
private static final String PASSWORD_FIELD = "//*[#id=\"password\"]";
private static final String SIGN_IN_BUTTON = "//*[#id=\"loginForm\"]/fieldset[2]/button";
private static final String RUN_TEST_BUTTON = "/html/body/div[1]/div/header/div/div/button/span";
// User credentials
private static final String USERNAME = "my-username";
private static final String PASSWORD = "my-password";
// TestObject URL's
private static final String LOGIN_URL = "url";
private static final String RUN_TEST_URL = "my-test-url;
private static final int TIME_OUT = 10000;
public static void main(String[] args) throws IOException {
java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
try (final WebClient client = new WebClient(BrowserVersion.CHROME)) {
client.setAjaxController(new NicelyResynchronizingAjaxController());
client.setCssErrorHandler(new SilentCssErrorHandler());
client.getOptions().setCssEnabled(true);
client.getOptions().setRedirectEnabled(true);
client.getOptions().setAppletEnabled(false);
client.getOptions().setJavaScriptEnabled(true);
client.getOptions().setPopupBlockerEnabled(true);
client.getOptions().setTimeout(TIME_OUT);
client.getOptions().setThrowExceptionOnFailingStatusCode(false);
client.getOptions().setThrowExceptionOnScriptError(false);
client.getOptions().setPrintContentOnFailingStatusCode(true);
//client.setHTMLParserListener(HTMLParserListener.LOG_REPORTER);
client.waitForBackgroundJavaScript(TIME_OUT/2);
HtmlPage page = client.getPage(LOGIN_URL);
HtmlTextInput user = (HtmlTextInput) page.getByXPath(USERNAME_FIELD).get(0);
HtmlPasswordInput pass = (HtmlPasswordInput) page.getByXPath(PASSWORD_FIELD).get(0);
HtmlButton login = (HtmlButton) page.getByXPath(SIGN_IN_BUTTON).get(0);
user.setValueAttribute(USERNAME);
pass.setValueAttribute(PASSWORD);
page = login.click();
page = client.getPage(RUN_TEST_URL);
HtmlSpan runTest = (HtmlSpan) page.getByXPath(RUN_TEST_BUTTON).get(0); // this is the place where it gives an "out-of-bound exception"
page = runTest.click();
client.close();
}
}
}
Error:
net.sourceforge.htmlunit.corejs.javascript.Undefined#2c543bc5
Exception in thread "main"
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at eu.theappfactory.testobject.driver.TestObjectDriver.main(TestObjectDriver.java:71)
I'm trying to get an item from local storage using Selenium Webdriver.
I followed this site but when I run my code I get NullPointerException.
When I debug the code I see the function: getItemFromLocalStorage returns NULL for some reason.
Here is my code:
public class storage
{
public static WebDriver driver;
public static JavascriptExecutor js;
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "D://chromedriver.exe");
driver = new ChromeDriver();
driver.get("http://html5demos.com/storage");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.id("local")).sendKeys("myLocal");
driver.findElement(By.id("session")).sendKeys("mySession");
driver.findElement(By.tagName("code")).click(); // just to escape textbox
String sItem = getItemFromLocalStorage("value");
System.out.println(sItem);
}
public static String getItemFromLocalStorage(String key)
{
return (String) js.executeScript(String.format(
"return window.localStorage.getItem('%s');", key));
}
}
That is because you forgot to instantiate js object correctly. Add below line after driver = new ChromeDriver();.
js = ((JavascriptExecutor)driver);
It will work.
I assume you have NPE on your driver instance.
You can setup driver location property while driver instance creating:
final ChromeDriverService chromeDriverService = new ChromeDriverService.Builder()
.usingDriverExecutable(new File("D://chromedriver.exe")).build();
driver = new ChromeDriver(chromeDriverService);
BTW, I used selenium 2.44.0
Use this Code
WebStorage webStorage = (WebStorage) new Augmenter().augment(driver);
LocalStorage localStorage = webStorage.getLocalStorage();
String user_data_remember = localStorage.getItem("user_data_remember");
String emailAfterLogout;
String passwordAfterLogout;
if (!user_data_remember.equals("")) {
JSONObject jsonObject = new JSONObject(user_data_remember);
Boolean remember = jsonObject.getBoolean("remember");
if (remember) {
emailAfterLogout = jsonObject.getString("email");
passwordAfterLogout = jsonObject.getString("password");
if (emailAfterLogout.equals(email) && passwordAfterLogout.equals(password)) {
System.out.println("Remember me is working properly.");
} else {
System.out.println("Remember me is not working.");
}
}
} else {
System.out.println("Remember me checkbox is not clicked.");
}
From what I have read the correct connection string for a jTDS is:
jdbc:jtds:<server_type>://<server>[:<port>][/<database>]
I believe the issue is the server name. The server name is formatted like this
servername\adhoc
An SQLException gets thrown anytime I try to connect saying "unknown server host name"
Is that my issue, or is there something else I need to look into as well...?
import java.sql.*;
public class Main {
// The JDBC Connector Class.
private static final String MSdbClassName = "net.sourceforge.jtds.jdbc.Driver";
private static final String MSHOST = "servername\\adhoc"; //cascrmeufosqlp1\adhoc
private static final String MSDATABASE = "tier2";
private static final String MSUSER = "feed_****2";
private static final String MSPASSWORD = "*******0";
public static void main(String[] args) throws ClassNotFoundException,SQLException
{
Class.forName(MSdbClassName);
String url2 = "jdbc:jtds:sqlserver://" + MSHOST + ":1433/" + MSDATABASE;
Connection c2 = java.sql.DriverManager.getConnection( url2, MSUSER, MSPASSWORD );
System.out.println("MS SQL works...");
c2.close();
}
}
It looks like you are trying to connect to a "named instance" of sql server. You will need to use the "instance" property in the url. Something like this might work:
jdbc:jtds:sqlserver://servername:1433/dbName;appName=MyAPP;instance=instanceName
See the jTDS faq for more information found here: http://jtds.sourceforge.net/faq.html