I am testing an extjs web app by using robotframework and selenium2library, but I can not locate some HTML elements because they are assigned a dynamic id.
For example: selenium2library could not locate a button which html code like this:
<button type="button" id="ext-gen56" class=" x-btn-text silk-add">create vm</button>
I have tried to use detail XPath and css expression, but they do not work. How to deal with this problem? Any help would be appreciated.
What the tools I used are robotframework and selenium2library which are used for automatic web app testing.
Parts of my test script:
// filename is A.txt
//this is a resource file including keywords which are used by testcase file
*** Keywords ***
open vmmanager page
[Timeout]
click element xpath=//table[3]/tbody/tr[2]/td[2]/em/button
create vm
[Arguments] ${vm_name} ${input_description}
click element xpath=//table[3]/tbody/tr[2]/td[2]/em/button
click element xpath=//td[2]/table/tbody/tr[2]/td[2]/em/button
click link xpath=//tbody/tr/td[5]/div/a
click link xpath=//tbody/tr/td[7]/div/a
input text xpath=//div/div/input ${vm_name}
click image xpath=//div/div/img
click element xpath=//div[22]/div/div
click image xpath=//div[3]/div/div/img
click element xpath=//div[19]/div/div
name is null
alert should be present ${expect}
click button xpath=//div[2]/div/div/div/div/table/tbody/tr/td/em/button
click button xpath=//td[5]/table/tbody/tr[2]/td[2]/em/button
contact engineer
alert should be present
click button ext-gen311
//filename is B.txt
//this is testcase file
*** Settings ***
Resource fiel A.txt
*** Test Cases ***
VC_VM_01
open vmmanager page
create vm ${empty} description
name is null
VC_VM_03
open vmmanager page
create vm valentine day
contact engineer
I would just find out how to set static ids. If you dont have access to the application code, I would ask that the developers would assign static ids for the components. - this would be IMHO the simplest solution.
Generated ids just usually mean that no one yet cares about them.
Without IDs, you could test using _near and _under from Sahi automation framework...I am using it, its Open Source..have patience to try different ways to identify the elements...its cool and good...
Most of the elements will be having text present on them.
xpath=//button[contains(text(), 'create vm')]
A generic approach will be
xpath=//*[contains(text(), 'create vm')]
Related
I am trying to test the ability to retrieve results from a database. When running a test that logs in, navigates to the search tab and searches a word, I am getting a 401. If I go to the website, use the same log in information and do the exact same steps, it works perfectly. Here's the last few steps of the test:
cy.contains('Search').click(); //open tab
cy.contains('Search by').click();
cy.contains('Name').click();
cy.get('.search-field').type('Jane');
cy.get('.search-btn').click();
There's a drop down menu for what you want to search by, a textfield for the search word and a search button. I can't share all of the code but I can see from the video that logging in and all the following steps are performed as supposed to. What kind of things can cause a cypress test to return different results as opposed to manually performing the action? I added wait(2000)'s in between the steps but it made no difference.
Maybe there is an event that needs to be triggered before the page is able to search.
Take a look at the element you are typing into in the devtools, under the Event Listeners tab.
For example, the StackOverflow search box has an event for s-popover:show listed there - if testing that you would .trigger('s-popover:show') to fire that event and display the instruction tooltip.
So try something like this
cy.get('.search-field')
.type('Jane')
.trigger('change') // or .trigger('input')
Cypress deletes localStorage in between tests. In this case that deleted the authorization token which is why I was getting the 401. I installed this package: https://www.npmjs.com/package/cypress-localstorage-commands
After the log in I use
cy.saveLocalStorage();
And before making search
cy.restoreLocalStorage();
My company uses SpreadJS to embed an Excel like sheet into a web page. I'm trying to find a way to create automation tests for this, but I'm unable to locate any of the document information due to the following error:
"You need a browser which full supports HTML5 Canvas to run SpreadJS". I've tried several different browsers, all of which are up to date, and yet I still run into the same issue.
Does anyone know a way around this?
Here is an online example. Let say I just want to modify cell A1 and then retrieve its value:
driver = webdriver.Chrome(paht_to_driver_variable) driver.get("grapecity.com/spreadjs/designer/index.html")
I am trying to automatically select a file into an upload prompt.
Here is the code for the upload section of the website.
<input name="__RequestVerificationToken" value="rAyNscZYeYLEYTV1rodwr0lQr_0Eadpfd11lcuHUvJf83lM57R2vruocFLDPjK0axYr_XBYgqmgTXVH_V2qHGFpAq-zGx_mMm72XIUj4Z6HlUjcyz47Vepfjysur7CR0N8xgHMkjW1KRgb4K6w6VPQ2" type="hidden">
<li>
<input id="imageUpload" class="hideupload" name="imageUpload" multiple="" type="file">
<a id="imageUploadLink" href="#"><i class="addContent_icon uploadlink"><img src="/Content/images/addContent-icon-images.png"></i>Upload Images</a>
</li>
The element of interest as far as I can tell is id: imageUploadLink. Clicking that will open the prompt to select file. Here is my code.
require "selenium-webdriver"
browser = Selenium::WebDriver.for :firefox
sign_in(browser, myUsername, myPassword) #signs into testing site
browser.find_element(:id, 'imageUploadLink').click
element = browser.find_element(:id, 'imageUploadLink')
element.send_keys "/Users/DanielScarlett/Desktop/Example.JPG"
send_keys seems to be typed into the bottom of the browser in a sort of find section that disappears quickly: http://imgur.com/a/7iXcW
I have tried many different ways to implement this, and nothing seems to work. Also, couldn't find anything anywhere to handle this.
I assume you want to select file via browse and then click on Upload Images link. If that is the case, ID for your interest is imageUpload.
Code is in Java, you can change for ruby.
It worked for me using :
driver.findElement(By.id("imageUpload")).sendKeys("absolutepathtoimage\\testImage.jpg");
Check out the use of not using click() on button. It triggers the OS level modal dialog where selenium fails to automate.
I referred it from How to upload file using Selenium WebDriver in Java answer given by #talktokets
When uploading files with Selenium you want to add the file path to the form (e.g., id: 'imageUpload') and then submit the form. You want to avoid triggering the system level dialog box since Selenium isn't able to handle this.
For Ruby, it would look like this:
file_upload = driver.find_element(id: 'imageUpload')
file_upload.send_keys('path/to/your/file')
file_upload.submit
You can see a full write-up that steps through this here.
And if you're looking to run your tests on a remote node (e.g., with Selenium Grid or on a third-party like Sauce Labs) then you'll want to take a look at the file_detector method.
I am trying to create the gmail account through watir. As part of it while I am trying to select the birthday using div element I am unable to do.
I tried with the below one:
#ie.div(:text,'May').click
My system configurations:
IE-8
Windows-7
I've always disliked seeing the answers on here that say 'Why are you doing this?" or "Why would you want to do this?". So I'll just say "Don't do this!". I'm sure whatever issue you are facing can be resolved without automating the creation of gmail account.
If all you need is a unique gmail address then see the link below:
http://www.codestore.net/store.nsf/unid/BLOG-20111201-0411
Another option is https://mailinator.com/
As #titusfortner indicates, that element cannot be selected/clicked because it is not visible. Using watir-webdriver, this snippet makes the dropdown menu visible so its options can be selected:
b.div(title: "Birthday").when_present.click
b.div(text: "May").when_present.click
That being said, there are two other (read: larger) issues:
You won't be able to script your way past the captcha.
Google doesn't want you doing this. That's why the captcha is there, and they'll eventually block your IP if you consistently automate/script against them.
You can't click on the text of something that is not visible on the page. You first need to open the drop-down:
browser.span(id: 'BirthMonth').click
browser.div(text: 'May').click
b.element(:css, '#BirthMonth > div').click
b.element(:text, 'May').click
It works with Chrome and with Firefox also but not perfect
I used Microsoft Test Manager to create a test for a log on page (not locally hosted) and recorded this. All steps were executed without errors.
Then I've created a Coded UI test project in Visual Studio 2013.
I added a Coded UI Test with the existing recording.
I ran the test and I got the message below:
"FailedToPerformActionOnHiddenControlException: Cannot perform 'SetProperty of Text with value " on the username field.
I received this message when using the existing recording, but also if I record using the recording function in Visual Studio.
Has someone got experience with Coded UI Tests and maybe give me an example as to how to set it up.
If I understand correctly, you're basically trying to have Coded UI input a value into an HtmlInput control that's a text box on a web page. The error message "FailedToPerformActionOnHiddenControlException: Cannot perform 'SetProperty of Text with value" normally means that the value you're trying to submit isn't able to be taken by the control, either because a value isn't accepted (example, numeric values in a name field) or because it's more characters than can be accepted by the field. It could also be that the recording isn't defining the object properly, and that the property Text isn't an option on the control that was found.
So, confirm these three things:
1. The control you're tying to send value to is actually an HtmlInput. You can't send the Text property to, for example, an `HtmlDiv`.
2. The value you're submitting is a valid value for your control (you're not trying to submit numbers, for example, into a field that won't accept them).
3. The value you're submitting is within the length limit for the field.
If I were a betting man, I would say that you probably don't have the object defined properly. Take a look at the SearchProperties of the control in question first and make sure that it matches the HTML on the page itself.
Do I need to set a standard environment for testing on an other server.
I develop the Coded UI test project in a workspace on a development environment, but I need the tests to be run on a acceptation environment (the recorded tests are executed on the acceptation environment).
I read it's easy to setup this environment though, but what is best practise?
Is it better to execute it on the same environment?
Here's a code snippet:
[TestMethod]
public void TestLogonToAccount()
{
// To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
this.UIMap.Enterusername();
this.UIMap.Enterpassword();
this.UIMap.Clickonlogin();
this.UIMap.ClickonCentral();
this.UIMap.Searchforemailaddress();
this.UIMap.Clickonlogin1();
}
I forgot an important part regarding the login recording test in MTM.
I just tried to play the steps again and got this error:
Playback of the selected sections of the action recording could not be completed The playback failed to find the control with the
given search properties. Additional Details: TechnologyName: 'MSAA'
Name: '' ClassName: 'MozillaWindowClass' ControlType: 'Window'