I am new to Selenium IDE. As far as I know, when open Selenium IDE, you will notice that the red 'record macro' button is toggled. This means that selenium will attempt to record every action you make inside the browser. This is a problematic way of recording as we implicitly wait for actions to complete before moving on.
If I only let Selenium to record every actions without specifying extra actions, many test step will be failed with error message : Element not found. I was trying to add extra actions based on Selenium API, like waitForElementPresent, waitForSearch etc.
My question is: How do I know which extra action do I need to add for each web target? Any standard for it? Thanks!
I use webdriver but I am familiar with IDE and so far I know it depends on your application how you want to handle the tests. If your application uses ajax calls you might need to use some frequent waitForElementPresent or waitForSearch etc.. and Assertions also depend on the needs of your tests.
Now, the question is how do you know which extra step do you need to insert?
Ans. is you will know the necessity. Such as, if your test step depends on a previous ajax call to finish then you know there is a wait necessary and you know what to do. Not to mention, you can always insert extra steps and I am sure you already know that. And, there is no standard for using those. You adjust your tests depending on your necessity
you need to go through introduction to selenium ide or just think straight this way that if any action needs loading of page, you simple need to wait for element present and the perform click
click|target|
waitForElementPresent|target|
or if you need to store any value you can use
storeEval|target|value
also the variable name in the selenium ide is named followed by $variableName
enter can be performed as ${KEY_ENTER}
to verify any value we can use AssertValue or VerifyValue
the difference between assert and verify is that assert stops the execution of test case if the value is false whereas verify gives error and execute next statement.
these are few points to be noted in selenium ide.
hope this answer would help you!
You may want to try Implicit Wait addon for Selenium IDE. It will automatically call WaitForElementPresent before executing actions on that element (like clicks). This may save you some time.
Here is the link of Selenium API, all actions can be found here.
Related
I use Drag method on a Java Slider with some number as argument. It fails to work during execution. But always works with breakpoint. Any setting to make QTP simulate execution behavior of breakpoint.
Please note that application is thick client Java.
I've come across this problem in the past and I found it was because QTP/UFT was getting ahead of its self. This might seem primitive but I had a sync (to ensure that your application has displayed the expected page), put a couple of second wait, check that 'Slider' exists and then attempt an action on it.
I want to trigger an event directly from the Chrome developer tools.
I know that I can inspect an element and than reference to it using $0 in the console.
But how can I trigger a dom-event, on this element?
Yes you can. As a matter of fact you can try it right here on Stackoverflow.
Inspect your inbox. You will trigger a click event on that element.
Stackoverflow is convenient since it has jQuery already loaded so you can just do
$($0).trigger( "click");
And you will see the inbox behave as you would expect (open).
The command above uses jQuery $() to wrap the element $0 you have available.
With this you have all the beautiful functionality of jQuery.
In general you can use vanilla javascript for this too, but the commands for triggering events depend on the browser you are using.
You can of course load jQuery yourself via the command line
just copy the content of this paste it in the command line and press enter.
This will work great if the page you are viewing doesn't do anything that would cause any conflicts.
Moreover you can read this answer for vanilla javascript.
Considering that you're using chrome, you can use the URL-bar to simply type
javascript:document.getElementById("submit-button").form.submit()
to, in this case, submit an answer to StackOverflow. This way you can also trigger any other event, for example a url-click:
javascript:document.getElementById("answer-33569491").children[0].children[0].children[0].children[0].children[0].children[1].click()
This can also be entered in a watch, then you can execute it multiple times.
I'm still learning to use Selenium and come up with this question, supposed that I want to open 2 same browsers (2x firfox) at the same time, for the first browser I want it to navigate to google.com and search for the first keyword then click on the first link. In the mean time, the second browser will navigative to google.com and search for the second keyword then click on the first link. Those actions are happening at the same time so they will (or may) close at the same time to save time.
Can you please point me to the right direction what do i need to read or look into in order to archive this task? I read another post on Swing Worker but that's another multi-threading thing. My naive approach is to create a new driver then start them at the same time, but is it any other ways?
Thank you.
With the help of maven and TestNG this can be accomplished. Check this answer and git maven template
Kindly refer below to run parallel browser testing using TESTNG :
TestNG - Parallel browser testing
You will also get best tutorial for selenium web driver and testNG at Selenium Web driver tutorial
Yes with multithreadingyou can achieve this. A simple way can be to create multiple threads of each testcase in your launcher file and each testcase can create its own web driver object and maintain it. Just implement thread in your test case and off you go. And yes after that you can create a jar and run them on different machines.
I was wondering what the differences are between calling the click() method of the WebElement versus finding the element by id and firing the click event with JavaScript.
Just to be clear in the first method I call the .click() of an instance of WebElement:
myWebElement.click();
The second technique is:
((JavascriptExecutor)driver).executeScript("document.getElementById('myElementID').click()");
I'm interested in knowing all the differences between these two techniques for clicking web elements, and also advantages and disadvantages of each.
Webdriver utilizes a browser's native support for mapping the DOM element to WebElement object using id/xpath etc.
The JavascriptExecutor.executeScript executes an external script in the context of the currently selected browser window. (similar to an augmented browsing tool like grease monkey, if you ever used),
and in case the script returns any DOM element its converted into WebElement object.
One can also say, the click simulated by WebDriver on a browser is similar to what actual user do as compared to one invoked using javascript.
In reality, with WebDriver not all the events can be automated flawlessly with all the web browsers, in fact with different versions of the same Web browser also. (i.e. different version of IE, FF etc behave differently). Still WebDriver is the near best tool available for this.
Once (~4 years back) on a certain version of IE we observed that we can't send right click or may be hover mouse on generated menu links, so we used js to simulate that, which performed very much browser independent way. so you can now conclude what executing external javascript can be good for.
Also, there are automated web testing frameworks which use javascript for everything instead of browser's native support. e.g. :http://en.wikipedia.org/wiki/Sahi_%28software%29
Ref:
http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/JavascriptExecutor.html#executeScript%28java.lang.String,%20java.lang.Object...%29
http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement%28org.openqa.selenium.By%29
Those kind of tests are E2E (end to end) not BDD.
First one – is executed now, to take next action you must write some function that will delay execution for e.g download new data from server.
The second code return promise – http://selenium.googlecode.com/git/docs/api/javascript/class_webdriver_WebElement.html – „Schedules a command to click on this element.” – you can use then callback to run next action.
I need to create a user journey such as :
User is on the home page --> randomly clicks on particular item --> views the item stays for about 10 seconds --> then again goes back and clicks on another random item.
how do i generate a test script using jython? I am using Grinder tool
Shashank,
I think your question is too broad to get a detailed response. If you ask a more specific question I think you will get a better answer.
I would say there are two general approaches available for doing what you want, and you could have success with either option:
Write your test directly in Jython. The script documentation (http://grinder.sourceforge.net/g3/scripts.html) and script gallery (http://grinder.sourceforge.net/g3/script-gallery.html) will be helpful to you in this.
Using the HTTP proxy, perform the actions in a web browser that you wish your test to perform. (http://grinder.sourceforge.net/g3/tcpproxy.html) The proxy will capture your browser actions and convert them into a Jython script. After this happens, a small amount of additional work will be required on your part to modify the generated script to detect the list of items available and randomly select one.
My own personal preference is to code up the Grinder scripts from scratch. YMMV.