own project. I have two separated classes, which use two separated threads in Main class.
While going through debug of the class, which running one of 2 websites, I open the website another one.
So, my situation is the next. Here's one of 2 classes:
public class GBFeedReader implements Runnable {
//private static ChromeOptions chOptions;
private DatabaseConnections databaseConnections = new DatabaseConnections();
public void run() {
// Setup ChromeDriver using WebDriverManager
WebDriverManager.chromedriver().setup();
// Set Chrome options and capabilities
ChromeOptions chromeOptions = new ChromeOptions();
//WebDriverManager.chromedriver().browserVersion("119.0.6045.160").setup();
//WebDriverManager.chromedriver().capabilities(chOptions).setup();
//WebDriverManager.chromedriver().capabilities(chromeOptions).setup();
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--disable-gpu");
chromeOptions.addArguments("--disable-extensions");
ChromeDriver driver = new ChromeDriver(chromeOptions);
driver.get("https://....");
...
and the 2-nd one as below:
public class BGFeedReader implements Runnable {
private DatabaseConnections databaseConnections = new DatabaseConnections();
public void run() {
ChromeOptions options = new ChromeOptions();
//WebDriverManager.chromedriver().browserVersion("118.0.5993.118").setup();
//WebDriverManager.chromedriver().browserVersion("114.0.5735.90").setup();
//WebDriverManager.chromedriver().setup();
/*options.addArguments("--headless");
options.addArguments("--disable-gpu");
options.addArguments("--disable-extensions");*/
ChromeDriver driver = new ChromeDriver(options);
driver.get("https://www.banggood.com/new-arrivals.html");
//driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
...
I'm binding them as below:
public static void main(String[] args) {
//PropertyConfigurator.configure("D:\\IdeaProject\\maven-bot\\src\\main\\resources\\log4j.properties");
// creation pool with 2 threads
//A ScheduledExecutorService is capable of scheduling
// tasks to run either periodically or once after a certain amount of time has elapsed.
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2);
long initialDelay = 0; // the time from now to delay execution - первоначальная задержка
long period = 1; // the period between successive executions - повторение ежедневное
scheduler.scheduleAtFixedRate(new GBFeedReader(), initialDelay, period, TimeUnit.DAYS);
sleepThread();
scheduler.scheduleAtFixedRate(new BGFeedReader(), initialDelay, period, TimeUnit.DAYS);
ApiContextInitializer.init();
// ...
}
As result, the code is running instead of the class GBFeedReader, the class BGFeedReader
The question, am I missing something here? My configuration of the running debug the next one (screen)
Thanks in advance for any ideas, if you're included in my topic, because I'm still confusing with it. Maybe, I'm missing multithreading some detailes under the hood.
If I find the way how to fix it, I'll update the question here👍
Under the phrase as: "As result, the code is running instead of the class GBFeedReader, the class BGFeedReader" I mean it opens me the website of the another class absolutely, for some reason.
In short, from the last updates. I have a different result on the different versions of Selenium. For example, if you take versions from 3.x.x, then the wrong site opens when using several threads, but if you take from 4.x.x, it generally ignores and does not open anything, no browsers. My first conclusion is that this is related to versioning, but how to get around it, this is tough a question, as for now.
The cause was in these lines: chromeOptions.addArguments("--headless"); chromeOptions.addArguments("--disable-gpu"); chromeOptions.addArguments("--disable-extensions"); I simply forgot I didn't comment these lines in Gearbest class, but I commented it in BGFeedReader
Обсуждают сегодня