I know similar questions have been posted, but from my investigating, there has not been a solution posted, at least not one that works. I have successfully run UI tests only from sample projects in both Swift and Obj-C.
I am trying (unsuccessfully) to integrate UI tests into an existing Xcode Obj-C project, which seems to be another issue altogether. Here are the steps I have taken:
Created a new UI Test target within my project
Ensured that 'Enable Testability' has been set to YES for the target I am testing
Cleaned, cleaned build folder, rebuilt the app, restarted Xcode and everything else I could think of.
When I do this, the test target is available but the record button is greyed out (disabled) and there are no play buttons in the gutter to execute the tests. There is nothing visual about the test class that would indicate that it is a test class. When I place my cursor in the test method, the record button remains disabled.
Is there anything I've left out? Anything else to check that might be preventing UI tests?
Record button only gets enabled within a function body.
The function name must start with test. Like testExample().
After changing the name of the function wait for a few seconds for the run icon to appear in the gutter.
Now the record button should appear.
Make sure you are in the correct XCTestCase subclass file.
After researching for a time, I found that I was all the time in a extension file (I'm been ordering the flows in extension files). So when I opened the main XCTestCase subclass file (like "YourAppUItests") the record test button has been enabled.
Click on 6th button from top of the left pane - Show the test navigator
Right click on the UI tests, then click on "Enable ... "
Then you can record.
Make sure you can build for the test target successfully.
Go to Product > Test, and make sure the UI Testing test case is run (it is fine if the test case is empty). You should also see the test cases under Test Navigator, or in the app target scheme.
I followed all the tips listed here, and the only thing that fixed it was restarting Xcode.
Make sure you have at least one test function in your ui test class. For example- func testExample(){}. Then you'll be able to record in that function as you can only run functions as tests if they have test as prefix.
I realized you had to have your cursor inside the test function you want to record for. I simply clicked inside the test function and the record button got enabled.
Also, make sure you select the UI test scheme, which was the problem in my case:
If your project has a test plan (.xctestplan) then make sure that the new test is enabled. Till then the record button will be disabled. This often happens when you add a new UI Test Case Class. Or when you add new test to existing class which has some of the tests disabled.
create function in yourfileUITests.swift
running program by TEST
your function can record UI Testing, button already enable
Related
Record UITest button is disabled in Xcode
Deleted derived data, clean the build not solving this problem
It's working fine with Xcode 10.1
Is there anything i'm missing?
I see this a lot as well.
For starters, here is how my class looks after immediately creating the test function:
Notice the following:
No record button available, matching OP
The diamond indicating it is a test does not appear on the left column
I then run my tests, but stop immediately. Doing that gives me this:
I can now record
The diamond appears on the left column
You can also shut down Xcode and restart, but the above steps are faster.
I'm working in Xcode 9 on a Swift project, and I'm in table flipping mode with this.
Here's my end goal: put my tests next to my logic in a playground so that as I write the logic, I can see the tests pass in close to real time.
I will also accept how to put my tests in a playground by themselves, I just don't want to be running tests on a simulator for every little thing.
My problems in trying to get this to work are many. First and foremost, I can't find a way to add a playground directly to my project/workspace. When I right click on a group in the project navigator and select 'New file...' I get this:
As you can see, no option for playground. Filtering also returns no results. If I press the plus button at the bottom of the project navigator, the same dialog (with no playground option) pops up.
I thought it's in another menu so I went to the File menu, and in "New >" I find an option for creating a playground. I select a blank playground from the chooser, choose where to save it (strange that it wanted to save it under 'Unsaved Xcode Documents') and a basic playground comes up in a new tab. Odd thing I notice, though, is that there's no longer a play button or scheme/simulator selector at the top on this tab.
It now doesn't recognize ANY modules other than Apple provided ones! And sure enough, creating the playground didn't actually add it to my workspace. I guess I have to manually add it to my project. Upon doing so, it will recognize my pods but none of my project files! Any class I try to use gives me an Unrecognized identifier. Trying to import my project doesn't work either, it just gives me a No module.
I tried clearing DerivedData, I tried cleaning, I tried restarting Xcode, I even made sure I had an iPad Pro in the list of simulators (since that seems to matter for some people).
In frustration, I deleted the playground, and resolved just to deal with running my tests constantly. But now, my project has persistent errors! Despite moving the playground to the trash, Swift continues to error saying 'Unresolved identifier' for that playground!
As the excellent Brandon Williams says in his talk at FrenchKit, a playground "does not get access to anything in the application target." Which is ridiculous, but hey, what are you gonna do. So the answer is: there is currently no way to do this the way I asked.
It IS possible, however, to achieve this functionality if your logic is in its own framework/cocoapod. That is, move the logic you want to test out of your app target and into an outside library that your app, subsequently, imports. This will allow your playground to import it as well, and you can test to your heart's content.
I know the breakpoints. But not known about the thing that look like the diamond. Take a look at the image shown, it is present at lines no. 16, 28 and 33. When I click on that, Xcode compiles the project. It is hard to get some details about that.
The diamonds are symbols to indicate test results.
To use them run the tests by selecting menu item Test from menu Product or pressing ⌘U
Test cases are starts with the method name -(void)testLogin, those methods are mentioned in diamond , we can run that test individully or overall test cases can be run by choosing the target as test.
This can be achieved by long press on the play button, which will provide you with 3 option, in that choose test. This will perform all the test cases and provide you the success or failure test cases
So I downloaded the beta of XCode 7 and I've created some UI tests, but I can't find the functionality of how to take screenshots of my app/UI during the test.
Can someone please help?
UI Testing in Xcode automatically takes screenshots of your app after every step.
Simply go to one of the tests that has already ran (Report Navigator > choose a Test), then start expanding your tests. When you hover your mouse over the steps, you will see eye icons near each step that has a screenshot.
Here's an example... in this case, notice the eye icon at the end of the gray row. If I were to tap on it, I would see a screenshot of the app right when the button in my app was tapped (since the step is Tap the "Button" Button).
If you want to generate screenshots, you can also use snapshot, which describes how to trigger screenshots in UI tests: https://github.com/fastlane/fastlane/tree/master/snapshot#how-does-it-work
It basically rotates the device to .Unknown (Source), which triggers a snapshot without actually modifying your app's state.
Comparing the output with the generated plist file enables you to even properly name the screenshot
Facebook's ios-snapshot-test-case and KIF both run as Unit Tests, and therefore are in the same process as the app. As such, they can directly access views and use something like renderView: or snapshotViewAfterScreenUpdates. Xcode UI Testing runs in a separate process, and therefore cannot directly access the views.
UI Automation, Apple's now-deprecated Javascript UI testing library, had a function calledcaptureScreenWithName.
Unfortunately, the new Xcode UI Testing lacks any similar function in its testing library, which to me seems like a glaring omission and I encourage you to submit a Radar for it, as taking screenshots is fundamental to perceptual difference tests (which it sounds like you're trying to do). I hope (and expect) that able will address this deficiency in later Xcode updates.
In the meantime, there are more creative approaches to taking screenshots. See this stack overflow response for a workaround involving taking the screenshot in the app itself and then sending it to the test process.
I' ve created a tool that saves the tests last n screenshots and generates the JUnit tests results report, parsing TestSummaries plist file from test logs. https://github.com/nacuteodor/ProcessTestSummaries
Maybe, that helps you.
Facebook's FBSnapshotTestCase can be alternative solution:
https://github.com/facebook/ios-snapshot-test-case
I am trying to use UIAutomation for testing an iOS 8 Today extension widget. I can change the target to the extension, launch it, but then unable to do anything after that.
Has anyone had any success in using UIAutomation with the extensions?
I hope I have the right end of the stick on this one.
I think you want to create a set of UI Tests which run like you can do with a normal application.
I found that I was not able to create a specific UI Tests target to then set the target application as WidgetExtension, as you would normally.
However I was able to set the WidgetExtension target to build and run onto a device (>= iOS 14) then within my UI Tests, I was able to record some steps which would allow me to write a clearer UI Test (place the cursor inside a test function to use record, you might already know this).
The tricky bit would be keeping the WidgetExtension target up-to-date onto the testing simulator to run your automated tests.