Run debug configuration programmatically - eclipse-plugin

I use Chrome DevTools to debug java script code and I need it to run programmatically from my plugin.

(If I understood the slightly brief question.)
You want to make a ILaunchConfigurationWorkingCopy, set the attributes on it, optionally save it, then launch it.
The Launch Manager is very useful as you can do stuff with launches using it.
Here is a simple example:
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType launchType = launchMgr.getLaunchConfigurationType("type id (from plugin.xml)");
ILaunchConfigurationWorkingCopy wc = launchType.newInstance(null, manager.generateLaunchConfigurationName("Name Here"));
wc.setAttributes(launchAttributes);
ILaunchConfiguration lc = wc.doSave();
Launch launch = lc.launch(ILaunchManager.DEBUG_MODE, new NullProgressMonitor());

Related

Can anyone help me in recording script using recording controller in jmeter?

I have done till creation of proxy sever.Facing some socket broken issue on running the scripts in firefox
When i perform some actions everything is working then some error occurs
also explain what is jmeter tree model and jmeternode is?
Scanner sc = new Scanner(System.in);
// recordingController recordingcontroller=new recordingController("testrecorder",RecordController.class);
// RecordingController rc= (RecordingController) recordingcontroller.buildTestElement();
RecordingController rc = new RecordingController();
GenericController gc = new GenericController();
rc.initialize();
gc.addTestElement(rc);
LoopController loopController = new LoopController();
loopController.setLoops(1);
loopController.setFirst(true);
loopController.setProperty(TestElement.TEST_CLASS, LoopController.class.getName());
loopController.setProperty(TestElement.GUI_CLASS, LoopControlPanel.class.getName());
loopController.initialize();
rc.addTestElement(loopController);
ThreadGroup threadGroup = new ThreadGroup();
threadGroup.setName("Thread-Group");
threadGroup.setSamplerController(loopController);
ProxyControl proxyController = new ProxyControl();
// proxyController.setProperty(TestElement.TEST_CLASS, ProxyControl.class.getName());
// proxyController.setProperty(TestElement.GUI_CLASS, ProxyControlGui.class.getName());
proxyController.setName("Proxy Recorder");
proxyController.setPort(4444);
// threadGroup.setSamplerController(rc);
// proxyController.setSamplerTypeName("SAMPLER_TYPE_JAVA_SAMPLER");
TestPlan testPlan = new TestPlan("My_Test_Plan");
testPlan.addTestElement(threadGroup);
testPlan.addTestElement(proxyController);
JMeterTreeModel jtm = new JMeterTreeModel();
proxyController.setNonGuiTreeModel(jtm);
JMeterTreeNode node = new JMeterTreeNode(proxyController,jtm);
// JMeterTreeNode node=new JMeterTreeNode();
proxyController.setTarget(node);
// proxyController.setCaptureHttpHeaders(true);
// proxyController.setUseKeepAlive(true);
// proxyController.setGroupingMode(4);
proxyController.setCaptureHttpHeaders(true);
proxyController.setProxyPauseHTTPSample("10000");
proxyController.setSamplerFollowRedirects(true);
proxyController.setSslDomains("www.geeksforgeeks.org");
proxyController.startProxy();
I don't think non-GUI proxy recording is something you can achieve with vanilla JMeter, if you have to automate the recording process you will have to go for desktop applications automation solutions like Appium or LDTP
If you need to record a JMeter script using Firefox on a system which doesn't have GUI I can think of following approaches:
Use Proxy2JMX Converter module of Taurus tool
Use BlazeMeter Proxy Recorder (by the way it has nice feature of exporting recorded scenarios in "SmartJMX" mode with automatic detection and correlation of dynamic parameters)

Take a snapshot of program after every test

