special-case getting the text of a button

This commit is contained in:
Jonathan Lipps
2013-02-12 10:06:07 -08:00
parent 53590088d8
commit eee901fc2e
4 changed files with 39 additions and 20 deletions
+1 -1
View File
@@ -394,7 +394,7 @@ IOS.prototype.getText = function(elementId, cb) {
this.remote.executeAtom('get_text', [atomsElement], cb);
}
} else {
var command = ["au.getElement('", elementId, "').value()"].join('');
var command = ["au.getElement('", elementId, "').text()"].join('');
this.proxy(command, cb);
}
};
+9
View File
@@ -64,6 +64,15 @@ UIAElement.prototype.hasChildren = function() {
type === "UIASwitch" || type === "UIAElementNil");
};
UIAElement.prototype.text = function() {
var type = this.type();
if (type === "UIAButton") {
return this.label();
} else {
return this.value();
}
};
UIAElement.prototype.matchesTagName = function(tagName) {
var type = this.type();
// i.e. "UIALink" matches "link:
+20 -19
View File
@@ -61,35 +61,36 @@ describe "Computation" do
@driver.quit
end
#it "should add two numbers" do
#values = [rand(10), rand(10)]
#expected_sum = values.reduce(&:+)
#elements = @driver.find_elements(:tag_name, 'textField')
it "should add two numbers" do
values = [rand(10), rand(10)]
expected_sum = values.reduce(&:+)
elements = @driver.find_elements(:tag_name, 'textField')
#elements.each_with_index do |element, index|
#element.send_keys values[index]
#end
elements.each_with_index do |element, index|
element.send_keys values[index]
end
#button = @driver.find_element(:tag_name, 'button')
#button.click
button = @driver.find_element(:tag_name, 'button')
button.click
#actual_sum = @driver.find_elements(:tag_name, 'staticText')[0].text
#actual_sum.should eq(expected_sum.to_s)
#end
actual_sum = @driver.find_elements(:tag_name, 'staticText')[0].text
actual_sum.should eq(expected_sum.to_s)
end
#it "should handle alerts" do
#els = @driver.find_elements(:tag_name, 'button')
#els[1].click
#a = @driver.switch_to.alert
#a.text.should eq("Cool title")
#a.accept
#end
it "should handle alerts" do
els = @driver.find_elements(:tag_name, 'button')
els[1].click
a = @driver.switch_to.alert
a.text.should eq("Cool title")
a.accept
end
it "should find alerts" do
els = @driver.find_elements(:tag_name, 'button')
els[1].click
alert = @driver.find_element(:tag_name, 'alert')
buttons = alert.find_elements(:tag_name, 'button')
buttons[0].text.should eq("Cancel")
buttons[0].click
alerts = @driver.find_elements(:tag_name, 'alert')
alerts.should be_empty
+9
View File
@@ -137,6 +137,15 @@ describeWd('calc app', function(h) {
//};
//_.each(["PORTRAIT", "LANDSCAPE"], testOrientation);
it('should be able to get text of a button', function(done) {
h.driver.elementsByTagName('button', function(err, els) {
els[0].text(function(err, text) {
text.should.eql("ComputeSumButton");
done();
});
});
});
return it('should get an app screenshot', function(done){
h.driver.takeScreenshot(function(err, screenshot){
assert.notEqual(typeof screenshot, "undefined");