Selenium/Java program speeding up overtime - java

I have written a Java program using Selenium HTMLUnitDriver. It consists of a few methods which basically first scrape a site for some elements, then interact with these elements, and then finally fills in and submits a form. I run these few methods a number of times and record the time between the beginning of the first method and the end of the last method each time. The run time seems to go down overtime. Why is this?

Related

How to make program output differently depending on number of runs?

This is not like a code help or code review thing.I am trying to make a counter for my program that can define the output of my program.For eg: If i want my program do specific thing after it has been run two times or else it should do another thing.Another example of what i am trying to say is that when i run my program first and second time it should print 3,but when i run it third time it should print 5.
I believe there are many ways already out there,but i don't know how to search such type of specific query on google.
I am working on complex program,where such type of thing is required,but i don't know where and how to start or look.I tried to make a counter,but every time the program runs,it initializes the value of counter and so it doesn't increment.
You have to maintain a state of the each time it runs. It means in the program, maintain a counter and store it in a file. You can do it in the following way.
If there is running state counter stored in a file, it means the application is run first time.
Before running the application, read the file which maintains running counter.
Based upon the running counter number like even , odd etc, you can write the logic.
You have to save the value in a file or some other storage method that persists after the program runs and ends.
Every time the program runs:
If there's no file, then create one and write the number 1 in it to show that the program has run once.
If there is already a file when you run the program, then read the number stored in it and interpret it as the number of previous runs. Write a number to the file that is 1 higher than the number of previous runs.

Programmatically insert multiple Chars into Bing search engine and perform search for each

I’ve made a simple Java program that loops through 100 elements of type char. With each iteration it prints out the char to the console using System.out.println. It does this for all 100 chars so at the end the output is 100 chars to the console.
I would like to take the output of each iteration as it comes in the sequence and insert that into the Bing search engine then perform a search automatically while seeing the updated results within Bing. It should do this 100 times for all char elements, so there should be 100 individual char insertions each with them doing a search within Bing.
If it’s not clear I’ve provided a video link of exactly what I mean, you can see how normally I have to type 1 and press enter to perform a search, and then keep doing that to get 100 searches while seeing the results get updated each time. I would like my loop in my program to do this programmatically, if such a thing is possible.
I’m open to use any language as long as it can run on Windows 10, but would prefer Java if possible.
I believe this can be achieved with Selenium (https://www.seleniumhq.org/ and https://www.guru99.com/introduction-webdriver-comparison-selenium-rc.html). It allows you to open browsers and interact with the elements (click, enter data...).
I'm more of a Python guy so I can't provide you code but here's a page that can get you started:
https://www.guru99.com/accessing-forms-in-webdriver.html

Is there a way to run a program in Eclipse without it creating certain variables again every time I run the program?

Basically, I would like to create a "library" of sorts in another class that is created when I run the program's main class the first time. But instead of repeating the action when I click run for a second time, I want the manipulated library in the first run to be initialized. For example if I have a static array with capacity 5 and put the int 1 in index 0, the next time I run the entire thing, I want to start with a static array with 1 in index 0. Is this even possible (in Eclipse) and if so, how can I do this?
All of your program's variables and other state are discarded when it is terminated and reinitialized when it is launched again. (This is a common cause of bugs in Android apps, which are frequently discarded and then re-opened.) To save state between program runs, you need to store it in some place that's intended for this. Common choices include files, databases (H2 with a file-backed database might be a good option), Android SharedPreferences, servers, and more exotic tools such as prevalent systems.

How to scan hbase in a map reduce job

I need to run hourly analysis of elements that are stored in hbase, which means for each element, I need to get the previous hour's data to analyze. The only problem is it's taking me more than 1 hour to scan everything when using a for loop without mapreduce. There are over 100,000 elements we are storing data on.
The data isn't contiguous and it is in time series, coming in every 2 minutes. There is a hash to prevent scanning/writing hotspots so the key looks like this:
hash_elementName_epochTimestamp, e.g. 100_element_1234567890.
I tried to write a mapreduce program using the TableMapReduceUtil.initTableMapperJob method to run my scan. However, the TableMapReduceUtil.initTableMapperJob method takes one scan object and I can't figure out how to scan all the elements that I need without making 100,000 separate scan objects and without scanning the whole table.
Someone else said there was a spark-hbase connector library I could use to leverage Spark and store everything in memory to query quickly. The problem is this code is written in Scala, which I don't know and can't spend time to learn right now.
Is there a spark-hbase connector that's in Java? Is there a way to utilize the TableMapReduceUtil.initTableMapperJob method scan Hbase quickly, even with 100,000 non-contiguous scan ranges?
EDIT: Someone suggested that I should use a start and end time filter. The problem is I'm not interested in every single element. There are only certain elements I'm interested in. When I made my query via the for loop, I passed in the elements I was interested in. Now with the TableMapReduceUtil, I can only make one scan object.

How to compare all the variables in two different Eclipse sessions

I am presently trying to find a bug in a long java code. This code reads an input text file and it runs many CFD simulations and then it collects results and analyzes them. In the input file there is a flag that only changes the order in which that bunch of completely independent threads is run. However, if I change this flag I have that the java program crashes after all the simulations are run, while it should actually behave the same. In order to debug this, I opened two different Eclipse sessions, and in each session I run the code. The only difference between the 2 sessions is the value of that flag I mentioned above. I have set up a breakpoint in a line after all the 37 threads (i.e. simulations) are run and results saved on file. That line is in a subroutine where only the main thread is active (all the other threads stopped) and it collects and elaborate further the results of the 37 simulations. I would like to have a way to quickly compare all the variables (in the present scope) of one Eclipse session with the other, in order to find possible differences. Saving them in a text file and comparing the 2 text files would make the trick for me. Do you know how I can do it, if even possible at all? Any other working solutions is also welcomed.

Categories