how to access a element in right view of text box in xcuitest - xcuitest

I am new to XCUITESTING AND here is my code
let btn = UIButton(frame: CGRect(x: 0, y: 5, width: 50, height: 40))
btn.addTarget(self, action: #selector(addEmail), for: .touchDown)
btn.setImage(UIImage(named: "f_add_email"), for: .normal)
btn.contentMode = .center
btn.isAccessibilityElement = true
btn.accessibilityIdentifier = "emailsbutton"
txtField.isAccessibilityElement = true
txtField.accessibilityIdentifier = "emailtextbox"
txtField.rightViewMode = .always
txtField.rightView = btn
i am able to access my textbox like XCUIApplication().textFields["emailtextbox"]
BUT if i use XCUIApplication().textFields["emailsbutton"] it throws error

It could be that the button is under a textField. If so, you would need to access it with the following code:
XCUIApplication().textFields.buttons["emailsbutton"]

I think You should try this following things :
1 ) Always do XCUIApplication().debugDescription see that button Ids/label/title.
You can use buttons or otherElements to trigger tap on it.
XCUIApplication().buttons["emailsbutton"].tap()
OR
XCUIApplication().otherElements["emailsbutton"].tap()

Related

How to duplicate slider in HTML (esp8266)

I'm doing something With an ESP8266, and I need some help with the HTML part of it.
I want to duplicate 1 slider:
The code is :
client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
// CSS to style the on/off buttons
// Feel free to change the background-color and font-size attributes to fit your preferences
client.println("<style>body { text-align: center; font-family: \"Trebuchet MS\", Arial; margin-left:auto; margin-right:auto;}");
client.println(".slider { width: 300px; }</style>");
client.println("<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>");
// Web Page
//client.println("</head><body><h1>ESP32 with Servo</h1>");
client.println("<p>Start Temperature: <span id=\"servoPos\"></span></p>");
client.println("<input type=\"range\" min=\"20\" max=\"30\" class=\"slider\" id=\"servoSlider\" onchange=\"servo(this.value)\" value=\""+valueString+"\"/>");
client.println("<script>var slider = document.getElementById(\"servoSlider\");");
client.println("var servoP = document.getElementById(\"servoPos\"); servoP.innerHTML = slider.value;");
client.println("slider.oninput = function() { slider.value = this.value; servoP.innerHTML = this.value; }");
client.println("$.ajaxSetup({timeout:1000}); function servo(pos) { ");
client.println("$.get(\"/?value=\" + pos + \"&\"); {Connection: close};}</script>");
client.println("</body></html>");
//GET /?value=180& HTTP/1.1
if(header.indexOf("GET /?value=")>=0) {
pos1 = header.indexOf('=');
pos2 = header.indexOf('&');
valueString = header.substring(pos1+1, pos2);
//Rotate the servo
//myservo.write(valueString.toInt());
// Serial.println(valueString);
}
}
}
// Clear the header variable
header = "";
This gives me a slider, but I want another one for controlling a different thing, under a different variable.
Since I don't really understand HTML, I have tried to change some variables and duplicate the code myself, but without success. The slider works, but I get a lot of errors.
Second (independent) slider
client.println("<p>Start Sensor2: <span id=\"servoPos2\"></span></p>");
client.println("<input type=\"range\" min=\"20\" max=\"30\" class=\"slider\" id=\"servoSlider2\" onchange=\"servo2(this.value)\" value=\""+valueString+"\"/>");
client.println("<script>var slider2 = document.getElementById(\"servoSlider2\");");
client.println("var servoP2 = document.getElementById(\"servoPos2\"); servoP2.innerHTML = slider2.value;");
client.println("slider2.oninput = function() { slider2.value = this.value; servoP2.innerHTML = this.value; }");
The function servo(pos) (my guess) in the rest code not shown has either to be
duplicated or ???
to stop guessing and helping you please add the following info:
Source code esp8266 or if it is a standard example the name of the ino file
The type of error- during compilation, on the browser console, on serial port?

Interference between two UIStepper controls

I have a program with two stepper controls. I click the first control and increase to 10. When I click the second control, the value of the first control changes to 11, before the second control changes. If I would set the second stepper to 5 and press the first stepper down, the second value changes to 4, before the first stepper changes.
So the two steppers interferes with each other in the change from one to the other but only then.
Here is what I believe is the significant code:
#IBAction func firstMarkdownPressed(_ sender1: UIStepper) {
let firstMarkdownNum = Double(sender1.value)
firstMarkdownText.text = "\(String(format:"%.0f%",firstMarkdownNum))%"
}
#IBAction func secondMarkdownPressed(_ sender2: UIStepper) {
let secondMarkdownNum = Double(sender2.value)
secondMarkdownText.text = "\(String(format:"%.0f%",secondMarkdownNum))%"
}
override func viewDidLoad() {
super.viewDidLoad()
firstMarkdownStepper.wraps = false
firstMarkdownStepper.autorepeat = true
firstMarkdownStepper.maximumValue = 100
firstMarkdownStepper.value = 0
firstMarkdownStepper.isContinuous = false
secondMarkdownStepper.wraps = false
secondMarkdownStepper.autorepeat = true
secondMarkdownStepper.maximumValue = 100
secondMarkdownStepper.value = 0
}
Any thoughts?
Sorry I didn't check the app on an actual device. The problem I described only happens using the simulator. When running on an actual iPhone, it works as it should.

How to short the code to change control properties on command buttion click in ms-access vba