I have a test setup that opens a program and does a test on loop.
I want to have the program take a snapshot / screenshot of the program (only) after a test, inside the loop.
Is this possible?
Below is my test suite run:
So it is fine, and I can run through the full test, but I can't see the results, unless I have Ranorex open. This is not sufficient, if I run this on another PC or VM.
NOTE: All the blanked out boxes, are my variables.
To take a screenshot of the app under test, 3 simple steps:
Create a repo item of the application (using Ranorex Spy).
Drag n Drop the repo item in a recording.
Select the "Capture Screenshot" action.
Hope this helps (even though you have solved the issue!)
Just for clarification.
Ranorex Support team helped me by giving me some C# code to help save screenshots to a location on my PC.
Add a Code Module to the Action Screen, then add the following code:
public void SaveScreenshot(string savelocation)
{
//Take a screenshot of a specific element
Bitmap image = Imaging.CaptureImageAuto(repo.program.SSTabCtlWndClass);
//Name and path to store the screenshot
String imageName = String.Format(varNumber1 + "_" + varNumber2 + ".jpg");
String pathImageName = Path.Combine(#"C:\temp\Screenshots\", imageName);
//Save the screenhot in your specific folder
image.Save(pathImageName, System.Drawing.Imaging.ImageFormat.Jpeg);
}

Code coverage in SimpleTest

Is there any way to generate code coverage report when using SimpleTest similar to PHPUnit.
I have read the documentation of SimpleTest on their website but can not find a clear way on how to do it!
I came across this website that says
we can add require_once (dirname(__FILE__).'/coverage.php')
to the intended file and it should generate the report, but it did not work!
If there is a helpful website on how to generate code coverage, please share it here.
Thanks alot.
I could not get it to work in the officially supported way either, but here is something I got working that I was able to hack together by examining their code. This works for v1.1.7 of SimpleTest, not their master code. At the time of this writing v1.1.7 is the latest release, and works with new versions of PHP 7, even though it is an old release.
First off you have to make sure you have Xdebug installed, configured, and working. On my system there is both a CLI and Apache version of the php.ini file that have to be configured properly depending on if I am trying to use PHP through Apache or just directly from the terminal. There are alternatives to Xdebug, but most people us Xdebug.
Then, you have to make the PHP_CodeCoverage library accessible from your code. I recommend adding it to your project as a composer package.
Now you just have to manually use that library to capture code coverage and generate a report. How exactly you do that will depend on how you run your tests. Personally, I run my tests on the terminal, and I have a bootstrap file that php runs before it starts the script. At the end of the bootstrap file, I include the SimpleTest autorun file so it will automatically run the tests in any test classes that get included like so:
require_once __DIR__.'/vendor/simpletest/simpletest/autorun.php';
Somewhere inside your bootstrap file you will need to create a filter, whitelist the directories and files you want to get reported, create a coverage object and pass in the filter to the constructor, start coverage, and create and register a shutdown function that will change the way SimpleTest executes the tests to make sure it also stops the coverage and generates the coverage report. Your bootstrap file might look something like this:
<?php
require __DIR__.'/vendor/autoload.php';
$filter = new \SebastianBergmann\CodeCoverage\Filter();
$filter->addDirectoryToWhitelist(__DIR__."/src/");
$coverage = new \SebastianBergmann\CodeCoverage\CodeCoverage(null, $filter);
$coverage->start('<name of test>');
function shutdownWithCoverage($coverage)
{
$autorun = function_exists('\run_local_tests'); // provided by simpletest
if ($autorun) {
$result = \run_local_tests(); // this actually runs the tests
}
$coverage->stop();
$writer = new \SebastianBergmann\CodeCoverage\Report\Html\Facade;
$writer->process($coverage, __DIR__.'/tmp/code-coverage-report');
if ($autorun) {
// prevent tests from running twice:
exit($result ? 0 : 1);
}
}
register_shutdown_function('\shutdownWithCoverage', $coverage);
require_once __DIR__.'/vendor/simpletest/simpletest/autorun.php';
It took me some time to figure out, as - to put it mildly - the documentation for this feature is not really complete.
Once you have your test suite up and running, just include these lines before the lines that are actually running it:
require_once ('simpletest/extensions/coverage/coverage.php');
require_once ('simpletest/extensions/coverage/coverage_reporter.php');
$coverage = new CodeCoverage();
$coverage->log = 'coverage/log.sqlite'; // This folder should exist
$coverage->includes = ['.*\.php$']; // Modify these as you wish
$coverage->excludes = ['simpletest.*']; // Or it is even better to use a setting file
$coverage->maxDirectoryDepth = '1';
$coverage->resetLog();
$coverage->startCoverage();
Then run your tests, for instance:
$test = new ProjectTests(); //It is an extension of the class TestSuite
$test->run(new HtmlReporter());
Finally generate your reports
$coverage->stopCoverage();
$coverage->writeUntouched();
$handler = new CoverageDataHandler($coverage->log);
$report = new CoverageReporter();
$report->reportDir = 'coverage/report'; // This folder should exist
$report->title = 'Code Coverage Report';
$report->coverage = $handler->read();
$report->untouched = $handler->readUntouchedFiles();
$report->summaryFile = $report->reportDir . '/index.html';
And that's it. Based on your setup, you might need to make some small adjustment to make it work. For instance, if you are using the autorun.php from simpletest, that might be a bit more tricky.

How to click on "Launch Application" dialog in Firefox with Selenium?

I have a Selenium test, in which I need to click on a "cliclient://" link, and that link needs to open an application. Now, I need to create a new profile for each test, and I don't know how to bypass the "Launch Application" dialog that appears when clicking on the link:
Here's a snippet of the test that I've created:
profile = Selenium::WebDriver::Firefox::Profile.new
profile.secure_ssl = false
profile.assume_untrusted_certificate_issuer=true
profile["plugin.default.state"] = 2
profile["plugin.state.java"] = 2
profile["browser.download.folderList"] = 2
profile["browser.download.manager.alertOnEXEOpen"] = false
profile["browser.download.manager.closeWhenDone"] = true
profile["browser.download.manager.focusWhenStarting"] = false
profile["browser.download.manager.showWhenStarting"] = false
profile["browser.helperApps.alwaysAsk.force"] = false
profile["browser.helperApps.neverAsk.saveToDisk"] = 'application/x-msdownload,application/octet-stream, application/x-msdownload, application/exe, application/x-exe, application/dos-exe, vms/exe, application/x-winexe, application/msdos-windows, application/x-msdos-program'
profile["gfx.direct2d.disabled"] = true
profile["layers.acceleration.disabled"] = true
What is it in the profile that I need to set, to bypass the dialog, or to somehow click on OK when this dialog appears?
You can also try using SikuliX http://sikulix.com/ which is an automation software which uses images to recognise the GUI elements on which certain actions need to be performed
Hovever to use it with ruby you will most probably need to compile and run a java class via a system command and also you will need JDK installed on the machine where the automation will be performed
Use C# to access the Win32 API and find the handle of the window with the title "Launch Application'. You'll need to use this, as the window is controlled by the OS and therefore Selenium can't interact with it. Then use the same API to click the cancel button (find its identifying properties using WinSpy)
Sorry if this isn't a full answer but I couldn't merely comment as I have insufficient rep at the moment.
The idea is creating a profile with default schemes you want and let selenium initialize by copying this profile. The key file that contains default schemes is handlers.json rather than prefs.js
Below is the proof of concept in python.
import json
import os
from pathlib import Path
from selenium import webdriver
# %APPDATA%\Mozilla\Firefox\Profiles\oa6m3bc6.default\Preferences\handlers.json
SCHEME_NAME = 'xxxxx'
PROFILE_DIR_NAME = 'xxxxxx'
handlers = {
'defaultHandlersVersion': {'en-US': 4},
'schemes': {SCHEME_NAME: {'action': 4}}
}
profile_dir = Path(os.environ['APPDATA']) / f'Mozilla/Firefox/Profiles/{PROFILE_DIR_NAME}'
profile_dir.mkdir(exist_ok=True)
with open(profile_dir / 'handlers.json', 'w+') as f:
json.dump(handlers, f)
profile = webdriver.FirefoxProfile(profile_dir)
driver = webdriver.Firefox(profile)
driver.get('http://example.com/')
Tested with Firefox 71.0, geckodriver 0.26.0 (e9783a644016 2019-10-10 13:38 +0000), Python 3.7, and Windows 10

how to Pass command line argument ( baseURL) for selenium WebDriver

Kindly help.
i have created a runnable jar for my Selenium webDriver suite. now i have to test this in multiple environment( QA , Demo box, Dev ). But my manager doesnt what it to be hard coded like below
driver.get(baseUrl)
As the baseURl will change according to the need. My script is given to the build team. So all they will do in the command prompt is
java -jar myproject-1.0.1.jar
So my manager has asked me to send the baseUrl as a command line argument so that build team do not have to go to my script and manually change the baseUrl. They should be able to change the URL every time they run the script from the command line itself. Something like this
java -jar myproject-1.0.1.jar "http://10.68.14.248:8080/BDA/homePage.html"
Can somebody please guide me through this. Is it possible to send command line arguments to Selenium Web Driver driver.get(baseUrl)
Thanks in advance
From your question above I recon you want pass URL at runtime, means your URL changes time to time so beside hardcoded URL , you want pass at the time your automation code runs. So, let me give you 2 simple solutions.
You can send URL dynamically or at Run time by using javascript executor:
try{
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("var pr=prompt('Enter your URL please:',''); alert(pr);");
Thread.sleep(15000L);
String URL = driver.switchTo().alert().getText();
driver.switchTo().alert().accept();
driver.get(URL);
}catch(Throwable e)
{
System.out.println("failed");
}
Use this code in place of driver.get(); , so that a prompt box will appear when you run your code and within 15 secs or it will throw a error(you can change the time in Thread.Sleep) you will give the current Valid URL and hit Enter, the navigation will go to the URL. So that you can use different URL for same set of testscripts.
By using Scanner Class:
String url = "";
System.out.println("Enter the URL :");
Scanner s = new Scanner(System.in);
url = s.next();
s.close();
By using this you can give needed URL in your Console (If you are using Eclipse).
I recommend try Javascript excutor in your code and then create a runnable jar file and just run the Jar file, you will know and it will be the better solution than commandline URL passing . Let me know :)
Another way is to supply arguments this way -Durl=foobar.com and extract them in runtime like this
String URL= System.getProperty("url")