Restart Selenium script without loosing data - selenium

I have a classic Selenium script (in jupyter notebook) for scraping a website.I run that script and craweled hundreds of pages (clicking next-next) and finally an exception occured. Browser window is open with that session. Now I want to rerun that script from where I left in the same window maybe, before error occured. How is it possible?

Yes, your code probably starts with opening new browser window and getting the url such as
driver=Chrome(executable_path='chromedriver.exe')
driver.get(url)
Just comment out that lines in the next run and your code will run in the current open window where you left.

Related

autoit +selanium on jenkins does not work

enter image description hereI have a selenium test implement for web application and implemented autoit to do a folder upload to my application. This folder upload initiates a chrome popup warning which has no title but 2 buttons "Upload" and "Cancel" (default selected). The folder upload is in the control of my application and has title for the popup window. So I could see controlfocus worked on upload folder popup even when my test was deployed on jenkins. But it does not click on the Chrome popup warning
#include <WinAPIFiles.au3>
ControlFocus("Select Folder to Upload","","Edit1")
ControlSetText("Select Folder to Upload","","Edit1","<Myfolder Path>")
sleep(4000)
ControlClick("Select Folder to Upload","","Button1")
sleep(4000)
;this is for the popup warning from chrome
ControlFocus("[CLASS:Edit; INSTANCE:1]","","Edit1")
Send("{LEFT}") <===== this and below does not ever work on jenkins but works on local
execution
Send("{ENTER}")
;sleep(10000)
exit(0)
my selenium code has
String filepath = ".\\uploadfile.bat";
Process p1 = Runtime.getRuntime().exec( filepath );
uploadfile.bat is ....
START /wait c:\AutoIT\uploadfld.exe
As first step run yours AutoIt script, and just after that click the HTML element using selenium.
Do not try to run AutoIt script after clicking the HTML element in selenium, as this stops your selenium because browser waits for file selection.
And as I said in one other cases (question which I answer some time ago), there should be other possibilities to do that without AutoIt, even without invoking the pop up window.

Selenium Tests for Internet Explorer doesn't executs properly through Jenkins

We have our Health Check automated wherein all of our applications are logged onto, all via Selenium and only on Internet Explorer.
The code runs well when it was executed directly from a batch file. However, when Jenkins calls this batch (.bat) file, it doesn't execute it completely.
BTW the platform is Windows Server 2008 R2 Standard
This is the .bat file code
#echo off
set path="";
set path="E:\XXXX\jre1.8.0_141\bin";
pushd E:\Jenkins_Softwares\SeleniumCode\HealthCheck_jar
SET JAVA_OPTS=-Xmx4g -Xms512m -XX:MaxPermSize=256m -XX:ReservedCodeCacheSize=128m -XX:MaxHeapSize=512m
java -jar HealthCheck_JenkinsNG.jar
I've added these additional IE options in the JAVA code before launching the IE driver.
InternetExplorerOptions options = new InternetExplorerOptions();
options.introduceFlakinessByIgnoringSecurityDomains();
options.enableNativeEvents();
options.destructivelyEnsureCleanSession();
When Jenkins executes the batch file, the IE browser opens into the Login page. There's something odd when this page is displayed - the entire page alignment is disrupted and all elements get aligned to the left. (I'd like to stress that when the batch file is instead executed directly, there is no such page alignment disruption. The elements retain their original centre position. For some reason, Jenkins sets all of this to the left). The alignment is not exactly a deal breaker for me.
However, when username and password is entered via the Selenium code, it types into the perfect text boxes; but when the submit button is hit, the content in these textboxes turn blank and I'm unable to login. (When this same piece of code is executed via running the batch file directly, I'm able to login and The homepage of my application is displayed)
I doubt if there's something wrong with the selenium java code. Since, it executes properly, when run from the .bat file or even command line or even as a Java Application from an IDE.
For some reason, when this is executed from Jenkins it does not work.
Is there any options or settings that needs to be set when Jenkins works with Selenium on IE 11? Because I've tried tweaking the selenium code so much, they all yield the same result - The elements on the Login page get cleared after the submit button is clicked.
Also, just to mention, all of this is run on one Master node of Jenkins only. There are no slave nodes.
You need to take care of a couple of things as follows:
For the build process Jenkins would need the path of jdk. Simply jre may not suffice.
JDK 8u141 is ancient now and you need to upgrade to latest JDK 8u202
introduceFlakinessByIgnoringSecurityDomains() (in Java) and IntroduceInstabilityByIgnoringProtectedModeSettings() (in DotNet) is not an ideal solution to address the issues croping out of Protected Mode settings.
Here you can find a detailed discussion in Internet Explorer Protective mode setting and Zoom levels
To work with Selenium, InternetExplorerDriver and InternetExplorer you need to fulfill the Required Configuration

Selenium + Chrome Webdrivers killing memory

Each time I run my selenium script, which uses a Chrome Webdriver, I find that at the end of the execution, I have significantly (~50 Mb) less memory in my drive. I am not pulling/storing data anywhere, I am just instructing it to complete a series of clicks to navigate some UI, so why would this be happening? I suspect that is has to do with my webdrivers never actually quitting, but I'm not sure why that would be the case? If I close out of the chrome page being run by selenium prematurely, I'm assuming the driver closes too? And in the case where it does conclude running, I explicitly program the driver to quit.
Additionally, I can no longer open chrome through my desktop. It simply won't start.
Can someone give me some advice or enlighten me about what is actually taking place behind the scenes to cause this problem?
When execution starts chromedriver creates some temp directories in this location :
C:\Users\username\AppData\Local\Temp
these directories starts with name like "scoped_dir8952_11195" and every directory created by chrome in temp folder starts with "scoped_dir".
when driver.quit() or close() is called it should be deleted but if it is not getting deleted then you have to delete it after execution using java code or you can simply create a .bat file that deletes the directories starting with name "scoped_dir" and then can execute it using ProcessBuilder or Runtime.exec() .
You can also manually delete them if you want.
Hope that helps you.

CMD window Close automatically after Jenkins build is over

I trying to run Selenium grid and node using Jenkins but the CMD windows always closes after executing the steps
i am running the below code in Jenkins Window Batch Command
cd "C:\TapsiumACSS\Grid3.9"
start Hub.bat
I need the CMD window to be opened
You can create a shortcut of the bat file and under properties in the target section you have to add &PAUSE
This will pause the command prompt until an user input is done.
Just a opinion, Not a good idea to use Jenkins and ask the user to do something as that defeats the whole automation aspect... Instead copy the selenium results into a html or text file which can be viewed later :)
P.S. you will have to refer to this bat file location in Jenkins i.e. the shortcut location
Hope it helps :)

How can I stop or pause playframework Selenium tests on error?

I'd like to stop or pause Selenium test when running with playframework, because I can't see what is wrong!
Is there a way to preserve the window with my application on the step where it failed? It automatically closes that window!
You could try a few things after you pin point exactly which step causes the error:
Put a wait command in your selenium test to pause the test so you can see what is going on in the UI
You could start the debugger and put a break point on some code that gets executed on the server after the failure happens (assuming the test continues running after the failure)
You could use the selenium test runner panel to slow down the speed of the test so you can see the error (i.e. I'm referring to the speed slider that you see when you run the tests in the browser via the url http://localhost:9000/#tests)