Convert JUnit test case to Selenium IDE html file? - selenium

I have learnt how to export Selenium IDE html file to JUnit.
But if I make a change to the JUnit test - is there a way I can convert the Junit test to Selenium IDE html file so that even if I run the test from IDE the new change is recorded?
What is the best practice for such scenarios?
Note: (2nd user#Manii88), I am also facing the same issue...THough it might be an old question, it is still not solved yet...I find this question compelling because, say for example, I am in middle of some test, which i have exported from selenium ide and modified in Selenium Webdriver, eclipse, to check the viability of test cases and handling of popups...then, i want to continue my test case in ide...till the step completed, i want to proceed quickly and then, the next step, i will continue recording...
Hope this makes the scenario clear...Any answers???
Thanks!

Though it's not always possible, you may try the below steps to achieve it to some extent:
Install the latest Selenium IDE (or at least >= 1.6)
Open Selenium IDE
Options Menu > Format > JUnit 4 (Webdriver backed) [or use the same option here which was used while exporting html to JUnit]
Dismiss the warning dialog
Go to the Source tab, and paste your JUnit code
Change the format again back to HTML by selecting Options > Format > HTML
Dismiss the warning dialog
Switch (back) to Table tab to see your latest changes

Related

Running a pre-existing .java

I'm switching from Sublime Text 3 to IntelliJ, I had a test.java file on my desktop that I used for small testing but now I am not able run the same in IntelliJ, the problem is it's not showing the file when I select run.
I tried experimenting with different projects created through IntelliJ and understand that I need to set Project to run the code, but again I don't see the file I want.
Here is the project selection screen
Here is what happens when I hit run
See this answer and this document.
You need to configure the content and source roots inside the Java module.
If you right click on test.java and click "Run 'test'", that will attempt to run your main class. Although you may have a NullPointer exception in your code. When you attempt to access a.get(0), the value will return null as there are no Integers in your ArrayList. Also generally class files are named with uppercase first characters. Hope this helps!

Intellij : Adding 'JUnit' to context menu when creating new file

Currently in Intellij if I try to create a new file via "New > whatever", I don't see any option to choose a JUnit file. I dug deeper and found out the "Edit File Templates...".
While you can add a variety of files from there to the context menu, there is no ability to choose JUnit.
If you browse over to "Code" tab you can see various JUnit templates. However I have no idea if these are just code generation templates instead of file generation templates. And besides, there is no option to port them to the "Files" tab.
The closest SO thread describing this issue is this and it failed to match my needs.
Mind you I am relatively new to Intellij and I come from eclipse.
P.S: I am aware you can generate tests from existing classes. I am currently trying to implement TDD so that does not answer my needs.
While I don't have an answer for this exact question, I think there's an easier way to handle the underlying requirements (easily creating tests):
Navigate to the class you want to test and press ALT+ENTER. In the context menu, pick "Create Test":
After you choose it, you'll get a dialog with several options including the framework to use (e.g., JUnit 5, JUnit 5, TestNG), the methods you want to generate test stubs for, etc:

Changing the sequence of test cases in Selenium IDE

For example,
I have several test cases here when recording. And now I want to take test case "exp11141" to the first one, but I can't drag and drop the test case in Selenium IDE.
Is there a way to change the sequence of test cases in Selenium IDE?
I mean just in the IDE, not to modify any code. Thanks for help!
Yes you can! (control the order of the tests in the User Interface)
I don't recall when this was introduced but I'm currently running v3.17.0.
In Selenium IDE by default you're looking at Tests which shows the tests, I believe, in the chronological order you recorded them.
If you click the word "Tests", and choose instead "Test Suites" you should see the default test suite. In that view you can add a new suite or use the Default Suite.
Taking the Default Suite as our example, to the right of the name of the suite you'll see an icon (for me in Windows it's triple dots stacked vertically)
Clicking that icon gives a menu that allows you to choose:
Add tests
Rename
Delete
Settings
Export
By clicking "Add tests" you get a select tests dialogue with the names of all your saved tests, each with a checkbox beside it. Check any unchecked checkboxes first. All of them!
Now press enter to save or, if they were all already checked, escape to exit.
Now, viewing your suite you CAN click and drag to re-order the tests! So for the OP's question, in the suite click and drag that one to the top and off you go!
When you run a suite (icon with right-pointing triangle and three horizontal lines) or using shortcut (Ctrl-Shift-R) the tests will run in that order.
By creating different suites, I have created alternate combinations of tests from my total list to run different scenarios.
You should be able to drag and drop, that is part of the IDE functionality. If that isn't working then something may be wrong with your IDE install. Other than that there is no other way within the IDE to reorder the tests, you'd need to build the suite again by adding in the test cases from the file menu.
I'm not sure why you're against editing it outside of the IDE, but it is incredibly simple, as it would just be 1 cut and paste. If you open the suite file in a text editor you'll see something like this within it.
<body>
<table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium"><tbody>
<tr><td><b>Test Suite</b></td></tr>
<tr><td>TestCase1</td></tr>
<tr><td>TestCase2</td></tr>
<tr><td>TestCase3</td></tr>
</tbody></table>
</body>
All you'd need to do is cut the row of the test case you want to move and paste it in at the top