I have a userform with a group of command buttons with similiar properties and fuctionality. I am using these buttons to let the user keep track about his activity. So e.g. whenever user will click the "production" button the application label will say "production" mode, when the user presses "Break" button the label will change from "production" mode to "Break" mode, Similiarly I have 7-8 buttons altogether on same form. Other conditions are whichever buttons gets pressed that button should get disabled and all other buttons should get enabled, followed by next button, if pressed it should get disabled and it should enable the button which was pressed previously.
The button which has been pressed whould also change its color and should also change the previous button's color back to normal.
I understand it would be difficult to understand the scenario, please check the code below for one of my buttons and its working well.
Private Sub btn1()
Me.Label78.Caption = Me.btn1.Caption
Me.btn1.BackColor = RGB(250, 100, 100)
Me.btn1.Gradient = 12
Me.btn1.Enabled = False
Me.btn2.Enabled = True
Me.btn2.BackColor = RGB(100, 250, 100)
Me.btn2.Gradient = 12
Me.btn3.Enabled = True
Me.btn3.BackColor = RGB(100, 250, 100)
Me.btn3.Gradient = 12
End Sub
the above code works perfeclty and changes properties to 3 buttons(its sample code not the code for all 7 buttons), but I have total 7-8 button and i may add more buttons in future SO if i keep on writing this kind of code in one button for all 7-8 buttons, then it will take a lot of time and efforct.
So what is the best possible way to short this code ?
I know this is little complicated hence please ask if any more information required.
Thanks in advance !!
You can have a helper subfunction:
Private Sub SetButton(ByVal ButtonId As Long, ByVal Enabled As Boolean)
Dim BackColor As Long
If Enabled Then
BackColor = RGB(100, 250, 100)
Else
BackColor = RGB(250, 100, 100)
End If
With Me("btn" & Cstr(Id))
.Enabled = Enabled
.Gradient = 12
.BackColor = BackColor
End With
End Sub
Then call this in the OnClick event like:
For Id = 1 To 8
Select Case Id
Case 1, 2, 4, 7
SetButton Id, True
Case Else
SetButton Id, False
End Select
Next

Adding a smooth fitted line (loess) to a bar graph

I am trying to add a loess curve to a bar plot.
After loading the ggplots2 package, I first create the bar plot:
test<-read.csv("tseries.csv", header = TRUE)
barplot(test$tn90p, beside = TRUE,ylim =c(-6,6))
lo<-loess(tn10p~year, test) pred<-predict(lo, se = TRUE)
a<-order(test$year)
So far so good, until I try to add the smoothed curve:
lines(test$year[a], pred$fit[a], col = "red", lwd = 2)
When I do that, no error message, the prompt comes back, but no line is added.
What am I missing?
Thanks for your help.
Note: when I dput(test), I have this:
structure(list(year = 1951:1980, tn90p = c(3.126667391, 4.091391006,
3.11420404, 5.117428018, 2.281128013, 2.654342884, 4.189742845,
-0.448909654, 1.634574903, -1.324893538, -0.675205784, -1.876889174,
-2.689793785, 0.364812684, -1.859920287, -1.736813462, -1.527857975,
-3.214404324, -4.189742845, 0.448909654, -1.634574903, 1.324893538,
0.675205784, 1.876889174, -0.436873606, -4.45620369, -1.254283753,
-3.380614556, -0.753270038, 0.560061439)), .Names = c("year",
"tn90p"), class = "data.frame", row.names = c(NA, -30L))
Finally I could make it work:
test<-read.csv("tseries.csv", header = TRUE)
attach(test)
p = barplot(test$tn90p, names.arg=test$year, beside = TRUE, ylim =c(-6,6))
lo<-loess(tn90p~year)
lines(p, predict(lo), col="red", lwd=3)
abline (h=0, lwd=1)

Double CommandBar - is it possible?

Here is my problem. After I select iten I have 4 options to click, then each options give me 4 additional final options.
So now I have command bar:
And now after I click one of buttons I want to show another command bar above the first one:
Is it possible with winRT for Windows Phone 8.1? Or maybe show some Fly Menu with icons?
like so:
here is code for adding FlyOut menu but ... when i click sendBtn everything gets grey but nothing is shown ;/
MenuFlyout testMenu = new MenuFlyout();
MenuFlyoutItem item1 = new MenuFlyoutItem();
item1.Text = "Test1";
MenuFlyoutItem item2 = new MenuFlyoutItem();
item1.Text = "Test2";
testMenu.Items.Add(item1);
testMenu.Items.Add(item2);
AppBarButton sendBtn = new AppBarButton();
sendBtn.Label = textLoader.GetString("SendToService");
sendBtn.Icon = new SymbolIcon(Symbol.Mail);
sendBtn.Flyout = testMenu;
command_bar.PrimaryCommands.Add(sendBtn);
As for your main question - there is no possiblity to make double commandbar. Though you may build your own control and implement such functionality.
As for your code - in my case it seems to work - I've tried like this:
CommandBar command_bar;
public MainPage()
{
this.InitializeComponent();
command_bar = new CommandBar();
MenuFlyout testMenu = new MenuFlyout();
MenuFlyoutItem item1 = new MenuFlyoutItem();
item1.Text = "Test1";
MenuFlyoutItem item2 = new MenuFlyoutItem();
item2.Text = "Test2";
testMenu.Items.Add(item1);
testMenu.Items.Add(item2);
AppBarButton sendBtn = new AppBarButton();
sendBtn.Label = "SendToService";
sendBtn.Icon = new SymbolIcon(Symbol.Mail);
sendBtn.Flyout = testMenu;
command_bar.PrimaryCommands.Add(sendBtn);
BottomAppBar = command_bar;
}
You have one mistake - your second MenuItem has empty label - you change the first twice.
Also if you encounter problem with bad positioning of your flyout then this answer may help.