Я получаю «не могу найти символ» всякий раз, когда я компилирую свой код. Но когда я перестраиваю свой проект, а затем компилирую, он работает. Не знаю, почему это происходит, я предполагаю, что это происходит из-за импорта в BSLocal.
"C:\Program Files\Java\jdk1.8.0_201\bin\java.exe" -Dmaven.multiModuleProjectDirectory=C:\Users\njayanthy\Desktop\WPS\BrowserStack "-Dmaven.home=C:\Program Files\JetBrains\IntelliJ IDEA 2018.2.2\plugins\maven\lib\maven3" "-Dclassworlds.conf=C:\Program Files\JetBrains\IntelliJ IDEA 2018.2.2\plugins\maven\lib\maven3\bin\m2.conf" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2018.2.2\lib\idea_rt.jar=65122:C:\Program Files\JetBrains\IntelliJ IDEA 2018.2.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA 2018.2.2\plugins\maven\lib\maven3\boot\plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version=2018.2.4 clean compile package install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building BrowserStack 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ BrowserStack ---
[INFO] Deleting C:\Users\njayanthy\Desktop\WPS\BrowserStack\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ BrowserStack ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ BrowserStack ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ BrowserStack ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ BrowserStack ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ BrowserStack ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ BrowserStack ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 2 source files to C:\Users\njayanthy\Desktop\WPS\BrowserStack\target\test-classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/njayanthy/Desktop/WPS/BrowserStack/src/test/java/com/mtrustcompany/browserstack/TestBase.java:[29,31] cannot find symbol
symbol: class BSLocal
[ERROR] /C:/Users/njayanthy/Desktop/WPS/BrowserStack/src/test/java/com/mtrustcompany/browserstack/TestBase.java:[31,19] cannot find symbol
symbol: class BSLocal
location: class com.mtrustcompany.browserstack.TestBase
[ERROR] /C:/Users/njayanthy/Desktop/WPS/BrowserStack/src/test/java/com/mtrustcompany/browserstack/TestBase.java:[31,37] cannot find symbol
symbol: variable BSLocal
location: class com.mtrustcompany.browserstack.TestBase
[ERROR] /C:/Users/njayanthy/Desktop/WPS/BrowserStack/src/test/java/com/mtrustcompany/browserstack/TestBase.java:[38,28] cannot find symbol
symbol: method getClass()
[INFO] 4 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.625 s
[INFO] Finished at: 2019-04-24T09:45:19-05:00
[INFO] Final Memory: 21M/538M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project BrowserStack: Compilation failure: Compilation failure:
[ERROR] /C:/Users/njayanthy/Desktop/WPS/BrowserStack/src/test/java/com/mtrustcompany/browserstack/TestBase.java:[29,31] cannot find symbol
[ERROR] symbol: class BSLocal
[ERROR] /C:/Users/njayanthy/Desktop/WPS/BrowserStack/src/test/java/com/mtrustcompany/browserstack/TestBase.java:[31,19] cannot find symbol
[ERROR] symbol: class BSLocal
[ERROR] location: class com.mtrustcompany.browserstack.TestBase
[ERROR] /C:/Users/njayanthy/Desktop/WPS/BrowserStack/src/test/java/com/mtrustcompany/browserstack/TestBase.java:[31,37] cannot find symbol
[ERROR] symbol: variable BSLocal
[ERROR] location: class com.mtrustcompany.browserstack.TestBase
[ERROR] /C:/Users/njayanthy/Desktop/WPS/BrowserStack/src/test/java/com/mtrustcompany/browserstack/TestBase.java:[38,28] cannot find symbol
[ERROR] symbol: method getClass()
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
это класс TestBase.java
package com.mtrustcompany.browserstack;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.DataProvider;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.UnexpectedException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;
public class TestBase extends BSLocal {
public static BSLocal bsLocal = BSLocal.getInstance();
static URL serverUrl;
public WebDriver getWebDriver() {
return webDriver.get();
}
String className = this.getClass().getSimpleName();
static {
try {
;
serverUrl = new URL(String.format("http://%s:%s@%s/wd/hub", bsLocal.username, bsLocal.accessKey, bsLocal.server));
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
/**
* ThreadLocal variable which contains the {@link WebDriver} instance which is used to perform browser interactions with.
*/
private ThreadLocal<WebDriver> webDriver = new ThreadLocal<WebDriver>();
/**
* DataProvider that explicitly sets the browser combinations to be used.
*
* @param testMethod
* @return Two dimensional array of objects with browser, version, and platform information
*/
@DataProvider(name = "browsers", parallel = true)
public static Object[][] sauceBrowserDataProvider(Method testMethod) {
return new Object[][]{
new Object[]{"firefox", "65.0", "Windows 10"},
new Object[]{"chrome", "70", "windows 10"},
};
}
/**
* @return the {@link WebDriver} for the current thread
*/
protected void createDriver(String browser, String version, String os, String methodName)
throws MalformedURLException, UnexpectedException {
Calendar now = Calendar.getInstance();
int year = now.get(Calendar.YEAR);
int month = now.get(Calendar.MONTH) + 1; // Note: zero based!
int day = now.get(Calendar.DAY_OF_MONTH);
Calendar c = Calendar.getInstance();
c.set(year, month - 1, day, 0, 0);
SimpleDateFormat format = new SimpleDateFormat("MMM dd,yyyy hh");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("build", String.format("%s %s", className, format.format(c.getTime())));
capabilities.setCapability(CapabilityType.BROWSER_NAME, browser);
capabilities.setCapability(CapabilityType.VERSION, version);
capabilities.setCapability("name", methodName);
capabilities.setCapability("browserstack.local", "true");
webDriver.set(new RemoteWebDriver(
serverUrl,
capabilities));
}
@AfterTest
public void done() {
bsLocal.stop();
}
@AfterSuite
public void mailTestReport() {
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("", "");
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("jayanthymohit6@gmail.com"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(""));
message.setSubject(String.format("%s %s", className, new Date()));
BodyPart messageBodyPart1 = new MimeBodyPart();
messageBodyPart1.setText("Test Results");
MimeBodyPart messageBodyPart2 = new MimeBodyPart();
String filename = "C:\\Users\\njayanthy\\Desktop\\WPS\\BrowserStack\\test-output\\emailable-report.html";
DataSource source = new FileDataSource(filename);
messageBodyPart2.setDataHandler(new DataHandler(source));
messageBodyPart2.setFileName(filename);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart2);
multipart.addBodyPart(messageBodyPart1);
message.setContent(multipart);
Transport.send(message);
System.out.println("=====Email Sent=====");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
Я не могу понять, почему это происходит, и что происходит в ручной сборке проекта в ide, который запускаеткомпилировать без проблем?
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
<groupId>MTC</groupId>
<artifactId>BrowserStack</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>com.browserstack</groupId>
<artifactId>automate-testassist</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>3.0.0-alpha-4</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.browserstack</groupId>
<artifactId>browserstack-local-java</artifactId>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.1.5</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.saucelabs</groupId>
<artifactId>sauce_testng</artifactId>
<version>2.1.23</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<parallel>methods</parallel>
<threadCount>40</threadCount>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
</configuration>
</plugin>
<plugin>
<groupId>com.browserstack</groupId>
<artifactId>automate-maven-plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<complianceLevel>1.8</complianceLevel>
</configuration>
<executions>
<execution>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>