Unable to pass the value using sendkeys in Selenium webdriver

I am unable to send any value to my application using webdriver. I'm able to click on the element. But SendKeys is not working, execution stops once I click on a Textbox.
driver.findElement(By.xpath("//table[#id='atgf']/tbody/tr[2]/td[3]")).click();
driver.findElement(By.xpath("//table[#id='atgf']/tbody/tr[2]/td[3]")).sendkeys("abc");
Try using the following way,
driver.findElement(By.xpath("...")).sendkeys(new String[]{"abc"});
Try using a Thread.sleep(time in ms) before entering the value in the text field. Sometimes that may be the issue.
Java compiler is set to 1.5 version change it to 1.6.
This is a very common problem with the Java compiler.
All you need to do is just set the Java compiler 1.6 from 1.5.
To change the Java compiler version, complete the following steps:
In the Project Explorer view of the Java EE perspective, right-click
the project and then select Properties.
Select the Project Facets page in the in the Properties window. This page lists the facets in the project and their versions.
Click Modify Project.
Double click the version number next to theJava facet to select a different level of Java compiler.
Click Finish to close the Modify Faceted Project window and then click OK.

How do I use Selenium IDE on Firefox to test JavaScript generated codes?

I am trying to test a website which contains alot of javascript.
Javascript does alot of opening new dialog to let user choose "yes" or "no".
It also has a function to upon right clicking, it opens up a right click menu which contains many functions such as zip, delete etc.
In Selenium, I can use the Selenium IDE to login, click, and others, but I don't know how to test those functions.
I've read there are codes I can write such as in Java to run the test, but I'm hoping to make it work by using the simple Selenium IDE if possible. If not, then can someone post a simple testing code which works to run java scripts? Such as click button -> javascript menu pops up -> click ok on the pop up.
Thank you very much.
Right context menus can be a little tricky. I'd suggest making custom commands for the right click context menu. Add the code from this article to your custom user-extensions.js file.
http://old.nabble.com/How-to-recognise-right-click-of-the-mouse-in-IDE-td14913052.html
The parameters for these functions in these commands become the expected arguments of your Selenium IDE commands. If you really want to make it simple, you can just call your javascript functions in these custom user-extension commands. :-) That might be a bit lazy and isn't truely testing what your right click is doing, but it would work.
Option #1 - if using IDE:
Specify the user-extensions.js file under Selenium IDE > Options (menu) > Options (menu option) > General Tab, then browse to your file under "Selenium Core Extensions".
Option #2 - if using Selenium RC Server:
If you're not using the IDE and using Selenium RC server with a client driver (like JUnit for example), you must specify the path of the *.js file with the -userExtensions parameter when you start the Selenium RC Server on the command line. But you said you just wanted to use the IDE, so I'd ignore this. It takes quite a bit of other setup to use the Selenium RC server.
java -jar selenium-server.jar -userExtensions user-extensions.js
=======================
I've never done this before, so I made the following custom command (JavaScript function) in my custom user-extensions.js file, and it worked well for me. I had to exit and restart the IDE before it found it. For some reason, you type everything after the "do" in the "Command" field in the IDE. It looks like it also added a "customAlertAndWait" to the IDE as well.
Code in user-extensions.js file:
Selenium.prototype.doCustomAlert = function(sTarget, sValue) {
alert('Target: ' + sTarget + ' ... Value: ' + sValue);
};
Selenium IDE command details:
Command: customAlert
Target: custom alert target
Value: custom alert value
The selenium IDE has a lot of tools to verify that specific elements are present and that the value is correct.
To set something up, you would create a test case, and start to record it. When you get to a page where you have to verify that something exists, right click on that element, and you will see a lot of Selenium commands tagged at the bottom of the click menu, such as "VerifyTextPresent" or "verifyValue" or "verifyElementPresent" When you select those commands, they will appear in your test case, and will fail if the verification fails.