我正在尝试在 maven 中使用 selenium 和 java 和 Testng 页面对象模型项目,我已经在 pom.xml 中添加了所有依赖项,但是在运行脚本后我遇到了一些问题,说 FAILED CONFIGURATION: @BeforeMethod setUp 我必须更新项目,我已经检查了我的脚本我的时间,但我仍然无法解决这个问题。
This is Base Class
package com.qa.Pages;
import java.io.FileInputStream;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerOptions;
public class Base
{
public static WebDriver driver;
public static Properties prop;
public Base()
{
FileInputStream fis;
try {
fis = new FileInputStream("./Configuration/config.properties");
prop = new Properties();
prop.load(fis);
} catch (Exception e) {
System.out.println("Property File not loaded Properly " +e.getMessage());
}
}
public static void browserFactory()
{
String BrowserName = prop.getProperty("browser");
if(BrowserName.equalsIgnoreCase("Chrome"))
{
System.setProperty("webdriver.chrome.driver","C:\\Users\\User\\Downloads\\chromedriver.exe");
driver = new ChromeDriver();
}
else if(BrowserName.equalsIgnoreCase("firefox"))
{
System.setProperty("webdriver.gecko.driver",prop.getProperty("firefoxpath"));
driver = new FirefoxDriver();
}
else if(BrowserName.equalsIgnoreCase("ie"))
{
System.setProperty("webdriver.ie.driver",prop.getProperty("ie"));
InternetExplorerOptions opt = new InternetExplorerOptions();
opt.ignoreZoomSettings();
driver = new InternetExplorerDriver(opt);
}
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(20,TimeUnit.SECONDS);
driver.get(prop.getProperty("url"));
}
}
This is pageclass
package com.qa.Pages;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
public class Homepage extends Base
{
public Homepage()
{
PageFactory.initElements(driver, this);
}
@FindBy(xpath = "//a[@id = '1st']")
WebElement howItWorksTab;
@FindBy(xpath = "//a[@id = '2nd']")
WebElement hiringManagerTab;
@FindBy(xpath = "//*[contains(text(),'Get Certified')]")
WebElement getCertifiedTab;
@FindBy(xpath = "//*[@id=\"bs-example-navbar-collapse-1\"]/ul[1]/li[4]/span/a")
WebElement pricing;
@FindBy(xpath = "//*[contains(text(),'Learn More')]")
WebElement learnMore;
@FindBy(xpath = "//*[@id=\"main-md-content\"]/div[1]/section/div[3]/div[4]/div[2]/div[1]/div[4]/button")
WebElement getStarted1;
@FindBy(xpath = "//*[@id=\"main-md-content\"]/div[1]/section/div[3]/div[4]/div[2]/div[3]/div[4]/button")
WebElement getStarted2;
@FindBy(xpath = "//*[contains(text(),'CONTACT US')]")
WebElement contactUsLink;
@FindBy(xpath = "//*[contains(text(),'About Us')]")
WebElement aboutUsLink;
@FindBy(xpath = "//*[contains(text(),'Blog')]")
WebElement blogLink;
@FindBy(xpath = "//*[contains(text(),'Privacy Policy')]")
WebElement privacyPolicyLink;
@FindBy(xpath = "//*[contains(text(),'Complex Adaptive Testing')]")
WebElement complexAdaptiveLink;
@FindBy(xpath = "//*[contains(text(),'FAQ')]")
WebElement faqLink;
@FindBy(xpath = "//*[contains(text(),'//*[@id=\"main-md-content\"]/div[2]/footer/div/div[1]/div[2]/div[2]/a[2]')]")
WebElement pricingLink;
@FindBy(xpath = "//*[@id=\"main-md-content\"]/div[2]/footer/div/div[1]/div[2]/div[2]/a[3]")
WebElement howItWorksLink;
@FindBy(xpath = "//*[contains(text(),'Geekbears')]")
WebElement geeksbearsLink;
@FindBy(xpath = "//button[contains(text(),'Log in')]")
WebElement logInBtn;
@FindBy(xpath = "//button[contains(text(),'Sign up')]")
WebElement signUpBtn;
public void hoveronHowItWorksTab()
{
Actions act = new Actions(driver);
act.moveToElement(howItWorksTab).build().perform();
}
public void hoveroverHiringManager()
{
Actions act = new Actions(driver);
act.moveToElement(hiringManagerTab).build().perform();
}
public void hoverOverGetCertified()
{
Actions act = new Actions(driver);
act.moveToElement(getCertifiedTab).build().perform();
}
public void hoverOverPricing()
{
Actions act = new Actions(driver);
act.moveToElement(pricing).build().perform();
}
public void clickOnLearnMore()
{
learnMore.click();
}
public void clickOnGetStarted()
{
getStarted1.click();
}
public void clickOnGetStarted2()
{
getStarted2.click();
}
public void clickOnContactUsLink()
{
contactUsLink.click();
}
public void clickOnAboutusLink()
{
aboutUsLink.click();
}
public void clickOnBlogLink()
{
blogLink.click();
}
public void clickOnPrivacyPolicyLink()
{
privacyPolicyLink.click();
}
public void clickOnComplexAdaptiveLink()
{
complexAdaptiveLink.click();
}
public void clickOnFAQlink()
{
faqLink.click();
}
public void clickOnPricingLink()
{
pricingLink.click();
}
public void clickOnHowItWorksLink()
{
howItWorksLink.click();
}
public void clickOnGeeksBearsLink()
{
geeksbearsLink.click();
}
public void clickOnLoginLink()
{
logInBtn.click();
}
public void clickOnSignUpLink()
{
signUpBtn.click();
}
}
This is Test Class
package com.qa.test;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.qa.Pages.Base;
import com.qa.Pages.Homepage;
public class HomepageTest extends Base
{
Homepage home;
public HomepageTest()
{
super();
}
@BeforeMethod
public void setUp()
{
home = new Homepage();
browserFactory();
}
@Test(priority = 1)
public void mouseHoverHowItWorksTest()
{
home.hoveronHowItWorksTab();
}
@Test(priority = 2)
public void mouseHoverHiringManagerTest()
{
home.hoveroverHiringManager();
}
@Test(priority = 3)
public void mouseHoverOnGetCertifiedTest()
{
home.hoverOverGetCertified();
}
@Test(priority = 4)
public void mouseHoverOnPricing()
{
home.hoverOverPricing();
}
@AfterMethod
public void tearDown()
{
driver.quit();
}
}
This is the Error Log
FAILED CONFIGURATION: @BeforeMethod setUp
org.openqa.selenium.TimeoutException: timeout
(Session info: chrome=79.0.3945.117)
Build info: version: '4.0.0-alpha-3', revision: '8c567de6dc'
System info: host: 'DESKTOP-L95KUEC', ip: '192.168.1.49', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_221'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 79.0.3945.117, chrome: {chromedriverVersion: 79.0.3945.36 (3582db32b3389..., userDataDir: C:\Users\User\AppData\Local...}, goog:chromeOptions: {debuggerAddress: localhost:56007}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 1e0d7d8e81fe5268218a38952f31c2cc
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:191)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:125)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:52)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:161)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:576)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:276)
at com.qa.Pages.Base.browserFactory(Base.java:61)
at com.qa.test.HomepageTest.setUp(HomepageTest.java:24)
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.invokeConfigurationMethod(Invoker.java:514)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:589)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:822)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1130)
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.RemoteTestNG.run(RemoteTestNG.java:113)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)
This Pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>devdatascholarautomation</groupId>
<artifactId>devdatascholarautomation</artifactId>
<version>0.0.1-snapshot</version>
<packaging>jar</packaging>
<name>devdatascholarautomation</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceencoding>utf-8</project.build.sourceencoding>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-alpha-3</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.2</version>
</dependency>
</dependencies>
</project>