你好我试图运行Java代码,但它给出了错误“代理服务器拒绝连接”
网页未打开。我也检查了代理设置。设置为自动检测
仍然得到错误。我也检查了防火墙的设置。所以请让我知道应该怎么做来解决这个错误
这是代码:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.MarionetteDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
//import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
//import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class sample_google
{
WebDriver driver;
@BeforeTest
public void setUp(){
// FirefoxProfile profile = new FirefoxProfile();
System.setProperty("webdriver.gecko.driver", "D:\\ashwini\\geckodriver.exe");
driver= new MarionetteDriver();
//driver = new HtmlUnitDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testsample_google() throws Exception{
driver.get("https://www.google.com/");
// WebElement searchBox = driver.findElement(By.name("q"));
// searchBox.sendKeys("fast cars");
// searchBox.submit();
driver.findElement(By.name("q")).sendKeys("Selenium");
System.out.println("Page title : " + driver.getTitle());
WebElement resultCount = driver.findElement(By.id("resultStats"));
System.out.println("Result Count : " + resultCount.getText());
}
@AfterTest
public void teardown()
{
//driver.quit();
}
}
和错误:
[TestNG] Running:
C:\Users\Pramod\AppData\Local\Temp\testng-eclipse-33059775\testng-customsuite.xml
1472721257179 Marionette INFO Listening on port 61629
1472721260499 Marionette INFO startBrowser db6c37fd-5fa7-4f5e-a1fd-89f46151f221
1472721260513 Marionette INFO sendAsync db6c37fd-5fa7-4f5e-a1fd-89f46151f221
1472721261196 Marionette INFO sendAsync db6c37fd-5fa7-4f5e-a1fd-89f46151f221
FAILED: testsample_google
java.lang.NullPointerException
at sample_google.testsample_google(sample_google.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:643)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:152)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:57)
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 38 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@5594a1b5: 31 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@3f3afe78: 21 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@1cd072a9: 141 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@34ce8af7: 11 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@6b71769e: 54 ms
1条答案
按热度按时间w41d8nur1#
通过更改我的计算机的LAN设置解决了代理的问题